diff --git a/connector/connector.go b/connector/connector.go index 770259c8..f332dc5e 100644 --- a/connector/connector.go +++ b/connector/connector.go @@ -412,10 +412,32 @@ func (s *SignalClient) handleSignalEvent(rawEvt events.SignalEvent) { case *events.ReadSelf: case *events.Call: case *events.ContactList: + s.handleSignalContactList(evt) case *events.ACIFound: } } +func (s *SignalClient) handleSignalContactList(evt *events.ContactList) { + log := s.UserLogin.Log.With().Str("action", "handle contact list").Logger() + ctx := log.WithContext(context.TODO()) + for _, contact := range evt.Contacts { + if contact.ACI != uuid.Nil { + fullContact, err := s.Client.ContactByACI(ctx, contact.ACI) + if err != nil { + log.Err(err).Msg("Failed to get full contact info from store") + continue + } + fullContact.ContactAvatar = contact.ContactAvatar + ghost, err := s.Main.Bridge.GetGhostByID(ctx, makeUserID(contact.ACI)) + if err != nil { + log.Err(err).Msg("Failed to get ghost to update contact info") + continue + } + ghost.UpdateInfo(ctx, s.contactToUserInfo(contact)) + } + } +} + func (s *SignalClient) HandleMatrixMessage(ctx context.Context, msg *bridgev2.MatrixMessage) (message *database.Message, err error) { mcCtx := &msgconvContext{ Connector: s.Main, diff --git a/portal.go b/portal.go index b0ba6353..0369c045 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 0a72b05f..dc16f980 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) } }