diff --git a/src/components/structures/TagPanel.js b/src/components/structures/TagPanel.js index 59a658c1b4..9bf5a12731 100644 --- a/src/components/structures/TagPanel.js +++ b/src/components/structures/TagPanel.js @@ -60,6 +60,7 @@ const TagPanel = React.createClass({ const orderedTags = TagOrderStore.getOrderedTags() || []; const orderedGroupTags = orderedTags.filter((t) => t[0] === '+'); + // XXX: One profile lookup failing will bring the whole lot down Promise.all(orderedGroupTags.map( (groupId) => FlairStore.getGroupProfileCached(this.context.matrixClient, groupId), )).then((orderedGroupTagProfiles) => { diff --git a/src/stores/TagOrderStore.js b/src/stores/TagOrderStore.js index cc1ce8625e..2ed6ff6e75 100644 --- a/src/stores/TagOrderStore.js +++ b/src/stores/TagOrderStore.js @@ -97,11 +97,28 @@ class TagOrderStore extends Store { _updateOrderedTags() { this._setState({ - orderedTags: this._state.hasSynced && this._state.hasFetchedJoinedGroups ? - this._state.orderedTagsAccountData || this._state.joinedGroupIds : null, + orderedTags: + this._state.hasSynced && + this._state.hasFetchedJoinedGroups ? + this._mergeGroupsAndTags() : null, }); } + _mergeGroupsAndTags() { + const groupIds = this._state.joinedGroupIds || []; + const tags = this._state.orderedTagsAccountData || []; + + const tagsToKeep = tags.filter( + (t) => t[0] !== '+' || groupIds.includes(t), + ); + + const groupIdsToAdd = groupIds.filter( + (groupId) => !tags.includes(groupId), + ); + + return tagsToKeep.concat(groupIdsToAdd); + } + getOrderedTags() { return this._state.orderedTags; }