cetirizine

An experimental matrix client written in reactjs utilizing tailwind and storybook
git clone git://archive.git.mtrnord.blog/MTRNord/cetirizine.git
Log | Files | Refs | README | LICENSE

commit 1ddd18664e42773d5f25b9cf1c527eb23b9f6f63
parent 079b0333e20bad9f8f11084a826aba60b24b7ded
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue,  9 May 2023 22:11:54 +0200

Move DMs to own section

Diffstat:
Msrc/app/sdk/slidingSync.ts | 2++
Msrc/components/roomList/roomList.tsx | 19++++++++++++++++++-
Msrc/pages/MainPage.tsx | 19+++++++++++++++----
3 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/app/sdk/slidingSync.ts b/src/app/sdk/slidingSync.ts @@ -189,6 +189,7 @@ export class MatrixSlidingSync extends EventEmitter { }; for (const space of this.client.spaceOpen) { if (space === "other") { continue } + if (space === "dm") { continue } lists_ranges[space] = [[0, 20]]; } @@ -358,6 +359,7 @@ export class MatrixSlidingSync extends EventEmitter { for (const space of this.client.spaceOpen) { if (space === "other") { continue } + if (space === "dm") { continue } if (!body.lists) { body.lists = {}; } diff --git a/src/components/roomList/roomList.tsx b/src/components/roomList/roomList.tsx @@ -58,6 +58,10 @@ type RoomListProps = { * Rooms outside of any Sections */ rooms: Room[] + /** + * Rooms outside of any Sections and DM + */ + dmRooms: Room[] }; type RoomListRoomsProps = { @@ -160,12 +164,25 @@ const RoomSection: FC<{ section: Section, onRoomClick: (roomID: string) => void, ); }) -const RoomList: FC<RoomListProps> = memo(({ sections, rooms }: RoomListProps) => { +const RoomList: FC<RoomListProps> = memo(({ sections, rooms, dmRooms }: RoomListProps) => { const [activeRoom, setActiveRoom] = useState<string | undefined>(undefined); const navigate = useNavigate(); return ( <div className="flex flex-col gap-1 flex-1 p-2 min-w-[30ch] overflow-y-auto overflow-x-hidden scrollbarSmall max-w-[33ch]"> + <RoomSection + section={{ + sectionName: "DMs", + roomID: "dms", + subsections: [], + rooms: dmRooms + }} + onRoomClick={(roomID: string) => { + setActiveRoom(roomID); + navigate(`/${encodeURIComponent(roomID)}`); + }} + activeRoom={activeRoom} + /> { sections.map(section => { return ( diff --git a/src/pages/MainPage.tsx b/src/pages/MainPage.tsx @@ -241,7 +241,7 @@ const MainPage = memo(() => { // The toplevel section "Other" is always present. // The toplevel section "Other" is always the last section. const sections = toplevelSpaces.map(space => { - const rooms = [...space.children].filter(room => !room.isSpace() && !room.isTombstoned()).sort((a, b) => { + const rooms = [...space.children].filter(room => !room.isSpace() && !room.isTombstoned() && !room.isDM()).sort((a, b) => { // Sort rooms by sliding sync list order of the spaces list, // Get the index of the room in the sync list. @@ -273,7 +273,7 @@ const MainPage = memo(() => { const generateSubsections = (subspace: Room): Section | undefined => { const subspaceMeta = [...spacesWithRooms].find(space => space.spaceRoom.roomID === subspace.roomID); if (subspaceMeta) { - const rooms = [...subspaceMeta?.children].filter(room => !room.isSpace() && !room.isTombstoned()).map(room => { + const rooms = [...subspaceMeta?.children].filter(room => !room.isSpace() && !room.isTombstoned() && !room.isDM()).map(room => { return { roomID: room.roomID, displayname: room.getName(), @@ -307,7 +307,7 @@ const MainPage = memo(() => { }); // Add the toplevel section "Other" to the end of the list. - const otherRooms = leftOverRooms.filter(room => !room.isSpace()).map(room => { + const otherRooms = leftOverRooms.filter(room => !room.isSpace() && !room.isDM()).map(room => { return { roomID: room.roomID, displayname: room.getName(), @@ -317,6 +317,17 @@ const MainPage = memo(() => { } }); + const dmRooms = leftOverRooms.filter(room => !room.isSpace() && room.isDM()).map(room => { + return { + roomID: room.roomID, + displayname: room.getName(), + avatarUrl: room.getAvatarURL(), + dm: room.isDM(), + online: room.presence, + } + }); + + // Check and print if otherRooms has duplicates. const otherRoomsIDs = otherRooms.map(room => room.roomID); const otherRoomsDuplicates = otherRoomsIDs.filter((id, index) => otherRoomsIDs.indexOf(id) !== index); @@ -340,7 +351,7 @@ const MainPage = memo(() => { <Settings size={28} stroke='unset' className='stroke-slate-600 rounded-full hover:bg-slate-300 p-1 cursor-pointer' /> </div> </div> - <RoomList sections={sections} rooms={otherRooms} /> + <RoomList sections={sections} rooms={otherRooms} dmRooms={dmRooms} /> </div> { room && <div className='flex-1 flex flex-col' id='room-wrapper'>