Skip to content

Commit

Permalink
Fix contact avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed May 29, 2024
1 parent e5e3dd1 commit b3e881c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
22 changes: 22 additions & 0 deletions connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion puppet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit b3e881c

Please sign in to comment.