diff options
| author | 2025-06-19 15:10:41 +0200 | |
|---|---|---|
| committer | 2025-06-19 15:10:41 +0200 | |
| commit | bfc8c31e5f80bd7e405ad407d58597a92a1e85fd (patch) | |
| tree | 53645d0ddfdd32469f36eaa649b31be14d8018c3 /internal/federation/dereferencing/account.go | |
| parent | [bugfix] delete interaction requests when deleting account (#4278) (diff) | |
| download | gotosocial-bfc8c31e5f80bd7e405ad407d58597a92a1e85fd.tar.xz | |
[feature] Support incoming avatar/header descriptions (#4275)
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
# Description
Follow-up to #4270
Closes https://codeberg.org/superseriousbusiness/gotosocial/issues/3450
## Checklist
- [x] I/we have read the [GoToSocial contribution guidelines](https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CONTRIBUTING.md).
- [ ] I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
- [x] I/we have not leveraged AI to create the proposed changes.
- [x] I/we have performed a self-review of added code.
- [x] I/we have written code that is legible and maintainable by others.
- [x] I/we have commented the added code, particularly in hard-to-understand areas.
- [ ] I/we have made any necessary changes to documentation.
- [x] I/we have added tests that cover new code.
- [x] I/we have run tests and they pass locally with the changes.
- [x] I/we have run `go fmt ./...` and `golangci-lint run`.
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4275
Co-authored-by: nicole mikołajczyk <git@mkljczk.pl>
Co-committed-by: nicole mikołajczyk <git@mkljczk.pl>
Diffstat (limited to 'internal/federation/dereferencing/account.go')
| -rw-r--r-- | internal/federation/dereferencing/account.go | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/internal/federation/dereferencing/account.go b/internal/federation/dereferencing/account.go index 6c9afc665..effc22c44 100644 --- a/internal/federation/dereferencing/account.go +++ b/internal/federation/dereferencing/account.go @@ -807,12 +807,12 @@ func (d *Dereferencer) enrichAccount( latestAcc.UpdatedAt = now // Ensure the account's avatar media is populated, passing in existing to check for chages. - if err := d.fetchAccountAvatar(ctx, requestUser, account, latestAcc); err != nil { + if err := d.fetchAccountAvatar(ctx, requestUser, account, latestAcc, apubAcc); err != nil { log.Errorf(ctx, "error fetching remote avatar for account %s: %v", uri, err) } // Ensure the account's avatar media is populated, passing in existing to check for chages. - if err := d.fetchAccountHeader(ctx, requestUser, account, latestAcc); err != nil { + if err := d.fetchAccountHeader(ctx, requestUser, account, latestAcc, apubAcc); err != nil { log.Errorf(ctx, "error fetching remote header for account %s: %v", uri, err) } @@ -854,6 +854,7 @@ func (d *Dereferencer) fetchAccountAvatar( requestUser string, existingAcc *gtsmodel.Account, latestAcc *gtsmodel.Account, + apubAcc ap.Accountable, ) error { if latestAcc.AvatarRemoteURL == "" { // No avatar set on newest model, leave @@ -861,6 +862,8 @@ func (d *Dereferencer) fetchAccountAvatar( return nil } + avatarDescription := ap.ExtractIconDescription(apubAcc) + // Check for an existing stored media attachment // specifically with unchanged remote URL we can use. if existingAcc.AvatarMediaAttachmentID != "" && @@ -883,6 +886,18 @@ func (d *Dereferencer) fetchAccountAvatar( nil, ) + if existing.Description != avatarDescription { + existing.Description = avatarDescription + if err := d.state.DB.UpdateAttachment( + ctx, + existing, + "description", + ); err != nil { + err := gtserror.Newf("db error updating existing avatar description: %w", err) + return gtserror.NewErrorInternalError(err) + } + } + if err != nil { log.Errorf(ctx, "error updating existing attachment: %v", err) @@ -906,8 +921,9 @@ func (d *Dereferencer) fetchAccountAvatar( latestAcc.ID, latestAcc.AvatarRemoteURL, media.AdditionalMediaInfo{ - Avatar: util.Ptr(true), - RemoteURL: &latestAcc.AvatarRemoteURL, + Avatar: util.Ptr(true), + RemoteURL: &latestAcc.AvatarRemoteURL, + Description: &avatarDescription, }, ) if err != nil { @@ -931,6 +947,7 @@ func (d *Dereferencer) fetchAccountHeader( requestUser string, existingAcc *gtsmodel.Account, latestAcc *gtsmodel.Account, + apubAcc ap.Accountable, ) error { if latestAcc.HeaderRemoteURL == "" { // No header set on newest model, leave @@ -938,6 +955,8 @@ func (d *Dereferencer) fetchAccountHeader( return nil } + headerDescription := ap.ExtractImageDescription(apubAcc) + // Check for an existing stored media attachment // specifically with unchanged remote URL we can use. if existingAcc.HeaderMediaAttachmentID != "" && @@ -951,6 +970,18 @@ func (d *Dereferencer) fetchAccountHeader( return gtserror.Newf("error getting attachment %s: %w", existingAcc.HeaderMediaAttachmentID, err) } + if existing.Description != headerDescription { + existing.Description = headerDescription + if err := d.state.DB.UpdateAttachment( + ctx, + existing, + "description", + ); err != nil { + err := gtserror.Newf("db error updating existing header description: %w", err) + return gtserror.NewErrorInternalError(err) + } + } + if existing != nil { // Ensuring existing attachment is up-to-date // and any recaching is performed if required. @@ -983,8 +1014,9 @@ func (d *Dereferencer) fetchAccountHeader( latestAcc.ID, latestAcc.HeaderRemoteURL, media.AdditionalMediaInfo{ - Header: util.Ptr(true), - RemoteURL: &latestAcc.HeaderRemoteURL, + Header: util.Ptr(true), + RemoteURL: &latestAcc.HeaderRemoteURL, + Description: &headerDescription, }, ) if err != nil { |
