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

Commit

Permalink
Fix RightPanelStore assuming isViewingRoom is false on load (#7642)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Jan 26, 2022
1 parent 225f894 commit e18bbb0
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/stores/right-panel/RightPanelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ const GROUP_PHASES = [
*/
export default class RightPanelStore extends ReadyWatchingStore {
private static internalInstance: RightPanelStore;
private readonly dispatcherRefRightPanelStore: string;
private viewedRoomId: string;
private isViewingRoom?: boolean;
private dispatcherRefRightPanelStore: string;
private isReady = false;

private global?: IRightPanelForRoom = null;
Expand Down Expand Up @@ -228,9 +227,8 @@ export default class RightPanelStore extends ReadyWatchingStore {
}
}

// Private
private loadCacheFromSettings() {
const room = this.mxClient?.getRoom(this.viewedRoomId);
const room = this.viewedRoomId && this.mxClient?.getRoom(this.viewedRoomId);
if (!!room) {
this.global = this.global ??
convertToStatePanel(SettingsStore.getValue("RightPanel.phasesGlobal"), room);
Expand Down Expand Up @@ -362,10 +360,9 @@ export default class RightPanelStore extends ReadyWatchingStore {
}
};

onRoomViewStoreUpdate = () => {
private onRoomViewStoreUpdate = () => {
// TODO: only use this function instead of the onDispatch (the whole onDispatch can get removed!) as soon groups are removed
this.viewedRoomId = RoomViewStore.getRoomId();
this.isViewingRoom = true; // Is viewing room will of course be removed when removing groups
// load values from byRoomCache with the viewedRoomId.
this.loadCacheFromSettings();
// If the right panel stays open mode is used, and the panel was either
Expand All @@ -386,11 +383,13 @@ export default class RightPanelStore extends ReadyWatchingStore {
this.emitAndUpdateSettings();
};

onDispatch = (payload: ActionPayload) => {
private get isViewingRoom(): boolean {
return !!this.viewedRoomId;
}

private onDispatch = (payload: ActionPayload) => {
switch (payload.action) {
case 'view_group': {
if (payload.room_id === this.viewedRoomId) break; // skip this transition, probably a permalink

// Put group in the same/similar view to what was open from the previously viewed room
// Is contradictory to the new "per room" philosophy but it is the legacy behavior for groups.

Expand All @@ -401,10 +400,8 @@ export default class RightPanelStore extends ReadyWatchingStore {
this.setRightPanelCache({ phase: RightPanelPhases.GroupMemberList, state: {} });
}

// Update the current room here, so that all the other functions dont need to be room dependant.
// The right panel store always will return the state for the current room.
this.viewedRoomId = payload.room_id;
this.isViewingRoom = false;
this.viewedRoomId = null; // a group is not a room
// load values from byRoomCache with the viewedRoomId.
if (this.isReady) {
// we need the client to be ready to get the events form the ids of the settings
Expand Down

0 comments on commit e18bbb0

Please sign in to comment.