aboutsummaryrefslogtreecommitdiff
path: root/matrix
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2019-06-16 15:15:30 +0300
committerTulir Asokan <tulir@maunium.net>2019-06-16 15:15:30 +0300
commit1ea6ba026aab8b9d3e66681c97043b5806ef4971 (patch)
tree25c6421dc5da1b96d2d7804eccad94ed8a2ee1a1 /matrix
parent2b7d5d54011ffcc93511bf05f44163a4b7a1270c (diff)
Make displayname pushrule check possible without loading room state
Diffstat (limited to 'matrix')
-rw-r--r--matrix/rooms/room.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go
index be91065..4928871 100644
--- a/matrix/rooms/room.go
+++ b/matrix/rooms/room.go
@@ -73,6 +73,7 @@ type Room struct {
PrevBatch string
// The MXID of the user whose session this room was created for.
SessionUserID string
+ SessionMember *mautrix.Member
// The number of unread messages that were notified about.
UnreadMessages []UnreadMessage
@@ -362,8 +363,11 @@ func (room *Room) UpdateState(event *mautrix.Event) {
}
room.aliasesCache = nil
case mautrix.StateMember:
+ userID := event.GetStateKey()
+ if userID == room.SessionUserID {
+ room.SessionMember = room.eventToMember(userID, &event.Content)
+ }
if room.memberCache != nil {
- userID := event.GetStateKey()
if event.Content.Membership == mautrix.MembershipLeave || event.Content.Membership == mautrix.MembershipBan {
delete(room.memberCache, userID)
} else if event.Content.Membership == mautrix.MembershipInvite || event.Content.Membership == mautrix.MembershipJoin {
@@ -567,6 +571,9 @@ func (room *Room) createMemberCache() map[string]*mautrix.Member {
cache[userID] = member
room.updateNthMemberCache(userID, member)
}
+ if userID == room.SessionUserID {
+ room.SessionMember = member
+ }
}
}
room.lock.RUnlock()
@@ -589,6 +596,9 @@ func (room *Room) GetMembers() map[string]*mautrix.Member {
// GetMember returns the member with the given MXID.
// If the member doesn't exist, nil is returned.
func (room *Room) GetMember(userID string) *mautrix.Member {
+ if userID == room.SessionUserID && room.SessionMember != nil {
+ return room.SessionMember
+ }
room.Load()
room.createMemberCache()
room.lock.RLock()