-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at additional ActivityPub handlers
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package handler |