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.
This commit is contained in:
parent
729356394e
commit
8a341446aa
2 changed files with 23 additions and 4 deletions
src
|
@ -107,7 +107,10 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
|
|||
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<IProps, IState> {
|
|||
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<IProps, IState> {
|
|||
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) => {
|
||||
|
|
|
@ -48,6 +48,10 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient<IState> {
|
|||
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<IState> {
|
|||
}
|
||||
} 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<IState> {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue