mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-10 17:20:28 +03:00
Added space nesting (#52)
This commit is contained in:
parent
6c1a602bdc
commit
4efc320f23
18 changed files with 368 additions and 91 deletions
|
|
@ -7,6 +7,7 @@ class RoomList extends EventEmitter {
|
|||
super();
|
||||
this.matrixClient = matrixClient;
|
||||
this.mDirects = this.getMDirects();
|
||||
this.roomIdToParents = new Map();
|
||||
|
||||
this.inviteDirects = new Set();
|
||||
this.inviteSpaces = new Set();
|
||||
|
|
@ -24,13 +25,54 @@ class RoomList extends EventEmitter {
|
|||
appDispatcher.register(this.roomActions.bind(this));
|
||||
}
|
||||
|
||||
getSpaceChildren(roomId) {
|
||||
const space = this.matrixClient.getRoom(roomId);
|
||||
const mSpaceChild = space?.currentState.getStateEvents('m.space.child');
|
||||
const children = mSpaceChild?.map((mEvent) => {
|
||||
if (Object.keys(mEvent.event.content).length === 0) return null;
|
||||
return mEvent.event.state_key;
|
||||
});
|
||||
return children?.filter((child) => child !== null);
|
||||
}
|
||||
|
||||
addToRoomIdToParents(roomId, parentRoomId) {
|
||||
if (!this.roomIdToParents.has(roomId)) {
|
||||
this.roomIdToParents.set(roomId, new Set());
|
||||
}
|
||||
const parents = this.roomIdToParents.get(roomId);
|
||||
parents.add(parentRoomId);
|
||||
}
|
||||
|
||||
removeFromRoomIdToParents(roomId, parentRoomId) {
|
||||
if (!this.roomIdToParents.has(roomId)) return;
|
||||
const parents = this.roomIdToParents.get(roomId);
|
||||
parents.delete(parentRoomId);
|
||||
if (parents.size === 0) this.roomIdToParents.delete(roomId);
|
||||
}
|
||||
|
||||
addToSpaces(roomId) {
|
||||
this.spaces.add(roomId);
|
||||
const spaceChildren = this.getSpaceChildren(roomId);
|
||||
spaceChildren?.forEach((childRoomId) => {
|
||||
this.addToRoomIdToParents(childRoomId, roomId);
|
||||
});
|
||||
}
|
||||
|
||||
deleteFromSpaces(roomId) {
|
||||
this.spaces.delete(roomId);
|
||||
const spaceChildren = this.getSpaceChildren(roomId);
|
||||
spaceChildren?.forEach((childRoomId) => {
|
||||
this.removeFromRoomIdToParents(childRoomId, roomId);
|
||||
});
|
||||
}
|
||||
|
||||
roomActions(action) {
|
||||
const addRoom = (roomId, isDM) => {
|
||||
const myRoom = this.matrixClient.getRoom(roomId);
|
||||
if (myRoom === null) return false;
|
||||
|
||||
if (isDM) this.directs.add(roomId);
|
||||
else if (myRoom.isSpaceRoom()) this.spaces.add(roomId);
|
||||
else if (myRoom.isSpaceRoom()) this.addToSpaces(roomId);
|
||||
else this.rooms.add(roomId);
|
||||
return true;
|
||||
};
|
||||
|
|
@ -85,6 +127,7 @@ class RoomList extends EventEmitter {
|
|||
|
||||
_populateRooms() {
|
||||
this.directs.clear();
|
||||
this.roomIdToParents.clear();
|
||||
this.spaces.clear();
|
||||
this.rooms.clear();
|
||||
this.inviteDirects.clear();
|
||||
|
|
@ -109,7 +152,7 @@ class RoomList extends EventEmitter {
|
|||
if (room.getMyMembership() !== 'join') return;
|
||||
|
||||
if (this.mDirects.has(roomId)) this.directs.add(roomId);
|
||||
else if (room.isSpaceRoom()) this.spaces.add(roomId);
|
||||
else if (room.isSpaceRoom()) this.addToSpaces(roomId);
|
||||
else this.rooms.add(roomId);
|
||||
});
|
||||
}
|
||||
|
|
@ -165,8 +208,16 @@ class RoomList extends EventEmitter {
|
|||
}
|
||||
});
|
||||
|
||||
this.matrixClient.on('RoomState.events', (event) => {
|
||||
if (event.getType() !== 'm.room.join_rules') return;
|
||||
this.matrixClient.on('RoomState.events', (mEvent) => {
|
||||
if (mEvent.getType() === 'm.space.child') {
|
||||
const { event } = mEvent;
|
||||
const isRoomAdded = Object.keys(event.content).length > 0;
|
||||
if (isRoomAdded) this.addToRoomIdToParents(event.state_key, event.room_id);
|
||||
else this.removeFromRoomIdToParents(event.state_key, event.room_id);
|
||||
this.emit(cons.events.roomList.ROOMLIST_UPDATED);
|
||||
return;
|
||||
}
|
||||
if (mEvent.getType() !== 'm.room.join_rules') return;
|
||||
|
||||
this.emit(cons.events.roomList.ROOMLIST_UPDATED);
|
||||
});
|
||||
|
|
@ -207,7 +258,7 @@ class RoomList extends EventEmitter {
|
|||
const procRoomInfo = this.processingRooms.get(roomId);
|
||||
|
||||
if (procRoomInfo.isDM) this.directs.add(roomId);
|
||||
else if (room.isSpaceRoom()) this.spaces.add(roomId);
|
||||
else if (room.isSpaceRoom()) this.addToSpaces(roomId);
|
||||
else this.rooms.add(roomId);
|
||||
|
||||
if (procRoomInfo.task === 'CREATE') this.emit(cons.events.roomList.ROOM_CREATED, roomId);
|
||||
|
|
@ -218,7 +269,7 @@ class RoomList extends EventEmitter {
|
|||
return;
|
||||
}
|
||||
if (room.isSpaceRoom()) {
|
||||
this.spaces.add(roomId);
|
||||
this.addToSpaces(roomId);
|
||||
|
||||
this.emit(cons.events.roomList.ROOM_JOINED, roomId);
|
||||
this.emit(cons.events.roomList.ROOMLIST_UPDATED);
|
||||
|
|
@ -269,12 +320,12 @@ class RoomList extends EventEmitter {
|
|||
}
|
||||
// when room is not a DM add/remove it from rooms.
|
||||
if (membership === 'leave' || membership === 'kick' || membership === 'ban') {
|
||||
if (room.isSpaceRoom()) this.spaces.delete(roomId);
|
||||
if (room.isSpaceRoom()) this.deleteFromSpaces(roomId);
|
||||
else this.rooms.delete(roomId);
|
||||
this.emit(cons.events.roomList.ROOM_LEAVED, roomId);
|
||||
}
|
||||
if (membership === 'join') {
|
||||
if (room.isSpaceRoom()) this.spaces.add(roomId);
|
||||
if (room.isSpaceRoom()) this.addToSpaces(roomId);
|
||||
else this.rooms.add(roomId);
|
||||
this.emit(cons.events.roomList.ROOM_JOINED, roomId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ const cons = {
|
|||
actions: {
|
||||
navigation: {
|
||||
CHANGE_TAB: 'CHANGE_TAB',
|
||||
SELECT_SPACE: 'SELECT_SPACE',
|
||||
SELECT_ROOM: 'SELECT_ROOM',
|
||||
TOGGLE_PEOPLE_DRAWER: 'TOGGLE_PEOPLE_DRAWER',
|
||||
OPEN_INVITE_LIST: 'OPEN_INVITE_LIST',
|
||||
|
|
@ -34,6 +35,7 @@ const cons = {
|
|||
events: {
|
||||
navigation: {
|
||||
TAB_CHANGED: 'TAB_CHANGED',
|
||||
SPACE_SELECTED: 'SPACE_SELECTED',
|
||||
ROOM_SELECTED: 'ROOM_SELECTED',
|
||||
PEOPLE_DRAWER_TOGGLED: 'PEOPLE_DRAWER_TOGGLED',
|
||||
INVITE_LIST_OPENED: 'INVITE_LIST_OPENED',
|
||||
|
|
|
|||
|
|
@ -6,29 +6,44 @@ class Navigation extends EventEmitter {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
this.activeTab = 'home';
|
||||
this.activeRoomId = null;
|
||||
this.selectedTab = 'home';
|
||||
this.selectedSpaceId = null;
|
||||
this.selectedSpacePath = [];
|
||||
this.selectedRoomId = null;
|
||||
this.isPeopleDrawerVisible = true;
|
||||
|
||||
// TODO:
|
||||
window.navigation = this;
|
||||
}
|
||||
|
||||
getActiveTab() {
|
||||
return this.activeTab;
|
||||
}
|
||||
|
||||
getActiveRoomId() {
|
||||
return this.activeRoomId;
|
||||
_setSpacePath(roomId) {
|
||||
if (roomId === null) {
|
||||
this.selectedSpacePath = [];
|
||||
return;
|
||||
}
|
||||
if (this.selectedSpacePath.includes(roomId)) {
|
||||
const spIndex = this.selectedSpacePath.indexOf(roomId);
|
||||
this.selectedSpacePath = this.selectedSpacePath.slice(0, spIndex + 1);
|
||||
return;
|
||||
}
|
||||
this.selectedSpacePath.push(roomId);
|
||||
}
|
||||
|
||||
navigate(action) {
|
||||
const actions = {
|
||||
[cons.actions.navigation.CHANGE_TAB]: () => {
|
||||
this.activeTab = action.tabId;
|
||||
this.emit(cons.events.navigation.TAB_CHANGED, this.activeTab);
|
||||
this.selectedTab = action.tabId;
|
||||
this.emit(cons.events.navigation.TAB_CHANGED, this.selectedTab);
|
||||
},
|
||||
[cons.actions.navigation.SELECT_SPACE]: () => {
|
||||
this._setSpacePath(action.roomId);
|
||||
this.selectedSpaceId = action.roomId;
|
||||
this.emit(cons.events.navigation.SPACE_SELECTED, action.roomId);
|
||||
},
|
||||
[cons.actions.navigation.SELECT_ROOM]: () => {
|
||||
const prevActiveRoomId = this.activeRoomId;
|
||||
this.activeRoomId = action.roomId;
|
||||
this.emit(cons.events.navigation.ROOM_SELECTED, this.activeRoomId, prevActiveRoomId);
|
||||
const prevSelectedRoomId = this.selectedRoomId;
|
||||
this.selectedRoomId = action.roomId;
|
||||
this.emit(cons.events.navigation.ROOM_SELECTED, this.selectedRoomId, prevSelectedRoomId);
|
||||
},
|
||||
[cons.actions.navigation.TOGGLE_PEOPLE_DRAWER]: () => {
|
||||
this.isPeopleDrawerVisible = !this.isPeopleDrawerVisible;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue