matrix: stop updating the global display names

We can afford to do that (which should stress less the [matrix]
homeservers) because we no longer drop all the user displaynames
across all channels) when we see a Leave or Ban membership event
This commit is contained in:
Simon THOBY
2022-08-14 16:40:27 +02:00
committed by Simon Thoby
parent 625d7cd94c
commit 09bc5379b7
2 changed files with 19 additions and 24 deletions

View File

@@ -75,15 +75,6 @@ func (b *Bmatrix) handleEvent(origin EventOrigin, ev *event.Event) {
b.Unlock()
}
// if we receive messages both via the classical matrix syncer and appserver, prefer appservice and throw away this duplicate event
if channel.appService && origin != originAppService {
b.Log.Debugf("Dropping event, should receive it via appservice: %s", ev.ID)
return
}
b.Log.Debugf("== Receiving event: %#v (appService=%t)", ev, origin == originAppService)
if ev.Type == event.EphemeralEventTyping {
typing := ev.Content.AsTyping()
if len(typing.UserIDs) > 0 {
@@ -98,6 +89,15 @@ func (b *Bmatrix) handleEvent(origin EventOrigin, ev *event.Event) {
return
}
// if we receive messages both via the classical matrix syncer and appserver, prefer appservice and throw away this duplicate event
if channel.appService && origin != originAppService {
b.Log.Debugf("Dropping event, should receive it via appservice: %s", ev.ID)
return
}
b.Log.Debugf("== Receiving event: %#v (appService=%t)", ev, origin == originAppService)
defer (func(ev *event.Event) {
// not crucial, so no ratelimit check here
if err := b.mc.MarkRead(ev.RoomID, ev.ID); err != nil {
@@ -146,7 +146,7 @@ func (b *Bmatrix) handleMemberChange(ev *event.Event) {
if member.Membership == event.MembershipJoin {
b.cacheDisplayName(ev.RoomID, ev.Sender, member.Displayname)
} else if member.Membership == event.MembershipLeave || member.Membership == event.MembershipBan {
b.removeDisplayNameFromCache(ev.Sender)
b.removeDisplayNameFromCache(ev.Sender, ev.RoomID)
}
}

View File

@@ -88,9 +88,6 @@ func (c *NicknameCache) retrieveDisplaynameFromCache(channelID id.RoomID, mxid i
}
if cachedEntry.conflictWithOtherUsername {
// TODO: the current behavior is that only users with clashing usernames and *that have
// spoken since the bridge started* will get their mxids shown, and this doesn't
// feel right
return fmt.Sprintf("%s (%s)", cachedEntry.displayName, mxid)
}
@@ -232,18 +229,11 @@ func (b *Bmatrix) cacheDisplayName(channelID id.RoomID, mxid id.UserID, displayN
conflictWithOtherUsername: conflict,
}
// this is a local (room-specific) display name, let's cache it as such
if channelID == "" {
newEntry.globalEntry = &cacheEntry
} else {
globalDisplayName := b.retrieveGlobalDisplayname(mxid)
// updating the global display name or resetting the room name to the global name
if globalDisplayName == displayName {
delete(newEntry.perChannel, channelID)
newEntry.globalEntry = &cacheEntry
} else {
newEntry.perChannel[channelID] = cacheEntry
}
// this is a local (room-specific) display name, let's cache it as such
newEntry.perChannel[channelID] = cacheEntry
}
cache.users[mxid] = newEntry
@@ -251,13 +241,18 @@ func (b *Bmatrix) cacheDisplayName(channelID id.RoomID, mxid id.UserID, displayN
return displayName
}
func (b *Bmatrix) removeDisplayNameFromCache(mxid id.UserID) {
func (b *Bmatrix) removeDisplayNameFromCache(mxid id.UserID, roomID id.RoomID) {
cache := b.NicknameCache
cache.Lock()
defer cache.Unlock()
delete(cache.users, mxid)
if user, userPresent := cache.users[mxid]; userPresent {
if _, roomPresent := user.perChannel[roomID]; roomPresent {
delete(user.perChannel, roomID)
cache.users[mxid] = user
}
}
}
// getAvatarURL returns the avatar URL of the specified sender.