Avoid crash on drawer filtered channel list (#1042)

This commit is contained in:
enahum 2017-10-19 13:07:46 -03:00 committed by Jarred Witt
parent 40008a9242
commit 04ec27f333
3 changed files with 10 additions and 8 deletions

View file

@ -19,6 +19,7 @@ export default class ChannelItem extends PureComponent {
channelId: PropTypes.string.isRequired,
currentChannelId: PropTypes.string.isRequired,
displayName: PropTypes.string.isRequired,
fake: PropTypes.bool,
isUnread: PropTypes.bool,
mentions: PropTypes.number.isRequired,
onSelectChannel: PropTypes.func.isRequired,
@ -28,9 +29,9 @@ export default class ChannelItem extends PureComponent {
};
onPress = wrapWithPreventDoubleTap(() => {
const {channelId, currentChannelId, displayName, onSelectChannel} = this.props;
const {channelId, currentChannelId, displayName, fake, onSelectChannel, type} = this.props;
requestAnimationFrame(() => {
onSelectChannel({id: channelId, display_name: displayName}, currentChannelId);
onSelectChannel({id: channelId, display_name: displayName, fake, type}, currentChannelId);
});
});

View file

@ -12,7 +12,7 @@ function makeMapStateToProps() {
const getChannel = makeGetChannel();
return (state, ownProps) => {
const channel = getChannel(state, {id: ownProps.channelId});
const channel = ownProps.channel || getChannel(state, {id: ownProps.channelId});
let member;
if (ownProps.isUnread) {
member = getMyChannelMember(state, ownProps.channelId);
@ -21,6 +21,7 @@ function makeMapStateToProps() {
return {
currentChannelId: getCurrentChannelId(state),
displayName: channel.display_name,
fake: channel.fake,
mentions: member ? member.mention_count : 0,
status: channel.status,
theme: getTheme(state),

View file

@ -95,25 +95,25 @@ class FilteredList extends Component {
}
onSelectChannel = (channel) => {
const {makeGroupMessageVisibleIfNecessary} = this.props.actions;
const {actions, currentChannel} = this.props;
const {makeGroupMessageVisibleIfNecessary} = actions;
if (channel.type === General.GM_CHANNEL) {
makeGroupMessageVisibleIfNecessary(channel.id);
}
this.props.onSelectChannel(channel);
this.props.onSelectChannel(channel, currentChannel.id);
};
createChannelElement = (channel) => {
return (
<ChannelDrawerItem
ref={channel.id}
channelId={channel.id}
channel={channel}
hasUnread={false}
isUnread={false}
mentions={0}
onSelectChannel={this.onSelectChannel}
isActive={channel.isCurrent || false}
theme={this.props.theme}
/>
);
};