From 84313262955f452bbc31eb11c7bbcc78f011aea3 Mon Sep 17 00:00:00 2001 From: kim Date: Thu, 30 Jan 2025 07:56:55 +0000 Subject: [PATCH] some very small fixups --- internal/cleaner/emoji.go | 5 +++-- internal/gtsmodel/account.go | 16 ++++++++++++++-- internal/gtsmodel/emoji.go | 3 ++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/internal/cleaner/emoji.go b/internal/cleaner/emoji.go index 6cf194e40..05588ccb2 100644 --- a/internal/cleaner/emoji.go +++ b/internal/cleaner/emoji.go @@ -104,13 +104,14 @@ func (e *Emoji) UncacheRemote(ctx context.Context, olderThan time.Time) (int, er return total, gtserror.Newf("error getting remote emoji: %w", err) } - // If no emojis / same group is returned, we reached the end. + // If no emojis / same group is + // returned, we reached the end. if len(emojis) == 0 || olderThan.Equal(emojis[len(emojis)-1].CreatedAt) { break } - // Use last created-at as the next 'olderThan' value. + // Use last createdAt as next 'olderThan' value. olderThan = emojis[len(emojis)-1].CreatedAt for _, emoji := range emojis { diff --git a/internal/gtsmodel/account.go b/internal/gtsmodel/account.go index 79a35e561..64c252250 100644 --- a/internal/gtsmodel/account.go +++ b/internal/gtsmodel/account.go @@ -31,7 +31,8 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/log" ) -// Account represents either a local or a remote fediverse account, gotosocial or otherwise (mastodon, pleroma, etc). +// Account represents either a local or a remote fediverse +// account, gotosocial or otherwise (mastodon, pleroma, etc). type Account struct { ID string `bun:"type:CHAR(26),pk,nullzero,notnull,unique"` // id of this item in the database CreatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item created. @@ -83,9 +84,20 @@ type Account struct { Stats *AccountStats `bun:"-"` // gtsmodel.AccountStats for this account. } +// UsernameDomain returns account @username@domain (missing domain if local). +func (a *Account) UsernameDomain() string { + if a.IsLocal() { + return "@" + a.Username + } + return "@" + a.Username + "@" + a.Domain +} + // IsLocal returns whether account is a local user account. func (a *Account) IsLocal() bool { - return a.Domain == "" || a.Domain == config.GetHost() || a.Domain == config.GetAccountDomain() + // TODO: can we simplify this to just domain == ""? + return a.Domain == "" || + a.Domain == config.GetHost() || + a.Domain == config.GetAccountDomain() } // IsRemote returns whether account is a remote user account. diff --git a/internal/gtsmodel/emoji.go b/internal/gtsmodel/emoji.go index 7bf52586c..89cb551f1 100644 --- a/internal/gtsmodel/emoji.go +++ b/internal/gtsmodel/emoji.go @@ -19,7 +19,8 @@ package gtsmodel import "time" -// Emoji represents a custom emoji that's been uploaded through the admin UI or downloaded from a remote instance. +// Emoji represents a custom emoji that's been uploaded +// through the admin UI or downloaded from a remote instance. type Emoji struct { ID string `bun:"type:CHAR(26),pk,nullzero,notnull,unique"` // id of this item in the database CreatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item created