Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 8d46b19

Browse files
author
Luke Barnard
committed
Restrict Flair in the timeline to related groups of the room
1 parent 9f39a15 commit 8d46b19

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/components/views/elements/Flair.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,26 @@ export default class Flair extends React.Component {
183183
this.state = {
184184
profiles: [],
185185
};
186+
this.onRoomStateEvents = this.onRoomStateEvents.bind(this);
186187
}
187188

188189
componentWillUnmount() {
189190
this._unmounted = true;
191+
this.context.matrixClient.removeListener('RoomState.events', this.onRoomStateEvents);
190192
}
191193

192194
componentWillMount() {
193195
this._unmounted = false;
194196
if (UserSettingsStore.isFeatureEnabled('feature_groups') && groupSupport) {
195197
this._generateAvatars();
196198
}
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+
}
197206
}
198207

199208
async _getGroupProfiles(groups) {
@@ -224,6 +233,21 @@ export default class Flair extends React.Component {
224233
}
225234
console.error('Could not get groups for user', this.props.userId, err);
226235
}
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+
}
227251
if (!groups || groups.length === 0) {
228252
return;
229253
}
@@ -250,6 +274,12 @@ export default class Flair extends React.Component {
250274

251275
Flair.propTypes = {
252276
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,
253283
};
254284

255285
// TODO: We've decided that all components should follow this pattern, which means removing withMatrixClient and using

src/components/views/messages/SenderProfile.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ export default function SenderProfile(props) {
3333
return (
3434
<div className="mx_SenderProfile" dir="auto" onClick={props.onClick}>
3535
<EmojiText className="mx_SenderProfile_name">{ name || '' }</EmojiText>
36-
{ props.enableFlair ? <Flair userId={mxEvent.getSender()} /> : null }
36+
{ props.enableFlair ?
37+
<Flair
38+
userId={mxEvent.getSender()}
39+
roomId={mxEvent.getRoomId()}
40+
showRelated={true} />
41+
: null
42+
}
3743
{ props.aux ? <EmojiText className="mx_SenderProfile_aux"> { props.aux }</EmojiText> : null }
3844
</div>
3945
);

0 commit comments

Comments
 (0)