Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Allow gtsmodel to depend on util #3068

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/gtsmodel/emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ type Emoji struct {
func (e *Emoji) IsLocal() bool {
return e.Domain == ""
}

// ShortcodeDomain returns the [shortcode]@[domain] for the given emoji.
func (e *Emoji) ShortcodeDomain() string {
return e.Shortcode + "@" + e.Domain
}
2 changes: 1 addition & 1 deletion internal/media/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (m *Manager) RefreshEmoji(
// paths before they get updated with new
// path ID. These are required for later
// deleting the old image files on refresh.
shortcodeDomain := util.ShortcodeDomain(emoji)
shortcodeDomain := emoji.ShortcodeDomain()
oldStaticPath := emoji.ImageStaticPath
oldPath := emoji.ImagePath

Expand Down
7 changes: 3 additions & 4 deletions internal/media/refetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/util"
)

type DereferenceMedia func(ctx context.Context, iri *url.URL) (io.ReadCloser, int64, error)
Expand Down Expand Up @@ -68,7 +67,7 @@ func (m *Manager) RefetchEmojis(ctx context.Context, domain string, dereferenceM

if refetch, err := m.emojiRequiresRefetch(ctx, emoji); err != nil {
// an error here indicates something is wrong with storage, so we should stop
return 0, fmt.Errorf("error checking refetch requirement for emoji %s: %w", util.ShortcodeDomain(emoji), err)
return 0, fmt.Errorf("error checking refetch requirement for emoji %s: %w", emoji.ShortcodeDomain(), err)
} else if !refetch {
continue
}
Expand All @@ -77,7 +76,7 @@ func (m *Manager) RefetchEmojis(ctx context.Context, domain string, dereferenceM
}

// Update next maxShortcodeDomain from last emoji
maxShortcodeDomain = util.ShortcodeDomain(emojis[len(emojis)-1])
maxShortcodeDomain = emojis[len(emojis)-1].ShortcodeDomain()
}

// bail early if we've got nothing to do
Expand All @@ -95,7 +94,7 @@ func (m *Manager) RefetchEmojis(ctx context.Context, domain string, dereferenceM
// this shouldn't happen--since we know we have the emoji--so return if it does
return 0, fmt.Errorf("error getting emoji %s: %w", emojiID, err)
}
shortcodeDomain := util.ShortcodeDomain(emoji)
shortcodeDomain := emoji.ShortcodeDomain()

if emoji.ImageRemoteURL == "" {
log.Errorf(ctx, "remote emoji %s could not be refreshed because it has no ImageRemoteURL set", shortcodeDomain)
Expand Down
4 changes: 2 additions & 2 deletions internal/processing/admin/emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ func (p *Processor) EmojisGet(
Items: items,
Path: "api/v1/admin/custom_emojis",
NextMaxIDKey: "max_shortcode_domain",
NextMaxIDValue: util.ShortcodeDomain(emojis[count-1]),
NextMaxIDValue: emojis[count-1].ShortcodeDomain(),
PrevMinIDKey: "min_shortcode_domain",
PrevMinIDValue: util.ShortcodeDomain(emojis[0]),
PrevMinIDValue: emojis[0].ShortcodeDomain(),
Limit: limit,
ExtraQueryParams: []string{
emojisGetFilterParams(
Expand Down
25 changes: 0 additions & 25 deletions internal/util/emoji.go

This file was deleted.