Use room-specific listeners for community prototype

Similar to message previews, this changes another area to use room-specific
listeners for better performance and avoiding warnings.
pull/21833/head
J. Ryan Stinnett 2021-01-15 14:34:56 +00:00
parent 729356394e
commit 8a341446aa
2 changed files with 23 additions and 4 deletions

View File

@ -107,7 +107,10 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
this.notificationState.on(NOTIFICATION_STATE_UPDATE, this.onNotificationUpdate); this.notificationState.on(NOTIFICATION_STATE_UPDATE, this.onNotificationUpdate);
this.roomProps = EchoChamber.forRoom(this.props.room); this.roomProps = EchoChamber.forRoom(this.props.room);
this.roomProps.on(PROPERTY_UPDATED, this.onRoomPropertyUpdate); 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 = () => { private onNotificationUpdate = () => {
@ -140,6 +143,14 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
MessagePreviewStore.getPreviewChangedEventName(this.props.room), MessagePreviewStore.getPreviewChangedEventName(this.props.room),
this.onRoomPreviewChanged, 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<IProps, IState> {
MessagePreviewStore.getPreviewChangedEventName(this.props.room), MessagePreviewStore.getPreviewChangedEventName(this.props.room),
this.onRoomPreviewChanged, this.onRoomPreviewChanged,
); );
CommunityPrototypeStore.instance.off(
CommunityPrototypeStore.getUpdateEventName(this.props.room.roomId),
this.onCommunityUpdate,
);
} }
defaultDispatcher.unregister(this.dispatcherRef); defaultDispatcher.unregister(this.dispatcherRef);
this.notificationState.off(NOTIFICATION_STATE_UPDATE, this.onNotificationUpdate); this.notificationState.off(NOTIFICATION_STATE_UPDATE, this.onNotificationUpdate);
CommunityPrototypeStore.instance.off(UPDATE_EVENT, this.onCommunityUpdate);
} }
private onAction = (payload: ActionPayload) => { private onAction = (payload: ActionPayload) => {

View File

@ -48,6 +48,10 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient<IState> {
return CommunityPrototypeStore.internalInstance; return CommunityPrototypeStore.internalInstance;
} }
public static getUpdateEventName(roomId: string): string {
return `${UPDATE_EVENT}:${roomId}`;
}
public getSelectedCommunityId(): string { public getSelectedCommunityId(): string {
if (SettingsStore.getValue("feature_communities_v2_prototypes")) { if (SettingsStore.getValue("feature_communities_v2_prototypes")) {
return GroupFilterOrderStore.getSelectedTags()[0]; return GroupFilterOrderStore.getSelectedTags()[0];
@ -134,7 +138,8 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient<IState> {
} }
} else if (payload.action === "MatrixActions.accountData") { } else if (payload.action === "MatrixActions.accountData") {
if (payload.event_type.startsWith("im.vector.group_info.")) { 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") { } else if (payload.action === "select_tag") {
// Automatically select the general chat when switching communities // Automatically select the general chat when switching communities
@ -167,7 +172,7 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient<IState> {
if (getEffectiveMembership(myMember.membership) === EffectiveMembership.Invite) { if (getEffectiveMembership(myMember.membership) === EffectiveMembership.Invite) {
// Fake an update for anything that might have started listening before the invite // Fake an update for anything that might have started listening before the invite
// data was available (eg: RoomPreviewBar after a refresh) // data was available (eg: RoomPreviewBar after a refresh)
this.emit(UPDATE_EVENT, room.roomId); this.emit(CommunityPrototypeStore.getUpdateEventName(room.roomId), room.roomId);
} }
} }
} }