Factor out _getDisplayeDGroups

This commit is contained in:
Luke Barnard 2017-11-28 15:46:23 +00:00
parent b748c62880
commit b32e4a57bc

View file

@ -83,6 +83,18 @@ export default React.createClass({
}); });
}, },
_getDisplayedGroups(userGroups, relatedGroups) {
let displayedGroups = userGroups || [];
if (relatedGroups && relatedGroups.length > 0) {
displayedGroups = displayedGroups.filter((groupId) => {
return relatedGroups.includes(groupId);
});
} else {
displayedGroups = [];
}
return displayedGroups;
},
render() { render() {
const EmojiText = sdk.getComponent('elements.EmojiText'); const EmojiText = sdk.getComponent('elements.EmojiText');
const {mxEvent} = this.props; const {mxEvent} = this.props;
@ -93,14 +105,9 @@ export default React.createClass({
return <span />; // emote message must include the name so don't duplicate it return <span />; // emote message must include the name so don't duplicate it
} }
let displayedGroups = this.state.userGroups || []; const displayedGroups = this._getDisplayedGroups(
if (this.state.relatedGroups && this.state.relatedGroups.length > 0) { this.state.userGroups, this.state.relatedGroups,
displayedGroups = displayedGroups.filter((groupId) => { );
return this.state.relatedGroups.includes(groupId);
});
} else {
displayedGroups = [];
}
name = displayedGroups.length > 0 ? name.replace(' (IRC)', '') : name; name = displayedGroups.length > 0 ? name.replace(' (IRC)', '') : name;