From 58c07193702b9c069ecd94c594903d2f45ad1ae9 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Thu, 23 Jul 2020 14:27:11 +0000 Subject: [PATCH] Web.ActivityPub: Add a Resolve activity --- src/Web/ActivityPub.hs | 57 ++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/src/Web/ActivityPub.hs b/src/Web/ActivityPub.hs index f6fcdea..716f633 100644 --- a/src/Web/ActivityPub.hs +++ b/src/Web/ActivityPub.hs @@ -66,6 +66,7 @@ module Web.ActivityPub , Offer (..) , Push (..) , Reject (..) + , Resolve (..) , Undo (..) , Audience (..) , SpecificActivity (..) @@ -1332,6 +1333,16 @@ parseReject o = Reject <$> o .: "object" encodeReject :: UriMode u => Reject u -> Series encodeReject (Reject obj) = "object" .= obj +data Resolve u = Resolve + { resolveObject :: ObjURI u + } + +parseResolve :: UriMode u => Object -> Parser (Resolve u) +parseResolve o = Resolve <$> o .: "object" + +encodeResolve :: UriMode u => Resolve u -> Series +encodeResolve (Resolve obj) = "object" .= obj + data Undo u = Undo { undoObject :: LocalURI } @@ -1349,6 +1360,7 @@ data SpecificActivity u | OfferActivity (Offer u) | PushActivity (Push u) | RejectActivity (Reject u) + | ResolveActivity (Resolve u) | UndoActivity (Undo u) data Activity u = Activity @@ -1372,13 +1384,14 @@ instance ActivityPub Activity where <*> do typ <- o .: "type" case typ of - "Accept" -> AcceptActivity <$> parseAccept a o - "Create" -> CreateActivity <$> parseCreate o a actor - "Follow" -> FollowActivity <$> parseFollow o - "Offer" -> OfferActivity <$> parseOffer o a actor - "Push" -> PushActivity <$> parsePush a o - "Reject" -> RejectActivity <$> parseReject o - "Undo" -> UndoActivity <$> parseUndo a o + "Accept" -> AcceptActivity <$> parseAccept a o + "Create" -> CreateActivity <$> parseCreate o a actor + "Follow" -> FollowActivity <$> parseFollow o + "Offer" -> OfferActivity <$> parseOffer o a actor + "Push" -> PushActivity <$> parsePush a o + "Reject" -> RejectActivity <$> parseReject o + "Resolve" -> ResolveActivity <$> parseResolve o + "Undo" -> UndoActivity <$> parseUndo a o _ -> fail $ "Unrecognized activity type: " ++ T.unpack typ @@ -1391,20 +1404,22 @@ instance ActivityPub Activity where <> encodeSpecific authority actor specific where activityType :: SpecificActivity u -> Text - activityType (AcceptActivity _) = "Accept" - activityType (CreateActivity _) = "Create" - activityType (FollowActivity _) = "Follow" - activityType (OfferActivity _) = "Offer" - activityType (PushActivity _) = "Push" - activityType (RejectActivity _) = "Reject" - activityType (UndoActivity _) = "Undo" - encodeSpecific h _ (AcceptActivity a) = encodeAccept h a - encodeSpecific h u (CreateActivity a) = encodeCreate h u a - encodeSpecific _ _ (FollowActivity a) = encodeFollow a - encodeSpecific h u (OfferActivity a) = encodeOffer h u a - encodeSpecific h _ (PushActivity a) = encodePush h a - encodeSpecific _ _ (RejectActivity a) = encodeReject a - encodeSpecific h _ (UndoActivity a) = encodeUndo h a + activityType (AcceptActivity _) = "Accept" + activityType (CreateActivity _) = "Create" + activityType (FollowActivity _) = "Follow" + activityType (OfferActivity _) = "Offer" + activityType (PushActivity _) = "Push" + activityType (RejectActivity _) = "Reject" + activityType (ResolveActivity _) = "Resolve" + activityType (UndoActivity _) = "Undo" + encodeSpecific h _ (AcceptActivity a) = encodeAccept h a + encodeSpecific h u (CreateActivity a) = encodeCreate h u a + encodeSpecific _ _ (FollowActivity a) = encodeFollow a + encodeSpecific h u (OfferActivity a) = encodeOffer h u a + encodeSpecific h _ (PushActivity a) = encodePush h a + encodeSpecific _ _ (RejectActivity a) = encodeReject a + encodeSpecific _ _ (ResolveActivity a) = encodeResolve a + encodeSpecific h _ (UndoActivity a) = encodeUndo h a emptyAudience :: Audience u emptyAudience = Audience [] [] [] [] [] []