Skip to content

Commit

Permalink
First pass at additional ActivityPub handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
benpate committed Nov 30, 2023
1 parent 767c0a1 commit 149003d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions handler/activitypub_receive_announce_any.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package handler

import (
"github.com/EmissarySocial/emissary/domain"
"github.com/EmissarySocial/emissary/model"
"github.com/benpate/derp"
"github.com/benpate/hannibal/streams"
"github.com/benpate/hannibal/vocab"
)

func init() {
inboxRouter.Add(vocab.ActivityTypeAnnounce, vocab.Any, receiveAnnounce)
}

// receiveAnnounce handles all Announce, Like, and Dislike activities
func receiveAnnounce(factory *domain.Factory, user *model.User, activity streams.Document) error {

const location = "handler.receiveAnnounce"

// RULE: Verify that the ActivityID exists
if activity.ID() == "" {
return derp.NewBadRequestError(location, activity.Type()+" activities must have an ID")
}

// Load the Activity from JSON-LD.
// This populates the document in the ActivityStream cache
activity, err := factory.ActivityStreams().Load(activity.ID())

if err != nil {
return derp.NewBadRequestError(location, "Unable to load Activity "+activity.ID())
}

// Last, preload the cache with the activity "Object", which is the document being Liked/Disliked
_, _ = activity.Object().Load()

// Success.
return nil
}
1 change: 1 addition & 0 deletions handler/activitypub_receive_undo_like.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package handler

0 comments on commit 149003d

Please sign in to comment.