Update sidbar on room select from search (#374)

This commit is contained in:
Ajay Bura 2022-08-19 19:30:29 +05:30
parent 74ffd6280f
commit 010e3cca82

View file

@ -73,7 +73,7 @@ class Navigation extends EventEmitter {
_selectRoom(roomId, eventId) { _selectRoom(roomId, eventId) {
const prevSelectedRoomId = this.selectedRoomId; const prevSelectedRoomId = this.selectedRoomId;
this.selectedRoomId = roomId; this.selectedRoomId = roomId;
this._addSelectedSpaceToRoom(roomId); if (prevSelectedRoomId !== roomId) this._addSelectedSpaceToRoom(roomId);
this.removeRecentRoom(prevSelectedRoomId); this.removeRecentRoom(prevSelectedRoomId);
this.addRecentRoom(prevSelectedRoomId); this.addRecentRoom(prevSelectedRoomId);
this.removeRecentRoom(this.selectedRoomId); this.removeRecentRoom(this.selectedRoomId);
@ -89,6 +89,32 @@ class Navigation extends EventEmitter {
); );
} }
_selectTabWithRoom(roomId) {
const { roomList } = this.initMatrix;
if (roomList.directs.has(roomId)) {
this._selectSpace(null, true, false);
this._selectTab(cons.tabs.DIRECTS, false);
return;
}
if (roomList.isOrphan(roomId)) {
this._selectSpace(null, true, false);
this._selectTab(cons.tabs.HOME, false);
return;
}
const parents = [...roomList.roomIdToParents.get(roomId)];
if (parents) {
const sortedParents = parents.sort((p1, p2) => {
const t1 = this.selectedSpaceToRoom.get(p1)?.timestamp ?? 0;
const t2 = this.selectedSpaceToRoom.get(p2)?.timestamp ?? 0;
return t2 - t1;
});
this._selectSpace(sortedParents[0], true, false);
this._selectTab(sortedParents[0], false);
}
}
_getLatestActiveRoomId(roomIds) { _getLatestActiveRoomId(roomIds) {
const mx = this.initMatrix.matrixClient; const mx = this.initMatrix.matrixClient;
@ -106,6 +132,19 @@ class Navigation extends EventEmitter {
return roomId; return roomId;
} }
_selectTab(tabId, selectRoom = true) {
this.selectedTab = tabId;
if (selectRoom) this._selectRoomWithTab(this.selectedTab);
this.emit(cons.events.navigation.TAB_SELECTED, this.selectedTab);
}
_selectSpace(roomId, asBase, selectRoom = true) {
this._setSpacePath(roomId, asBase);
this.selectedSpaceId = roomId;
if (!asBase && selectRoom) this._selectRoomWithSpace(this.selectedSpaceId);
this.emit(cons.events.navigation.SPACE_SELECTED, this.selectedSpaceId);
}
_selectRoomWithSpace(spaceId) { _selectRoomWithSpace(spaceId) {
if (!spaceId) return; if (!spaceId) return;
const data = this.selectedSpaceToRoom.get(spaceId); const data = this.selectedSpaceToRoom.get(spaceId);
@ -167,17 +206,13 @@ class Navigation extends EventEmitter {
navigate(action) { navigate(action) {
const actions = { const actions = {
[cons.actions.navigation.SELECT_TAB]: () => { [cons.actions.navigation.SELECT_TAB]: () => {
this.selectedTab = action.tabId; this._selectTab(action.tabId);
this._selectRoomWithTab(this.selectedTab);
this.emit(cons.events.navigation.TAB_SELECTED, this.selectedTab);
}, },
[cons.actions.navigation.SELECT_SPACE]: () => { [cons.actions.navigation.SELECT_SPACE]: () => {
this._setSpacePath(action.roomId, action.asBase); this._selectSpace(action.roomId, action.asBase);
this.selectedSpaceId = action.roomId;
if (!action.asBase) this._selectRoomWithSpace(this.selectedSpaceId);
this.emit(cons.events.navigation.SPACE_SELECTED, this.selectedSpaceId);
}, },
[cons.actions.navigation.SELECT_ROOM]: () => { [cons.actions.navigation.SELECT_ROOM]: () => {
this._selectTabWithRoom(action.roomId);
this._selectRoom(action.roomId, action.eventId); this._selectRoom(action.roomId, action.eventId);
}, },
[cons.actions.navigation.OPEN_SPACE_SETTINGS]: () => { [cons.actions.navigation.OPEN_SPACE_SETTINGS]: () => {