Skip to content

Commit

Permalink
Update profile avatar paths & hashes properly
Browse files Browse the repository at this point in the history
- Store updates to profile avatar hashes in signalmeow_contacts
- Have puppets use the stored contact avatar hash rather than
  recomputing it
- Have puppets update their avatar path when the profile avatar path
  changed but the hash did not
- Have puppets clear their avatar path when using a contact avatar
  instead of a profile avatar
  • Loading branch information
AndrewFerr committed Mar 7, 2024
1 parent 100a81a commit d451d51
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions puppet.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ func (puppet *Puppet) updateAvatar(ctx context.Context, source *User, info *type
// TODO what to do? 🤔
return false
}
puppet.AvatarSet = false
puppet.AvatarPath = ""
puppet.AvatarHash = info.ContactAvatar.Hash
} else {
if puppet.AvatarPath == info.Profile.AvatarPath && puppet.AvatarSet {
return false
Expand Down Expand Up @@ -354,19 +354,24 @@ func (puppet *Puppet) updateAvatar(ctx context.Context, source *User, info *type
return true
}
avatarContentType = http.DetectContentType(avatarData)
puppet.AvatarPath = info.Profile.AvatarPath
hash := sha256.Sum256(avatarData)
newHash := hex.EncodeToString(hash[:])
if puppet.AvatarHash == newHash && puppet.AvatarSet {
log.Debug().
Str("avatar_hash", newHash).
Str("new_avatar_path", puppet.AvatarPath).
Msg("Avatar path changed, but hash didn't")
// Path changed, but actual avatar didn't
return true
}
puppet.AvatarHash = newHash
source.Client.Store.ContactStore.StoreContact(ctx, *info)
err = source.Client.Store.ContactStore.StoreContact(ctx, *info)
if err != nil {
log.Warn().Err(err).Msg("error updating contact's profile avatar hash")
}
}
hash := sha256.Sum256(avatarData)
newHash := hex.EncodeToString(hash[:])
if puppet.AvatarHash == newHash && puppet.AvatarSet {
log.Debug().
Str("avatar_hash", newHash).
Str("new_avatar_path", puppet.AvatarPath).
Msg("Avatar path changed, but hash didn't")
// Path changed, but actual avatar didn't
return true
}
puppet.AvatarPath = info.Profile.AvatarPath
puppet.AvatarHash = newHash
puppet.AvatarSet = false
puppet.AvatarURL = id.ContentURI{}
resp, err := puppet.DefaultIntent().UploadBytes(ctx, avatarData, avatarContentType)
Expand All @@ -383,7 +388,7 @@ func (puppet *Puppet) updateAvatar(ctx context.Context, source *User, info *type
return true
}
log.Debug().
Str("avatar_hash", newHash).
Str("avatar_hash", puppet.AvatarHash).
Stringer("avatar_mxc", resp.ContentURI).
Msg("Avatar updated successfully")
puppet.AvatarSet = true
Expand Down

0 comments on commit d451d51

Please sign in to comment.