@@ -183,17 +183,26 @@ export default class Flair extends React.Component {
183
183
this . state = {
184
184
profiles : [ ] ,
185
185
} ;
186
+ this . onRoomStateEvents = this . onRoomStateEvents . bind ( this ) ;
186
187
}
187
188
188
189
componentWillUnmount ( ) {
189
190
this . _unmounted = true ;
191
+ this . context . matrixClient . removeListener ( 'RoomState.events' , this . onRoomStateEvents ) ;
190
192
}
191
193
192
194
componentWillMount ( ) {
193
195
this . _unmounted = false ;
194
196
if ( UserSettingsStore . isFeatureEnabled ( 'feature_groups' ) && groupSupport ) {
195
197
this . _generateAvatars ( ) ;
196
198
}
199
+ this . context . matrixClient . on ( 'RoomState.events' , this . onRoomStateEvents ) ;
200
+ }
201
+
202
+ onRoomStateEvents ( event ) {
203
+ if ( event . getType ( ) === 'm.room.related_groups' && groupSupport ) {
204
+ this . _generateAvatars ( ) ;
205
+ }
197
206
}
198
207
199
208
async _getGroupProfiles ( groups ) {
@@ -224,6 +233,21 @@ export default class Flair extends React.Component {
224
233
}
225
234
console . error ( 'Could not get groups for user' , this . props . userId , err ) ;
226
235
}
236
+ if ( this . props . roomId && this . props . showRelated ) {
237
+ const relatedGroupsEvent = this . context . matrixClient
238
+ . getRoom ( this . props . roomId )
239
+ . currentState
240
+ . getStateEvents ( 'm.room.related_groups' , '' ) ;
241
+ const relatedGroups = relatedGroupsEvent ?
242
+ relatedGroupsEvent . getContent ( ) . groups || [ ] : [ ] ;
243
+ if ( relatedGroups && relatedGroups . length > 0 ) {
244
+ groups = groups . filter ( ( groupId ) => {
245
+ return relatedGroups . includes ( groupId ) ;
246
+ } ) ;
247
+ } else {
248
+ groups = [ ] ;
249
+ }
250
+ }
227
251
if ( ! groups || groups . length === 0 ) {
228
252
return ;
229
253
}
@@ -250,6 +274,12 @@ export default class Flair extends React.Component {
250
274
251
275
Flair . propTypes = {
252
276
userId : PropTypes . string ,
277
+
278
+ // Whether to show only the flair associated with related groups of the given room,
279
+ // or all flair associated with a user.
280
+ showRelated : PropTypes . bool ,
281
+ // The room that this flair will be displayed in. Optional. Only applies when showRelated = true.
282
+ roomId : PropTypes . string ,
253
283
} ;
254
284
255
285
// TODO: We've decided that all components should follow this pattern, which means removing withMatrixClient and using
0 commit comments