summaryrefslogtreecommitdiff
path: root/internal/typeutils/internaltofrontend.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-01-16 17:22:44 +0100
committerLibravatar GitHub <noreply@github.com>2024-01-16 16:22:44 +0000
commitc36f9ac37b8bbdeb4def7a20ba8ea6d6b7ad12d5 (patch)
tree9569c022aaf5c4ceaaf5ce433c95d9d90b6402cc /internal/typeutils/internaltofrontend.go
parent[chore] Move to codeberg's exif-terminator (#2536) (diff)
downloadgotosocial-c36f9ac37b8bbdeb4def7a20ba8ea6d6b7ad12d5.tar.xz
[feature] Account alias / move API + db models (#2518)
* [feature] Account alias / move API + db models * go fmt * fix little cherry-pick issues * update error checking, formatting * add and use new util functions to simplify alias logic
Diffstat (limited to 'internal/typeutils/internaltofrontend.go')
-rw-r--r--internal/typeutils/internaltofrontend.go25
1 files changed, 18 insertions, 7 deletions
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index abae81d04..75247f411 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -90,6 +90,7 @@ func (c *Converter) AccountToAPIAccountSensitive(ctx context.Context, a *gtsmode
Note: a.NoteRaw,
Fields: c.fieldsToAPIFields(a.FieldsRaw),
FollowRequestsCount: frc,
+ AlsoKnownAsURIs: a.AlsoKnownAsURIs,
}
return apiAccount, nil
@@ -111,27 +112,27 @@ func (c *Converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
followersCount, err := c.state.DB.CountAccountFollowers(ctx, a.ID)
if err != nil && !errors.Is(err, db.ErrNoEntries) {
- return nil, fmt.Errorf("AccountToAPIAccountPublic: error counting followers: %w", err)
+ return nil, gtserror.Newf("error counting followers: %w", err)
}
followingCount, err := c.state.DB.CountAccountFollows(ctx, a.ID)
if err != nil && !errors.Is(err, db.ErrNoEntries) {
- return nil, fmt.Errorf("AccountToAPIAccountPublic: error counting following: %w", err)
+ return nil, gtserror.Newf("error counting following: %w", err)
}
statusesCount, err := c.state.DB.CountAccountStatuses(ctx, a.ID)
if err != nil && !errors.Is(err, db.ErrNoEntries) {
- return nil, fmt.Errorf("AccountToAPIAccountPublic: error counting statuses: %w", err)
+ return nil, gtserror.Newf("error counting statuses: %w", err)
}
var lastStatusAt *string
lastPosted, err := c.state.DB.GetAccountLastPosted(ctx, a.ID, false)
if err != nil && !errors.Is(err, db.ErrNoEntries) {
- return nil, fmt.Errorf("AccountToAPIAccountPublic: error counting statuses: %w", err)
+ return nil, gtserror.Newf("error getting last posted: %w", err)
}
if !lastPosted.IsZero() {
- lastStatusAt = func() *string { t := util.FormatISO8601(lastPosted); return &t }()
+ lastStatusAt = util.Ptr(util.FormatISO8601(lastPosted))
}
// Profile media + nice extras:
@@ -180,7 +181,7 @@ func (c *Converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
// de-punify it just in case.
d, err := util.DePunify(a.Domain)
if err != nil {
- return nil, fmt.Errorf("AccountToAPIAccountPublic: error de-punifying domain %s for account id %s: %w", a.Domain, a.ID, err)
+ return nil, gtserror.Newf("error de-punifying domain %s for account id %s: %w", a.Domain, a.ID, err)
}
acct = a.Username + "@" + d
@@ -191,7 +192,7 @@ func (c *Converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
if !a.IsInstance() {
user, err := c.state.DB.GetUserByAccountID(ctx, a.ID)
if err != nil {
- return nil, fmt.Errorf("AccountToAPIAccountPublic: error getting user from database for account id %s: %w", a.ID, err)
+ return nil, gtserror.Newf("error getting user from database for account id %s: %w", a.ID, err)
}
switch {
@@ -207,6 +208,15 @@ func (c *Converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
acct = a.Username // omit domain
}
+ // Populate moved.
+ var moved *apimodel.Account
+ if a.MovedTo != nil {
+ moved, err = c.AccountToAPIAccountPublic(ctx, a.MovedTo)
+ if err != nil {
+ log.Errorf(ctx, "error converting account movedTo: %v", err)
+ }
+ }
+
// Remaining properties are simple and
// can be populated directly below.
@@ -235,6 +245,7 @@ func (c *Converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
CustomCSS: a.CustomCSS,
EnableRSS: *a.EnableRSS,
Role: role,
+ Moved: moved,
}
// Bodge default avatar + header in,