diff options
author | Tulir Asokan <tulir@maunium.net> | 2020-05-06 20:06:35 +0300 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2020-05-06 20:06:35 +0300 |
commit | 5b3e91524e000fe07fe30eff70061c9dd796014e (patch) | |
tree | 47eac32a4ce211b7d240841fe35e1a0cb745680c /matrix/rooms/roomcache.go | |
parent | 96bb87e8ac8f45d56d487ea6c16d67f057d97e1f (diff) | |
parent | ebdfe914283fb91204ca8512a0a73a78fe41998f (diff) |
Merge branch 'e2ee'
Diffstat (limited to 'matrix/rooms/roomcache.go')
-rw-r--r-- | matrix/rooms/roomcache.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/matrix/rooms/roomcache.go b/matrix/rooms/roomcache.go index ffdcad1..067cbb6 100644 --- a/matrix/rooms/roomcache.go +++ b/matrix/rooms/roomcache.go @@ -27,6 +27,7 @@ import ( sync "github.com/sasha-s/go-deadlock" "maunium.net/go/gomuks/debug" + "maunium.net/go/mautrix/event" "maunium.net/go/mautrix/id" ) @@ -67,6 +68,29 @@ func (cache *RoomCache) EnableUnloading() { cache.noUnload = false } +func (cache *RoomCache) IsEncrypted(roomID id.RoomID) bool { + room := cache.Get(roomID) + return room != nil && room.Encrypted +} + +func (cache *RoomCache) FindSharedRooms(userID id.UserID) (shared []id.RoomID) { + // FIXME this disables unloading so TouchNode wouldn't try to double-lock + cache.DisableUnloading() + cache.Lock() + for _, room := range cache.Map { + if !room.Encrypted { + continue + } + member, ok := room.GetMembers()[userID] + if ok && member.Membership == event.MembershipJoin { + shared = append(shared, room.ID) + } + } + cache.Unlock() + cache.EnableUnloading() + return +} + func (cache *RoomCache) LoadList() error { cache.Lock() defer cache.Unlock() |