summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb
diff options
context:
space:
mode:
Diffstat (limited to 'internal/federation/federatingdb')
-rw-r--r--internal/federation/federatingdb/inbox.go20
-rw-r--r--internal/federation/federatingdb/inbox_test.go21
2 files changed, 39 insertions, 2 deletions
diff --git a/internal/federation/federatingdb/inbox.go b/internal/federation/federatingdb/inbox.go
index b3b935bff..18f620bce 100644
--- a/internal/federation/federatingdb/inbox.go
+++ b/internal/federation/federatingdb/inbox.go
@@ -108,7 +108,15 @@ func (f *federatingDB) InboxesForIRI(c context.Context, iri *url.URL) (inboxIRIs
follow.Account = followingAccount
}
- inboxIRI, err := url.Parse(follow.Account.InboxURI)
+ // deliver to a shared inbox if we have that option
+ var inbox string
+ if config.GetInstanceDeliverToSharedInboxes() && follow.Account.SharedInboxURI != nil && *follow.Account.SharedInboxURI != "" {
+ inbox = *follow.Account.SharedInboxURI
+ } else {
+ inbox = follow.Account.InboxURI
+ }
+
+ inboxIRI, err := url.Parse(inbox)
if err != nil {
return nil, fmt.Errorf("error parsing inbox uri of following account %s: %s", follow.Account.InboxURI, err)
}
@@ -119,7 +127,15 @@ func (f *federatingDB) InboxesForIRI(c context.Context, iri *url.URL) (inboxIRIs
// check if this is just an account IRI...
if account, err := f.db.GetAccountByURI(c, iri.String()); err == nil {
- inboxIRI, err := url.Parse(account.InboxURI)
+ // deliver to a shared inbox if we have that option
+ var inbox string
+ if config.GetInstanceDeliverToSharedInboxes() && account.SharedInboxURI != nil && *account.SharedInboxURI != "" {
+ inbox = *account.SharedInboxURI
+ } else {
+ inbox = account.InboxURI
+ }
+
+ inboxIRI, err := url.Parse(inbox)
if err != nil {
return nil, fmt.Errorf("error parsing account inbox uri %s: %s", account.InboxURI, account.InboxURI)
}
diff --git a/internal/federation/federatingdb/inbox_test.go b/internal/federation/federatingdb/inbox_test.go
index fb3b96944..dbf9d3c53 100644
--- a/internal/federation/federatingdb/inbox_test.go
+++ b/internal/federation/federatingdb/inbox_test.go
@@ -63,6 +63,27 @@ func (suite *InboxTestSuite) TestInboxesForAccountIRI() {
suite.Contains(asStrings, suite.testAccounts["local_account_1"].InboxURI)
}
+func (suite *InboxTestSuite) TestInboxesForAccountIRIWithSharedInbox() {
+ ctx := context.Background()
+ testAccount := suite.testAccounts["local_account_1"]
+ sharedInbox := "http://some-inbox-iri/weeeeeeeeeeeee"
+ testAccount.SharedInboxURI = &sharedInbox
+ if _, err := suite.db.UpdateAccount(ctx, testAccount); err != nil {
+ suite.FailNow("error updating account")
+ }
+
+ inboxIRIs, err := suite.federatingDB.InboxesForIRI(ctx, testrig.URLMustParse(testAccount.URI))
+ suite.NoError(err)
+
+ asStrings := []string{}
+ for _, i := range inboxIRIs {
+ asStrings = append(asStrings, i.String())
+ }
+
+ suite.Len(asStrings, 1)
+ suite.Contains(asStrings, "http://some-inbox-iri/weeeeeeeeeeeee")
+}
+
func TestInboxTestSuite(t *testing.T) {
suite.Run(t, &InboxTestSuite{})
}