Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify space to room mapping logic #7

Merged
merged 1 commit into from
Apr 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions src/client/state/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Navigation extends EventEmitter {
}

_mapRoomToSpace(roomId) {
const { roomList, accountData } = this.initMatrix;
const { roomList } = this.initMatrix;
if (
this.selectedTab === cons.tabs.HOME
&& roomList.rooms.has(roomId)
Expand All @@ -59,23 +59,10 @@ class Navigation extends EventEmitter {
return;
}

const parents = roomList.roomIdToParents.get(roomId);
if (!parents) return;
if (parents.has(this.selectedSpaceId)) {
this.spaceToRoom.set(this.selectedSpaceId, {
roomId,
timestamp: Date.now(),
});
} else if (accountData.categorizedSpaces.has(this.selectedSpaceId)) {
const categories = roomList.getCategorizedSpaces([this.selectedSpaceId]);
const parent = [...parents].find((pId) => categories.has(pId));
if (parent) {
this.spaceToRoom.set(parent, {
roomId,
timestamp: Date.now(),
});
}
}
this.spaceToRoom.set(this.selectedSpaceId, {
roomId,
timestamp: Date.now(),
});
}

_selectRoom(roomId, eventId) {
Expand Down Expand Up @@ -202,7 +189,7 @@ class Navigation extends EventEmitter {
const { categorizedSpaces } = accountData;

const data = this.spaceToRoom.get(spaceId);
if (data && !categorizedSpaces.has(spaceId)) {
if (data) {
this._selectRoom(data.roomId);
return;
}
Expand All @@ -212,13 +199,6 @@ class Navigation extends EventEmitter {
if (categorizedSpaces.has(spaceId)) {
const categories = roomList.getCategorizedSpaces([spaceId]);

const latestSelectedRoom = this._getLatestSelectedRoomId([...categories.keys()]);

if (latestSelectedRoom) {
this._selectRoom(latestSelectedRoom);
return;
}

categories?.forEach((categoryId) => {
categoryId?.forEach((childId) => {
children.push(childId);
Expand Down