mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-25 21:33:33 -06:00
[feature] Dereference remote mentions when the account is not already known (#442)
* remove mention util function from db * add ParseMentionFunc to gtsmodel * add parseMentionFunc to processor * refactor search to simplify it a bit * add parseMentionFunc to account * add parseMentionFunc to status * some renaming for clarity * test dereference of unknown mentioned account
This commit is contained in:
parent
983e696bd6
commit
37d310f981
16 changed files with 420 additions and 183 deletions
|
|
@ -74,15 +74,17 @@ type processor struct {
|
|||
filter visibility.Filter
|
||||
formatter text.Formatter
|
||||
fromClientAPI chan messages.FromClientAPI
|
||||
parseMention gtsmodel.ParseMentionFunc
|
||||
}
|
||||
|
||||
// New returns a new status processor.
|
||||
func New(db db.DB, tc typeutils.TypeConverter, fromClientAPI chan messages.FromClientAPI) Processor {
|
||||
func New(db db.DB, tc typeutils.TypeConverter, fromClientAPI chan messages.FromClientAPI, parseMention gtsmodel.ParseMentionFunc) Processor {
|
||||
return &processor{
|
||||
tc: tc,
|
||||
db: db,
|
||||
filter: visibility.NewFilter(db),
|
||||
formatter: text.NewFormatter(db),
|
||||
fromClientAPI: fromClientAPI,
|
||||
parseMention: parseMention,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,16 @@
|
|||
package status_test
|
||||
|
||||
import (
|
||||
"codeberg.org/gruf/go-store/kv"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/federation"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/media"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/processing/status"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/transport"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
)
|
||||
|
|
@ -32,6 +37,10 @@ type StatusStandardTestSuite struct {
|
|||
suite.Suite
|
||||
db db.DB
|
||||
typeConverter typeutils.TypeConverter
|
||||
tc transport.Controller
|
||||
storage *kv.KVStore
|
||||
mediaManager media.Manager
|
||||
federator federation.Federator
|
||||
fromClientAPIChan chan messages.FromClientAPI
|
||||
|
||||
// standard suite models
|
||||
|
|
@ -62,17 +71,23 @@ func (suite *StatusStandardTestSuite) SetupSuite() {
|
|||
}
|
||||
|
||||
func (suite *StatusStandardTestSuite) SetupTest() {
|
||||
testrig.InitTestLog()
|
||||
testrig.InitTestConfig()
|
||||
testrig.InitTestLog()
|
||||
|
||||
suite.db = testrig.NewTestDB()
|
||||
suite.typeConverter = testrig.NewTestTypeConverter(suite.db)
|
||||
suite.fromClientAPIChan = make(chan messages.FromClientAPI, 100)
|
||||
suite.status = status.New(suite.db, suite.typeConverter, suite.fromClientAPIChan)
|
||||
suite.tc = testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db)
|
||||
suite.storage = testrig.NewTestStorage()
|
||||
suite.mediaManager = testrig.NewTestMediaManager(suite.db, suite.storage)
|
||||
suite.federator = testrig.NewTestFederator(suite.db, suite.tc, suite.storage, suite.mediaManager)
|
||||
suite.status = status.New(suite.db, suite.typeConverter, suite.fromClientAPIChan, processing.GetParseMentionFunc(suite.db, suite.federator))
|
||||
|
||||
testrig.StandardDBSetup(suite.db, nil)
|
||||
testrig.StandardDBSetup(suite.db, suite.testAccounts)
|
||||
testrig.StandardStorageSetup(suite.storage, "../../../testrig/media")
|
||||
}
|
||||
|
||||
func (suite *StatusStandardTestSuite) TearDownTest() {
|
||||
testrig.StandardDBTeardown(suite.db)
|
||||
testrig.StandardStorageTeardown(suite.storage)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/id"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/text"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||
)
|
||||
|
|
@ -192,27 +192,30 @@ func (p *processor) ProcessLanguage(ctx context.Context, form *apimodel.Advanced
|
|||
}
|
||||
|
||||
func (p *processor) ProcessMentions(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, accountID string, status *gtsmodel.Status) error {
|
||||
menchies := []string{}
|
||||
gtsMenchies, err := p.db.MentionStringsToMentions(ctx, util.DeriveMentionsFromText(form.Status), accountID, status.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error generating mentions from status: %s", err)
|
||||
}
|
||||
for _, menchie := range gtsMenchies {
|
||||
menchieID, err := id.NewRandomULID()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
menchie.ID = menchieID
|
||||
mentionedAccountNames := util.DeriveMentionNamesFromText(form.Status)
|
||||
mentions := []*gtsmodel.Mention{}
|
||||
mentionIDs := []string{}
|
||||
|
||||
if err := p.db.Put(ctx, menchie); err != nil {
|
||||
return fmt.Errorf("error putting mentions in db: %s", err)
|
||||
for _, mentionedAccountName := range mentionedAccountNames {
|
||||
gtsMention, err := p.parseMention(ctx, mentionedAccountName, accountID, status.ID)
|
||||
if err != nil {
|
||||
logrus.Errorf("ProcessMentions: error parsing mention %s from status: %s", mentionedAccountName, err)
|
||||
continue
|
||||
}
|
||||
menchies = append(menchies, menchie.ID)
|
||||
|
||||
if err := p.db.Put(ctx, gtsMention); err != nil {
|
||||
logrus.Errorf("ProcessMentions: error putting mention in db: %s", err)
|
||||
}
|
||||
|
||||
mentions = append(mentions, gtsMention)
|
||||
mentionIDs = append(mentionIDs, gtsMention.ID)
|
||||
}
|
||||
|
||||
// add full populated gts menchies to the status for passing them around conveniently
|
||||
status.Mentions = gtsMenchies
|
||||
status.Mentions = mentions
|
||||
// add just the ids of the mentioned accounts to the status for putting in the db
|
||||
status.MentionIDs = menchies
|
||||
status.MentionIDs = mentionIDs
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue