aboutsummaryrefslogtreecommitdiff
path: root/matrix/rooms
diff options
context:
space:
mode:
Diffstat (limited to 'matrix/rooms')
-rw-r--r--matrix/rooms/room.go13
-rw-r--r--matrix/rooms/roomcache.go28
2 files changed, 38 insertions, 3 deletions
diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go
index 0238cfb..d5d1d8f 100644
--- a/matrix/rooms/room.go
+++ b/matrix/rooms/room.go
@@ -412,7 +412,7 @@ func (room *Room) UpdateState(evt *event.Event) {
case *event.TopicEventContent:
room.topicCache = content.Topic
case *event.EncryptionEventContent:
- if content.Algorithm == event.AlgorithmMegolmV1 {
+ if content.Algorithm == id.AlgorithmMegolmV1 {
room.Encrypted = true
}
}
@@ -650,6 +650,17 @@ func (room *Room) GetMembers() map[id.UserID]*Member {
return room.memberCache
}
+func (room *Room) GetMemberList() []id.UserID {
+ members := room.GetMembers()
+ memberList := make([]id.UserID, len(members))
+ index := 0
+ for userID, _ := range members {
+ memberList[index] = userID
+ index++
+ }
+ return memberList
+}
+
// GetMember returns the member with the given MXID.
// If the member doesn't exist, nil is returned.
func (room *Room) GetMember(userID id.UserID) *Member {
diff --git a/matrix/rooms/roomcache.go b/matrix/rooms/roomcache.go
index ffdcad1..5af0c5b 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()
@@ -115,11 +139,11 @@ func (cache *RoomCache) LoadList() error {
func (cache *RoomCache) SaveLoadedRooms() {
cache.Lock()
- defer cache.Unlock()
cache.clean(false)
for node := cache.head; node != nil; node = node.prev {
node.Save()
}
+ cache.Unlock()
}
func (cache *RoomCache) SaveList() error {
@@ -169,7 +193,7 @@ func (cache *RoomCache) Touch(roomID id.RoomID) {
}
func (cache *RoomCache) TouchNode(node *Room) {
- if cache.noUnload || node.touch + 2 > time.Now().Unix() {
+ if cache.noUnload || node.touch+2 > time.Now().Unix() {
return
}
cache.Lock()