summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb/inbox.go
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-05-27 16:06:24 +0200
committerLibravatar GitHub <noreply@github.com>2021-05-27 16:06:24 +0200
commit40add686913b7eb6edd5a780e37e7513b43a337f (patch)
tree75549dff97e5a15f732a505d4d00aa7a686bdad8 /internal/federation/federatingdb/inbox.go
parentFaves (#31) (diff)
downloadgotosocial-40add686913b7eb6edd5a780e37e7513b43a337f.tar.xz
Notifications (#34)
Notifications working for: * Mentions * Faves * New follow requests * New followers
Diffstat (limited to 'internal/federation/federatingdb/inbox.go')
-rw-r--r--internal/federation/federatingdb/inbox.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/internal/federation/federatingdb/inbox.go b/internal/federation/federatingdb/inbox.go
new file mode 100644
index 000000000..25ef2cda5
--- /dev/null
+++ b/internal/federation/federatingdb/inbox.go
@@ -0,0 +1,73 @@
+package federatingdb
+
+import (
+ "context"
+ "fmt"
+ "net/url"
+
+ "github.com/go-fed/activity/pub"
+ "github.com/go-fed/activity/streams"
+ "github.com/go-fed/activity/streams/vocab"
+ "github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
+)
+
+// InboxContains returns true if the OrderedCollection at 'inbox'
+// contains the specified 'id'.
+//
+// The library makes this call only after acquiring a lock first.
+func (f *federatingDB) InboxContains(c context.Context, inbox, id *url.URL) (contains bool, err error) {
+ l := f.log.WithFields(
+ logrus.Fields{
+ "func": "InboxContains",
+ "id": id.String(),
+ },
+ )
+ l.Debugf("entering INBOXCONTAINS function with for inbox %s and id %s", inbox.String(), id.String())
+
+ if !util.IsInboxPath(inbox) {
+ return false, fmt.Errorf("%s is not an inbox URI", inbox.String())
+ }
+
+ activityI := c.Value(util.APActivity)
+ if activityI == nil {
+ return false, fmt.Errorf("no activity was set for id %s", id.String())
+ }
+ activity, ok := activityI.(pub.Activity)
+ if !ok || activity == nil {
+ return false, fmt.Errorf("could not parse contextual activity for id %s", id.String())
+ }
+
+ l.Debugf("activity type %s for id %s", activity.GetTypeName(), id.String())
+
+ return false, nil
+}
+
+// GetInbox returns the first ordered collection page of the outbox at
+// the specified IRI, for prepending new items.
+//
+// The library makes this call only after acquiring a lock first.
+func (f *federatingDB) GetInbox(c context.Context, inboxIRI *url.URL) (inbox vocab.ActivityStreamsOrderedCollectionPage, err error) {
+ l := f.log.WithFields(
+ logrus.Fields{
+ "func": "GetInbox",
+ },
+ )
+ l.Debugf("entering GETINBOX function with inboxIRI %s", inboxIRI.String())
+ return streams.NewActivityStreamsOrderedCollectionPage(), nil
+}
+
+// SetInbox saves the inbox value given from GetInbox, with new items
+// prepended. Note that the new items must not be added as independent
+// database entries. Separate calls to Create will do that.
+//
+// The library makes this call only after acquiring a lock first.
+func (f *federatingDB) SetInbox(c context.Context, inbox vocab.ActivityStreamsOrderedCollectionPage) error {
+ l := f.log.WithFields(
+ logrus.Fields{
+ "func": "SetInbox",
+ },
+ )
+ l.Debug("entering SETINBOX function")
+ return nil
+}