From c5a7ccaf89167ffc63187da7383c919aa45054fc Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 31 May 2024 15:47:27 +0300 Subject: [PATCH] Fix contact avatars --- portal.go | 8 ++++---- puppet.go | 5 ++++- user.go | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/portal.go b/portal.go index 2e90ac77..69223110 100644 --- a/portal.go +++ b/portal.go @@ -892,7 +892,7 @@ func (portal *Portal) handleSignalDataMessage(source *User, sender *Puppet, msg Uint64("msg_ts", msg.GetTimestamp()). Logger().WithContext(context.TODO()) // Always update sender info when we receive a message from them, there's caching inside the function - sender.UpdateInfo(genericCtx, source) + sender.UpdateInfo(genericCtx, source, nil) // Handle earlier missed group changes here. if msg.GetGroupV2() != nil { requiredRevision := msg.GetGroupV2().GetRevision() @@ -1800,7 +1800,7 @@ func (portal *Portal) CreateMatrixRoom(ctx context.Context, user *User, groupRev if portal.IsPrivateChat() { dmPuppet = portal.GetDMPuppet() if dmPuppet != nil { - dmPuppet.UpdateInfo(ctx, user) + dmPuppet.UpdateInfo(ctx, user, nil) portal.UpdateDMInfo(ctx, false) } else { portal.UpdatePNIDMInfo(ctx, user) @@ -1900,7 +1900,7 @@ func (portal *Portal) PostReIDUpdate(ctx context.Context, user *User) { if err != nil { zerolog.Ctx(ctx).Err(err).Msg("Failed to update ghost power level after portal re-ID") } - portal.GetDMPuppet().UpdateInfo(ctx, user) + portal.GetDMPuppet().UpdateInfo(ctx, user, nil) portal.UpdateDMInfo(ctx, true) if !portal.Encrypted { _, _ = portal.bridge.Bot.LeaveRoom(ctx, portal.MXID) @@ -2298,7 +2298,7 @@ func (portal *Portal) SyncParticipants(ctx context.Context, source *User, info * log.Warn().Stringer("signal_user_id", member.ACI).Msg("Couldn't get puppet for group member") continue } - puppet.UpdateInfo(ctx, source) + puppet.UpdateInfo(ctx, source, nil) intent := puppet.IntentFor(portal) if member.ACI != source.SignalID && portal.MXID != "" { userIDs[intent.UserID] = ((int)(member.Role) >> 1) * 50 diff --git a/puppet.go b/puppet.go index f58befa8..857312eb 100644 --- a/puppet.go +++ b/puppet.go @@ -232,7 +232,7 @@ func (puppet *Puppet) GetAvatarURL() id.ContentURI { return puppet.AvatarURL } -func (puppet *Puppet) UpdateInfo(ctx context.Context, source *User) { +func (puppet *Puppet) UpdateInfo(ctx context.Context, source *User, contactAvatar *types.ContactAvatar) { log := zerolog.Ctx(ctx).With(). Str("function", "Puppet.UpdateInfo"). Stringer("signal_user_id", puppet.SignalID). @@ -252,6 +252,9 @@ func (puppet *Puppet) UpdateInfo(ctx context.Context, source *User) { Msg("Ignoring outdated contact info") return } + if contactAvatar != nil { + info.ContactAvatar = *contactAvatar + } log.Trace().Msg("Updating puppet info") diff --git a/user.go b/user.go index a579e8b5..0814c3e2 100644 --- a/user.go +++ b/user.go @@ -755,7 +755,7 @@ func (user *User) handleContactList(evt *events.ContactList) { if puppet == nil { continue } - puppet.UpdateInfo(ctx, user) + puppet.UpdateInfo(ctx, user, &contact.ContactAvatar) } }