summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-02-03 20:03:05 +0000
committerLibravatar GitHub <noreply@github.com>2023-02-03 20:03:05 +0000
commit33aee1b1e974e99182a95ce1a05e2be924d19bb2 (patch)
tree1471623039f70325a0b7a1c25dd4fe3afc883970 /internal/processing
parent[feature/frogend] (Mastodon) domain block CSV import (#1390) (diff)
downloadgotosocial-33aee1b1e974e99182a95ce1a05e2be924d19bb2.tar.xz
[chore] reformat GetAccount() functionality, support updating accounts based on last_fetch (#1411)
* reformat GetAccount() functionality, and add UpdateAccount() function. * use fetched_at instead of last_webfingered_at * catch local "not found" errors. small formatting / error string changes * remove now unused error type * return nil when wrapping nil error * update expected error messages * return correct url for foss satan webfinger * add AP model for Some_User * normalize local domain * return notretrievable where appropriate * expose NewErrNotRetrievable * ensure webfinger for new accounts searched by uri * update local account short circuit * allow enrich to fail for already-known accounts * remove unused LastWebfingeredAt * expose test maps on mock http client * update Update test * reformat GetAccount() functionality, and add UpdateAccount() function. * use fetched_at instead of last_webfingered_at * catch local "not found" errors. small formatting / error string changes * remove nil error checks (we shouldn't be passing nil errors to newError() initializers) * remove mutex unlock on transport init fail (it hasn't yet been locked!) * woops add back the error wrapping to use ErrNotRetrievable * caches were never being started... :see_no_evil: --------- Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: tsmethurst <tobi.smethurst@protonmail.com>
Diffstat (limited to 'internal/processing')
-rw-r--r--internal/processing/account/createblock.go5
-rw-r--r--internal/processing/account/get.go11
-rw-r--r--internal/processing/admin/accountaction.go7
-rw-r--r--internal/processing/admin/createdomainblock.go8
-rw-r--r--internal/processing/federation/getfollowers.go8
-rw-r--r--internal/processing/federation/getfollowing.go8
-rw-r--r--internal/processing/federation/getoutbox.go8
-rw-r--r--internal/processing/federation/getstatus.go8
-rw-r--r--internal/processing/federation/getstatusreplies.go8
-rw-r--r--internal/processing/federation/getuser.go13
-rw-r--r--internal/processing/fromcommon.go35
-rw-r--r--internal/processing/fromfederator.go54
-rw-r--r--internal/processing/report/create.go6
-rw-r--r--internal/processing/search.go77
-rw-r--r--internal/processing/status/bookmark.go7
-rw-r--r--internal/processing/status/create.go6
-rw-r--r--internal/processing/status/fave.go5
-rw-r--r--internal/processing/util.go18
18 files changed, 132 insertions, 160 deletions
diff --git a/internal/processing/account/createblock.go b/internal/processing/account/createblock.go
index d2a2bab94..68f28fafe 100644
--- a/internal/processing/account/createblock.go
+++ b/internal/processing/account/createblock.go
@@ -53,10 +53,7 @@ func (p *processor) BlockCreate(ctx context.Context, requestingAccount *gtsmodel
// make the block
block := &gtsmodel.Block{}
- newBlockID, err := id.NewULID()
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
+ newBlockID := id.NewULID()
block.ID = newBlockID
block.AccountID = requestingAccount.ID
block.Account = requestingAccount
diff --git a/internal/processing/account/get.go b/internal/processing/account/get.go
index 6c134547e..0592555da 100644
--- a/internal/processing/account/get.go
+++ b/internal/processing/account/get.go
@@ -26,7 +26,6 @@ import (
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/transport"
@@ -94,13 +93,9 @@ func (p *processor) getAccountFor(ctx context.Context, requestingAccount *gtsmod
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error parsing url %s: %s", targetAccount.URI, err))
}
- a, err := p.federator.GetAccount(transport.WithFastfail(ctx), dereferencing.GetAccountParams{
- RequestingUsername: requestingAccount.Username,
- RemoteAccountID: targetAccountURI,
- RemoteAccountHost: targetAccount.Domain,
- RemoteAccountUsername: targetAccount.Username,
- Blocking: true,
- })
+ a, err := p.federator.GetAccountByURI(
+ transport.WithFastfail(ctx), requestingAccount.Username, targetAccountURI, true,
+ )
if err == nil {
targetAccount = a
}
diff --git a/internal/processing/admin/accountaction.go b/internal/processing/admin/accountaction.go
index c71eb27e5..e4e6bbd97 100644
--- a/internal/processing/admin/accountaction.go
+++ b/internal/processing/admin/accountaction.go
@@ -18,13 +18,8 @@ func (p *processor) AccountAction(ctx context.Context, account *gtsmodel.Account
return gtserror.NewErrorInternalError(err)
}
- adminActionID, err := id.NewULID()
- if err != nil {
- return gtserror.NewErrorInternalError(err)
- }
-
adminAction := &gtsmodel.AdminAccountAction{
- ID: adminActionID,
+ ID: id.NewULID(),
AccountID: account.ID,
TargetAccountID: targetAccount.ID,
Text: form.Text,
diff --git a/internal/processing/admin/createdomainblock.go b/internal/processing/admin/createdomainblock.go
index 98ba9cf1b..1c80ee78f 100644
--- a/internal/processing/admin/createdomainblock.go
+++ b/internal/processing/admin/createdomainblock.go
@@ -50,14 +50,8 @@ func (p *processor) DomainBlockCreate(ctx context.Context, account *gtsmodel.Acc
}
// there's no block for this domain yet so create one
- // note: we take a new ulid from timestamp here in case we need to sort blocks
- blockID, err := id.NewULID()
- if err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("error creating id for new domain block %s: %s", domain, err))
- }
-
newBlock := &gtsmodel.DomainBlock{
- ID: blockID,
+ ID: id.NewULID(),
Domain: domain,
CreatedByAccountID: account.ID,
PrivateComment: text.SanitizePlaintext(privateComment),
diff --git a/internal/processing/federation/getfollowers.go b/internal/processing/federation/getfollowers.go
index ceed3f2d5..991954389 100644
--- a/internal/processing/federation/getfollowers.go
+++ b/internal/processing/federation/getfollowers.go
@@ -24,7 +24,6 @@ import (
"net/url"
"github.com/superseriousbusiness/activity/streams"
- "github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/transport"
)
@@ -42,10 +41,9 @@ func (p *processor) GetFollowers(ctx context.Context, requestedUsername string,
return nil, errWithCode
}
- requestingAccount, err := p.federator.GetAccount(transport.WithFastfail(ctx), dereferencing.GetAccountParams{
- RequestingUsername: requestedUsername,
- RemoteAccountID: requestingAccountURI,
- })
+ requestingAccount, err := p.federator.GetAccountByURI(
+ transport.WithFastfail(ctx), requestedUsername, requestingAccountURI, false,
+ )
if err != nil {
return nil, gtserror.NewErrorUnauthorized(err)
}
diff --git a/internal/processing/federation/getfollowing.go b/internal/processing/federation/getfollowing.go
index 20ffae849..06acdad32 100644
--- a/internal/processing/federation/getfollowing.go
+++ b/internal/processing/federation/getfollowing.go
@@ -24,7 +24,6 @@ import (
"net/url"
"github.com/superseriousbusiness/activity/streams"
- "github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/transport"
)
@@ -42,10 +41,9 @@ func (p *processor) GetFollowing(ctx context.Context, requestedUsername string,
return nil, errWithCode
}
- requestingAccount, err := p.federator.GetAccount(transport.WithFastfail(ctx), dereferencing.GetAccountParams{
- RequestingUsername: requestedUsername,
- RemoteAccountID: requestingAccountURI,
- })
+ requestingAccount, err := p.federator.GetAccountByURI(
+ transport.WithFastfail(ctx), requestedUsername, requestingAccountURI, false,
+ )
if err != nil {
return nil, gtserror.NewErrorUnauthorized(err)
}
diff --git a/internal/processing/federation/getoutbox.go b/internal/processing/federation/getoutbox.go
index 186967c2c..6d0f2f3fe 100644
--- a/internal/processing/federation/getoutbox.go
+++ b/internal/processing/federation/getoutbox.go
@@ -25,7 +25,6 @@ import (
"github.com/superseriousbusiness/activity/streams"
"github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/transport"
)
@@ -43,10 +42,9 @@ func (p *processor) GetOutbox(ctx context.Context, requestedUsername string, pag
return nil, errWithCode
}
- requestingAccount, err := p.federator.GetAccount(transport.WithFastfail(ctx), dereferencing.GetAccountParams{
- RequestingUsername: requestedUsername,
- RemoteAccountID: requestingAccountURI,
- })
+ requestingAccount, err := p.federator.GetAccountByURI(
+ transport.WithFastfail(ctx), requestedUsername, requestingAccountURI, false,
+ )
if err != nil {
return nil, gtserror.NewErrorUnauthorized(err)
}
diff --git a/internal/processing/federation/getstatus.go b/internal/processing/federation/getstatus.go
index 08646ceda..b54e17b11 100644
--- a/internal/processing/federation/getstatus.go
+++ b/internal/processing/federation/getstatus.go
@@ -24,7 +24,6 @@ import (
"net/url"
"github.com/superseriousbusiness/activity/streams"
- "github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/transport"
)
@@ -42,10 +41,9 @@ func (p *processor) GetStatus(ctx context.Context, requestedUsername string, req
return nil, errWithCode
}
- requestingAccount, err := p.federator.GetAccount(transport.WithFastfail(ctx), dereferencing.GetAccountParams{
- RequestingUsername: requestedUsername,
- RemoteAccountID: requestingAccountURI,
- })
+ requestingAccount, err := p.federator.GetAccountByURI(
+ transport.WithFastfail(ctx), requestedUsername, requestingAccountURI, false,
+ )
if err != nil {
return nil, gtserror.NewErrorUnauthorized(err)
}
diff --git a/internal/processing/federation/getstatusreplies.go b/internal/processing/federation/getstatusreplies.go
index 0b6d22575..08c9b1119 100644
--- a/internal/processing/federation/getstatusreplies.go
+++ b/internal/processing/federation/getstatusreplies.go
@@ -25,7 +25,6 @@ import (
"github.com/superseriousbusiness/activity/streams"
"github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/transport"
@@ -44,10 +43,9 @@ func (p *processor) GetStatusReplies(ctx context.Context, requestedUsername stri
return nil, errWithCode
}
- requestingAccount, err := p.federator.GetAccount(transport.WithFastfail(ctx), dereferencing.GetAccountParams{
- RequestingUsername: requestedUsername,
- RemoteAccountID: requestingAccountURI,
- })
+ requestingAccount, err := p.federator.GetAccountByURI(
+ transport.WithFastfail(ctx), requestedUsername, requestingAccountURI, false,
+ )
if err != nil {
return nil, gtserror.NewErrorUnauthorized(err)
}
diff --git a/internal/processing/federation/getuser.go b/internal/processing/federation/getuser.go
index 97f452aa3..d3fb7bdf6 100644
--- a/internal/processing/federation/getuser.go
+++ b/internal/processing/federation/getuser.go
@@ -25,20 +25,20 @@ import (
"github.com/superseriousbusiness/activity/streams"
"github.com/superseriousbusiness/activity/streams/vocab"
- "github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/transport"
"github.com/superseriousbusiness/gotosocial/internal/uris"
)
func (p *processor) GetUser(ctx context.Context, requestedUsername string, requestURL *url.URL) (interface{}, gtserror.WithCode) {
- // get the account the request is referring to
+ // Get the instance-local account the request is referring to.
requestedAccount, err := p.db.GetAccountByUsernameDomain(ctx, requestedUsername, "")
if err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err))
}
var requestedPerson vocab.ActivityStreamsPerson
+
if uris.IsPublicKeyPath(requestURL) {
// if it's a public key path, we don't need to authenticate but we'll only serve the bare minimum user profile needed for the public key
requestedPerson, err = p.tc.AccountToASMinimal(ctx, requestedAccount)
@@ -53,11 +53,10 @@ func (p *processor) GetUser(ctx context.Context, requestedUsername string, reque
}
// if we're not already handshaking/dereferencing a remote account, dereference it now
- if !p.federator.Handshaking(ctx, requestedUsername, requestingAccountURI) {
- requestingAccount, err := p.federator.GetAccount(transport.WithFastfail(ctx), dereferencing.GetAccountParams{
- RequestingUsername: requestedUsername,
- RemoteAccountID: requestingAccountURI,
- })
+ if !p.federator.Handshaking(requestedUsername, requestingAccountURI) {
+ requestingAccount, err := p.federator.GetAccountByURI(
+ transport.WithFastfail(ctx), requestedUsername, requestingAccountURI, false,
+ )
if err != nil {
return nil, gtserror.NewErrorUnauthorized(err)
}
diff --git a/internal/processing/fromcommon.go b/internal/processing/fromcommon.go
index 9f0512941..1c6176565 100644
--- a/internal/processing/fromcommon.go
+++ b/internal/processing/fromcommon.go
@@ -76,13 +76,8 @@ func (p *processor) notifyStatus(ctx context.Context, status *gtsmodel.Status) e
}
// if we've reached this point we know the mention is for a local account, and the notification doesn't exist, so create it
- notifID, err := id.NewULID()
- if err != nil {
- return err
- }
-
notif := &gtsmodel.Notification{
- ID: notifID,
+ ID: id.NewULID(),
NotificationType: gtsmodel.NotificationMention,
TargetAccountID: m.TargetAccountID,
TargetAccount: m.TargetAccount,
@@ -127,13 +122,8 @@ func (p *processor) notifyFollowRequest(ctx context.Context, followRequest *gtsm
return nil
}
- notifID, err := id.NewULID()
- if err != nil {
- return err
- }
-
notif := &gtsmodel.Notification{
- ID: notifID,
+ ID: id.NewULID(),
NotificationType: gtsmodel.NotificationFollowRequest,
TargetAccountID: followRequest.TargetAccountID,
OriginAccountID: followRequest.AccountID,
@@ -172,13 +162,8 @@ func (p *processor) notifyFollow(ctx context.Context, follow *gtsmodel.Follow, t
}
// now create the new follow notification
- notifID, err := id.NewULID()
- if err != nil {
- return err
- }
-
notif := &gtsmodel.Notification{
- ID: notifID,
+ ID: id.NewULID(),
NotificationType: gtsmodel.NotificationFollow,
TargetAccountID: follow.TargetAccountID,
TargetAccount: follow.TargetAccount,
@@ -222,13 +207,8 @@ func (p *processor) notifyFave(ctx context.Context, fave *gtsmodel.StatusFave) e
return nil
}
- notifID, err := id.NewULID()
- if err != nil {
- return err
- }
-
notif := &gtsmodel.Notification{
- ID: notifID,
+ ID: id.NewULID(),
NotificationType: gtsmodel.NotificationFave,
TargetAccountID: fave.TargetAccountID,
TargetAccount: fave.TargetAccount,
@@ -301,13 +281,8 @@ func (p *processor) notifyAnnounce(ctx context.Context, status *gtsmodel.Status)
}
// now create the new reblog notification
- notifID, err := id.NewULID()
- if err != nil {
- return err
- }
-
notif := &gtsmodel.Notification{
- ID: notifID,
+ ID: id.NewULID(),
NotificationType: gtsmodel.NotificationReblog,
TargetAccountID: status.BoostOfAccountID,
TargetAccount: status.BoostOfAccount,
diff --git a/internal/processing/fromfederator.go b/internal/processing/fromfederator.go
index c30fc2692..e37488794 100644
--- a/internal/processing/fromfederator.go
+++ b/internal/processing/fromfederator.go
@@ -27,7 +27,6 @@ import (
"codeberg.org/gruf/go-kv"
"codeberg.org/gruf/go-logger/v2/level"
"github.com/superseriousbusiness/gotosocial/internal/ap"
- "github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/log"
@@ -154,11 +153,11 @@ func (p *processor) processCreateStatusFromFederator(ctx context.Context, federa
return err
}
- a, err := p.federator.GetAccount(ctx, dereferencing.GetAccountParams{
- RequestingUsername: federatorMsg.ReceivingAccount.Username,
- RemoteAccountID: remoteAccountID,
- Blocking: true,
- })
+ a, err := p.federator.GetAccountByURI(ctx,
+ federatorMsg.ReceivingAccount.Username,
+ remoteAccountID,
+ true,
+ )
if err != nil {
return err
}
@@ -200,11 +199,11 @@ func (p *processor) processCreateFaveFromFederator(ctx context.Context, federato
return err
}
- a, err := p.federator.GetAccount(ctx, dereferencing.GetAccountParams{
- RequestingUsername: federatorMsg.ReceivingAccount.Username,
- RemoteAccountID: remoteAccountID,
- Blocking: true,
- })
+ a, err := p.federator.GetAccountByURI(ctx,
+ federatorMsg.ReceivingAccount.Username,
+ remoteAccountID,
+ true,
+ )
if err != nil {
return err
}
@@ -242,11 +241,11 @@ func (p *processor) processCreateFollowRequestFromFederator(ctx context.Context,
return err
}
- a, err := p.federator.GetAccount(ctx, dereferencing.GetAccountParams{
- RequestingUsername: federatorMsg.ReceivingAccount.Username,
- RemoteAccountID: remoteAccountID,
- Blocking: true,
- })
+ a, err := p.federator.GetAccountByURI(ctx,
+ federatorMsg.ReceivingAccount.Username,
+ remoteAccountID,
+ true,
+ )
if err != nil {
return err
}
@@ -303,11 +302,11 @@ func (p *processor) processCreateAnnounceFromFederator(ctx context.Context, fede
return err
}
- a, err := p.federator.GetAccount(ctx, dereferencing.GetAccountParams{
- RequestingUsername: federatorMsg.ReceivingAccount.Username,
- RemoteAccountID: remoteAccountID,
- Blocking: true,
- })
+ a, err := p.federator.GetAccountByURI(ctx,
+ federatorMsg.ReceivingAccount.Username,
+ remoteAccountID,
+ true,
+ )
if err != nil {
return err
}
@@ -380,14 +379,11 @@ func (p *processor) processUpdateAccountFromFederator(ctx context.Context, feder
}
// further database updates occur inside getremoteaccount
- if _, err := p.federator.GetAccount(ctx, dereferencing.GetAccountParams{
- RequestingUsername: federatorMsg.ReceivingAccount.Username,
- RemoteAccountID: incomingAccountURL,
- RemoteAccountHost: incomingAccount.Domain,
- RemoteAccountUsername: incomingAccount.Username,
- PartialAccount: incomingAccount,
- Blocking: true,
- }); err != nil {
+ if _, err := p.federator.GetAccountByURI(ctx,
+ federatorMsg.ReceivingAccount.Username,
+ incomingAccountURL,
+ true,
+ ); err != nil {
return fmt.Errorf("error enriching updated account from federator: %s", err)
}
diff --git a/internal/processing/report/create.go b/internal/processing/report/create.go
index cc2f2405c..a7e83b656 100644
--- a/internal/processing/report/create.go
+++ b/internal/processing/report/create.go
@@ -64,11 +64,7 @@ func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, form
}
}
- reportID, err := id.NewULID()
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
-
+ reportID := id.NewULID()
report := &gtsmodel.Report{
ID: reportID,
URI: uris.GenerateURIForReport(reportID),
diff --git a/internal/processing/search.go b/internal/processing/search.go
index 6082d3539..6db938b37 100644
--- a/internal/processing/search.go
+++ b/internal/processing/search.go
@@ -27,6 +27,8 @@ import (
"codeberg.org/gruf/go-kv"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
+ "github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
@@ -85,7 +87,7 @@ func (p *processor) SearchGet(ctx context.Context, authed *oauth.Auth, search *a
if username, domain, err := util.ExtractNamestringParts(maybeNamestring); err == nil {
l.Trace("search term is a mention, looking it up...")
- foundAccount, err := p.searchAccountByMention(ctx, authed, username, domain, search.Resolve)
+ foundAccount, err := p.searchAccountByUsernameDomain(ctx, authed, username, domain, search.Resolve)
if err != nil {
var errNotRetrievable *dereferencing.ErrNotRetrievable
if !errors.As(err, &errNotRetrievable) {
@@ -210,27 +212,70 @@ func (p *processor) searchStatusByURI(ctx context.Context, authed *oauth.Auth, u
if !*status.Local && statusable != nil {
// Attempt to dereference the status thread while we are here
- p.federator.DereferenceRemoteThread(transport.WithFastfail(ctx), authed.Account.Username, uri, status, statusable)
+ p.federator.DereferenceThread(transport.WithFastfail(ctx), authed.Account.Username, uri, status, statusable)
}
return status, nil
}
func (p *processor) searchAccountByURI(ctx context.Context, authed *oauth.Auth, uri *url.URL, resolve bool) (*gtsmodel.Account, error) {
- return p.federator.GetAccount(transport.WithFastfail(ctx), dereferencing.GetAccountParams{
- RequestingUsername: authed.Account.Username,
- RemoteAccountID: uri,
- Blocking: true,
- SkipResolve: !resolve,
- })
+ if !resolve {
+ var (
+ account *gtsmodel.Account
+ err error
+ uriStr = uri.String()
+ )
+
+ // Search the database for existing account with ID URI.
+ account, err = p.db.GetAccountByURI(ctx, uriStr)
+ if err != nil && !errors.Is(err, db.ErrNoEntries) {
+ return nil, fmt.Errorf("searchAccountByURI: error checking database for account %s: %w", uriStr, err)
+ }
+
+ if account == nil {
+ // Else, search the database for existing by ID URL.
+ account, err = p.db.GetAccountByURL(ctx, uriStr)
+ if err != nil {
+ if !errors.Is(err, db.ErrNoEntries) {
+ return nil, fmt.Errorf("searchAccountByURI: error checking database for account %s: %w", uriStr, err)
+ }
+ return nil, dereferencing.NewErrNotRetrievable(err)
+ }
+ }
+
+ return account, nil
+ }
+
+ return p.federator.GetAccountByURI(
+ transport.WithFastfail(ctx),
+ authed.Account.Username,
+ uri, false,
+ )
}
-func (p *processor) searchAccountByMention(ctx context.Context, authed *oauth.Auth, username string, domain string, resolve bool) (*gtsmodel.Account, error) {
- return p.federator.GetAccount(transport.WithFastfail(ctx), dereferencing.GetAccountParams{
- RequestingUsername: authed.Account.Username,
- RemoteAccountUsername: username,
- RemoteAccountHost: domain,
- Blocking: true,
- SkipResolve: !resolve,
- })
+func (p *processor) searchAccountByUsernameDomain(ctx context.Context, authed *oauth.Auth, username string, domain string, resolve bool) (*gtsmodel.Account, error) {
+ if !resolve {
+ if domain == config.GetHost() || domain == config.GetAccountDomain() {
+ // We do local lookups using an empty domain,
+ // else it will fail the db search below.
+ domain = ""
+ }
+
+ // Search the database for existing account with USERNAME@DOMAIN
+ account, err := p.db.GetAccountByUsernameDomain(ctx, username, domain)
+ if err != nil {
+ if !errors.Is(err, db.ErrNoEntries) {
+ return nil, fmt.Errorf("searchAccountByUsernameDomain: error checking database for account %s@%s: %w", username, domain, err)
+ }
+ return nil, dereferencing.NewErrNotRetrievable(err)
+ }
+
+ return account, nil
+ }
+
+ return p.federator.GetAccountByUsernameDomain(
+ transport.WithFastfail(ctx),
+ authed.Account.Username,
+ username, domain, false,
+ )
}
diff --git a/internal/processing/status/bookmark.go b/internal/processing/status/bookmark.go
index 6f5c7f633..3cf64490a 100644
--- a/internal/processing/status/bookmark.go
+++ b/internal/processing/status/bookmark.go
@@ -55,14 +55,9 @@ func (p *processor) Bookmark(ctx context.Context, requestingAccount *gtsmodel.Ac
}
if newBookmark {
- thisBookmarkID, err := id.NewULID()
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
-
// we need to create a new bookmark in the database
gtsBookmark := &gtsmodel.StatusBookmark{
- ID: thisBookmarkID,
+ ID: id.NewULID(),
AccountID: requestingAccount.ID,
Account: requestingAccount,
TargetAccountID: targetStatus.AccountID,
diff --git a/internal/processing/status/create.go b/internal/processing/status/create.go
index 9e9d24c84..5bc1629c4 100644
--- a/internal/processing/status/create.go
+++ b/internal/processing/status/create.go
@@ -35,11 +35,7 @@ import (
func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, application *gtsmodel.Application, form *apimodel.AdvancedStatusCreateForm) (*apimodel.Status, gtserror.WithCode) {
accountURIs := uris.GenerateURIsForAccount(account.Username)
- thisStatusID, err := id.NewULID()
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
-
+ thisStatusID := id.NewULID()
local := true
sensitive := form.Sensitive
diff --git a/internal/processing/status/fave.go b/internal/processing/status/fave.go
index 3686eb96f..dd5d338b3 100644
--- a/internal/processing/status/fave.go
+++ b/internal/processing/status/fave.go
@@ -62,10 +62,7 @@ func (p *processor) Fave(ctx context.Context, requestingAccount *gtsmodel.Accoun
}
if newFave {
- thisFaveID, err := id.NewULID()
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
+ thisFaveID := id.NewULID()
// we need to create a new fave in the database
gtsFave := &gtsmodel.StatusFave{
diff --git a/internal/processing/util.go b/internal/processing/util.go
index 1e86c8f76..27cb9fabe 100644
--- a/internal/processing/util.go
+++ b/internal/processing/util.go
@@ -25,7 +25,6 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
- "github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/transport"
@@ -54,21 +53,24 @@ func GetParseMentionFunc(dbConn db.DB, federator federation.Federator) gtsmodel.
mentionedAccount = localAccount
} else {
var requestingUsername string
+
if originAccount.Domain == "" {
requestingUsername = originAccount.Username
}
- remoteAccount, err := federator.GetAccount(transport.WithFastfail(ctx), dereferencing.GetAccountParams{
- RequestingUsername: requestingUsername,
- RemoteAccountUsername: username,
- RemoteAccountHost: domain,
- })
+
+ remoteAccount, err := federator.GetAccountByUsernameDomain(
+ transport.WithFastfail(ctx),
+ requestingUsername,
+ username,
+ domain,
+ false,
+ )
if err != nil {
- return nil, fmt.Errorf("error dereferencing account: %s", err)
+ return nil, fmt.Errorf("parseMentionFunc: error fetching account: %s", err)
}
// we were able to resolve it!
mentionedAccount = remoteAccount
-
}
mentionID, err := id.NewRandomULID()