summaryrefslogtreecommitdiff
path: root/internal/processing/account/update.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-07-08 15:47:03 +0200
committerLibravatar GitHub <noreply@github.com>2024-07-08 15:47:03 +0200
commitd70f4e166dd9ce2f11a6ac2d7a2e500515657041 (patch)
tree256f2a4423742a41adceb00dbec0cd56c568e908 /internal/processing/account/update.go
parent[chore]: Bump github.com/minio/minio-go/v7 from 7.0.72 to 7.0.73 (#3083) (diff)
downloadgotosocial-d70f4e166dd9ce2f11a6ac2d7a2e500515657041.tar.xz
[feature/frontend] Allow setting alt-text for avatar + header (#3086)
Diffstat (limited to 'internal/processing/account/update.go')
-rw-r--r--internal/processing/account/update.go36
1 files changed, 34 insertions, 2 deletions
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go
index 61e88501f..ba9360c36 100644
--- a/internal/processing/account/update.go
+++ b/internal/processing/account/update.go
@@ -204,11 +204,16 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form
}
}
+ if form.AvatarDescription != nil {
+ desc := text.SanitizeToPlaintext(*form.AvatarDescription)
+ form.AvatarDescription = util.Ptr(desc)
+ }
+
if form.Avatar != nil && form.Avatar.Size != 0 {
avatarInfo, errWithCode := p.UpdateAvatar(ctx,
account,
form.Avatar,
- nil,
+ form.AvatarDescription,
)
if errWithCode != nil {
return nil, errWithCode
@@ -216,13 +221,29 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form
account.AvatarMediaAttachmentID = avatarInfo.ID
account.AvatarMediaAttachment = avatarInfo
log.Tracef(ctx, "new avatar info for account %s is %+v", account.ID, avatarInfo)
+ } else if form.AvatarDescription != nil && account.AvatarMediaAttachment != nil {
+ // Update just existing description if possible.
+ account.AvatarMediaAttachment.Description = *form.AvatarDescription
+ if err := p.state.DB.UpdateAttachment(
+ ctx,
+ account.AvatarMediaAttachment,
+ "description",
+ ); err != nil {
+ err := gtserror.Newf("db error updating account avatar description: %w", err)
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+ }
+
+ if form.HeaderDescription != nil {
+ desc := text.SanitizeToPlaintext(*form.HeaderDescription)
+ form.HeaderDescription = util.Ptr(desc)
}
if form.Header != nil && form.Header.Size != 0 {
headerInfo, errWithCode := p.UpdateHeader(ctx,
account,
form.Header,
- nil,
+ form.HeaderDescription,
)
if errWithCode != nil {
return nil, errWithCode
@@ -230,6 +251,17 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form
account.HeaderMediaAttachmentID = headerInfo.ID
account.HeaderMediaAttachment = headerInfo
log.Tracef(ctx, "new header info for account %s is %+v", account.ID, headerInfo)
+ } else if form.HeaderDescription != nil && account.HeaderMediaAttachment != nil {
+ // Update just existing description if possible.
+ account.HeaderMediaAttachment.Description = *form.HeaderDescription
+ if err := p.state.DB.UpdateAttachment(
+ ctx,
+ account.HeaderMediaAttachment,
+ "description",
+ ); err != nil {
+ err := gtserror.Newf("db error updating account avatar description: %w", err)
+ return nil, gtserror.NewErrorInternalError(err)
+ }
}
if form.Locked != nil {