Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update profile avatar paths & hashes properly #472

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 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,19 @@ func (puppet *Puppet) updateAvatar(ctx context.Context, source *User, info *type
return true
}
avatarContentType = http.DetectContentType(avatarData)
puppet.AvatarPath = info.Profile.AvatarPath
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was moved to before the return true so that an path change will end up getting saved to the store even when the hash didn't change.

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
}
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 +383,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
Loading