mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-02-08 17:16:31 +01:00
[bugfix] Missing emoji urls (#3707)
* filter out emoji that are uncached when converting to frontend models * some very small fixups * remove TODO notice
This commit is contained in:
parent
1ab960bf15
commit
91cef3495d
4 changed files with 32 additions and 11 deletions
|
@ -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 {
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
"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,19 @@ 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()
|
||||
return a.Domain == "" ||
|
||||
a.Domain == config.GetHost() ||
|
||||
a.Domain == config.GetAccountDomain()
|
||||
}
|
||||
|
||||
// IsRemote returns whether account is a remote user account.
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
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
|
||||
|
|
|
@ -2641,28 +2641,36 @@ func (c *Converter) FilterStatusToAPIFilterStatus(ctx context.Context, filterSta
|
|||
func (c *Converter) convertEmojisToAPIEmojis(ctx context.Context, emojis []*gtsmodel.Emoji, emojiIDs []string) ([]apimodel.Emoji, error) {
|
||||
var errs gtserror.MultiError
|
||||
|
||||
// GTS model attachments were not populated
|
||||
if len(emojis) == 0 && len(emojiIDs) > 0 {
|
||||
// GTS model attachments were not populated
|
||||
|
||||
var err error
|
||||
|
||||
// Fetch GTS models for emoji IDs
|
||||
emojis, err = c.state.DB.GetEmojisByIDs(ctx, emojiIDs)
|
||||
if err != nil {
|
||||
errs.Appendf("error fetching emojis from database: %w", err)
|
||||
return nil, gtserror.Newf("db error fetching emojis: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Preallocate expected frontend slice
|
||||
// Preallocate expected frontend slice of emojis.
|
||||
apiEmojis := make([]apimodel.Emoji, 0, len(emojis))
|
||||
|
||||
// Convert GTS models to frontend models
|
||||
for _, emoji := range emojis {
|
||||
|
||||
// Skip adding emojis that are
|
||||
// uncached, the empty URLs can
|
||||
// cause issues with some clients.
|
||||
if !*emoji.Cached {
|
||||
continue
|
||||
}
|
||||
|
||||
// Convert each to a frontend API model emoji.
|
||||
apiEmoji, err := c.EmojiToAPIEmoji(ctx, emoji)
|
||||
if err != nil {
|
||||
errs.Appendf("error converting emoji %s to api emoji: %w", emoji.ID, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Append converted emoji to return slice.
|
||||
apiEmojis = append(apiEmojis, apiEmoji)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue