Fix MUC member nickname changes

This commit is contained in:
Bohdan Horbeshko 2025-08-16 09:32:23 -04:00
parent 623af72cdd
commit 983c0102a4
2 changed files with 7 additions and 3 deletions

View file

@ -149,13 +149,13 @@ func (c *Client) updateHandler() {
// new user discovered
func (c *Client) updateUser(update *client.UpdateUser) {
// check if MUC nicknames should be updated
cacheUser, ok := c.cache.GetUser(update.User.Id)
if ok && (cacheUser.FirstName != update.User.FirstName || cacheUser.LastName != update.User.LastName) {
oldCacheUser, ok := c.cache.GetUser(update.User.Id)
c.cache.SetUser(update.User.Id, update.User)
if ok && (oldCacheUser.FirstName != update.User.FirstName || oldCacheUser.LastName != update.User.LastName) {
newNickname := c.GetMUCNickname(update.User.Id)
c.updateMUCsNickname(update.User.Id, newNickname)
}
c.cache.SetUser(update.User.Id, update.User)
show, status, presenceType := c.userStatusToText(update.User.Status, update.User.Id)
go c.ProcessStatusUpdate(update.User.Id, status, show, gateway.SPType(presenceType))
}

View file

@ -890,6 +890,10 @@ func (c *Client) updateMUCsNickname(memberID int64, newNickname string) {
for mucId, state := range c.mucCache {
oldOccupant, ok := state.Occupants.Get(memberID)
if ok {
c.DelayedStatusesLock.Lock()
delete(c.DelayedStatuses, mucId)
c.DelayedStatusesLock.Unlock()
deleted := state.Occupants.Set(memberID, &MUCOccupant{
Nickname: newNickname,
Affiliation: oldOccupant.Affiliation,