1
0
Fork 0
forked from Mirrors/gomuks

web/roomlist: close room when switching space

This commit is contained in:
Tulir Asokan 2024-12-31 13:51:21 +02:00
parent 7afcc37326
commit d0c35dda75
3 changed files with 14 additions and 3 deletions

View file

@ -77,7 +77,7 @@ export class StateStore {
readonly spaceEdges: Map<RoomID, SpaceEdgeStore> = new Map()
readonly spaceOrphans = new SpaceOrphansSpace(this)
readonly directChatsSpace = new DirectChatSpace()
readonly unreadsSpace = new UnreadsSpace()
readonly unreadsSpace = new UnreadsSpace(this)
readonly pseudoSpaces = [
this.spaceOrphans,
this.directChatsSpace,

View file

@ -79,8 +79,13 @@ export class DirectChatSpace extends Space {
export class UnreadsSpace extends Space {
id = "fi.mau.gomuks.unreads"
constructor(private parent: StateStore) {
super()
}
include(room: RoomListEntry): boolean {
return Boolean(room.unread_messages
return Boolean(room.room_id === this.parent.activeRoomID
|| room.unread_messages
|| room.unread_notifications
|| room.unread_highlights
|| room.marked_unread)

View file

@ -49,7 +49,13 @@ const RoomList = ({ activeRoomID }: RoomListProps) => {
const setSpace = useCallback((space: RoomListFilter | null) => {
directSetSpace(space)
client.store.currentRoomListFilter = space
}, [client])
if (client.store.activeRoomID && space) {
const entry = client.store.rooms.get(client.store.activeRoomID)?.roomListEntry
if (entry && !space.include(entry)) {
mainScreen.setActiveRoom(null)
}
}
}, [client, mainScreen])
const onClickSpace = useCallback((evt: React.MouseEvent<HTMLDivElement>) => {
const store = client.store.getSpaceStore(evt.currentTarget.getAttribute("data-target-space")!)
setSpace(store)