[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:
parent
27bcc1fcbd
commit
fde0c6bc8c
|
@ -50,3 +50,8 @@ type Emoji struct {
|
||||||
func (e *Emoji) IsLocal() bool {
|
func (e *Emoji) IsLocal() bool {
|
||||||
return e.Domain == ""
|
return e.Domain == ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShortcodeDomain returns the [shortcode]@[domain] for the given emoji.
|
||||||
|
func (e *Emoji) ShortcodeDomain() string {
|
||||||
|
return e.Shortcode + "@" + e.Domain
|
||||||
|
}
|
||||||
|
|
|
@ -308,7 +308,7 @@ func (m *Manager) RefreshEmoji(
|
||||||
// paths before they get updated with new
|
// paths before they get updated with new
|
||||||
// path ID. These are required for later
|
// path ID. These are required for later
|
||||||
// deleting the old image files on refresh.
|
// deleting the old image files on refresh.
|
||||||
shortcodeDomain := util.ShortcodeDomain(emoji)
|
shortcodeDomain := emoji.ShortcodeDomain()
|
||||||
oldStaticPath := emoji.ImageStaticPath
|
oldStaticPath := emoji.ImageStaticPath
|
||||||
oldPath := emoji.ImagePath
|
oldPath := emoji.ImagePath
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
"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)
|
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 {
|
if refetch, err := m.emojiRequiresRefetch(ctx, emoji); err != nil {
|
||||||
// an error here indicates something is wrong with storage, so we should stop
|
// 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 {
|
} else if !refetch {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -77,7 +76,7 @@ func (m *Manager) RefetchEmojis(ctx context.Context, domain string, dereferenceM
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update next maxShortcodeDomain from last emoji
|
// 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
|
// 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
|
// 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)
|
return 0, fmt.Errorf("error getting emoji %s: %w", emojiID, err)
|
||||||
}
|
}
|
||||||
shortcodeDomain := util.ShortcodeDomain(emoji)
|
shortcodeDomain := emoji.ShortcodeDomain()
|
||||||
|
|
||||||
if emoji.ImageRemoteURL == "" {
|
if emoji.ImageRemoteURL == "" {
|
||||||
log.Errorf(ctx, "remote emoji %s could not be refreshed because it has no ImageRemoteURL set", shortcodeDomain)
|
log.Errorf(ctx, "remote emoji %s could not be refreshed because it has no ImageRemoteURL set", shortcodeDomain)
|
||||||
|
|
|
@ -112,9 +112,9 @@ func (p *Processor) EmojisGet(
|
||||||
Items: items,
|
Items: items,
|
||||||
Path: "api/v1/admin/custom_emojis",
|
Path: "api/v1/admin/custom_emojis",
|
||||||
NextMaxIDKey: "max_shortcode_domain",
|
NextMaxIDKey: "max_shortcode_domain",
|
||||||
NextMaxIDValue: util.ShortcodeDomain(emojis[count-1]),
|
NextMaxIDValue: emojis[count-1].ShortcodeDomain(),
|
||||||
PrevMinIDKey: "min_shortcode_domain",
|
PrevMinIDKey: "min_shortcode_domain",
|
||||||
PrevMinIDValue: util.ShortcodeDomain(emojis[0]),
|
PrevMinIDValue: emojis[0].ShortcodeDomain(),
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
ExtraQueryParams: []string{
|
ExtraQueryParams: []string{
|
||||||
emojisGetFilterParams(
|
emojisGetFilterParams(
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
// GoToSocial
|
|
||||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package util
|
|
||||||
|
|
||||||
import "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
|
||||||
|
|
||||||
// ShortcodeDomain returns the [shortcode]@[domain] for the given emoji.
|
|
||||||
func ShortcodeDomain(emoji *gtsmodel.Emoji) string {
|
|
||||||
return emoji.Shortcode + "@" + emoji.Domain
|
|
||||||
}
|
|
Loading…
Reference in New Issue