diff --git a/src/components/views/rooms/RoomTile.tsx b/src/components/views/rooms/RoomTile.tsx index 2ad10c79c8..959b2f162a 100644 --- a/src/components/views/rooms/RoomTile.tsx +++ b/src/components/views/rooms/RoomTile.tsx @@ -107,7 +107,10 @@ export default class RoomTile extends React.PureComponent { this.notificationState.on(NOTIFICATION_STATE_UPDATE, this.onNotificationUpdate); this.roomProps = EchoChamber.forRoom(this.props.room); this.roomProps.on(PROPERTY_UPDATED, this.onRoomPropertyUpdate); - CommunityPrototypeStore.instance.on(UPDATE_EVENT, this.onCommunityUpdate); + CommunityPrototypeStore.instance.on( + CommunityPrototypeStore.getUpdateEventName(this.props.room.roomId), + this.onCommunityUpdate, + ); } private onNotificationUpdate = () => { @@ -140,6 +143,14 @@ export default class RoomTile extends React.PureComponent { MessagePreviewStore.getPreviewChangedEventName(this.props.room), this.onRoomPreviewChanged, ); + CommunityPrototypeStore.instance.off( + CommunityPrototypeStore.getUpdateEventName(prevProps.room?.roomId), + this.onCommunityUpdate, + ); + CommunityPrototypeStore.instance.on( + CommunityPrototypeStore.getUpdateEventName(this.props.room?.roomId), + this.onCommunityUpdate, + ); } } @@ -157,10 +168,13 @@ export default class RoomTile extends React.PureComponent { MessagePreviewStore.getPreviewChangedEventName(this.props.room), this.onRoomPreviewChanged, ); + CommunityPrototypeStore.instance.off( + CommunityPrototypeStore.getUpdateEventName(this.props.room.roomId), + this.onCommunityUpdate, + ); } defaultDispatcher.unregister(this.dispatcherRef); this.notificationState.off(NOTIFICATION_STATE_UPDATE, this.onNotificationUpdate); - CommunityPrototypeStore.instance.off(UPDATE_EVENT, this.onCommunityUpdate); } private onAction = (payload: ActionPayload) => { diff --git a/src/stores/CommunityPrototypeStore.ts b/src/stores/CommunityPrototypeStore.ts index 95d56bd40e..92e094c83b 100644 --- a/src/stores/CommunityPrototypeStore.ts +++ b/src/stores/CommunityPrototypeStore.ts @@ -48,6 +48,10 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient { return CommunityPrototypeStore.internalInstance; } + public static getUpdateEventName(roomId: string): string { + return `${UPDATE_EVENT}:${roomId}`; + } + public getSelectedCommunityId(): string { if (SettingsStore.getValue("feature_communities_v2_prototypes")) { return GroupFilterOrderStore.getSelectedTags()[0]; @@ -134,7 +138,8 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient { } } else if (payload.action === "MatrixActions.accountData") { if (payload.event_type.startsWith("im.vector.group_info.")) { - this.emit(UPDATE_EVENT, payload.event_type.substring("im.vector.group_info.".length)); + const roomId = payload.event_type.substring("im.vector.group_info.".length); + this.emit(CommunityPrototypeStore.getUpdateEventName(roomId), roomId); } } else if (payload.action === "select_tag") { // Automatically select the general chat when switching communities @@ -167,7 +172,7 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient { if (getEffectiveMembership(myMember.membership) === EffectiveMembership.Invite) { // Fake an update for anything that might have started listening before the invite // data was available (eg: RoomPreviewBar after a refresh) - this.emit(UPDATE_EVENT, room.roomId); + this.emit(CommunityPrototypeStore.getUpdateEventName(room.roomId), room.roomId); } } }