[chore] Allow gtsmodel to depend on util (#3068)

Convert one free function into a gtsmodel.Emoji method so that util does not depend on gtsmodel and can be used from it in the future
This commit is contained in:
Vyr Cossont 2024-07-03 15:53:54 -07:00 committed by GitHub
commit fde0c6bc8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 11 additions and 32 deletions

View file

@ -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

View file

@ -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)
@ -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
}
@ -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
@ -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)