Person: Implement (trivial) Revoke handler

This commit is contained in:
Pere Lev 2023-06-05 12:38:08 +03:00
parent b4ebd08c5a
commit d467626049
No known key found for this signature in database
GPG key ID: 5252C5C863E5E57D
2 changed files with 45 additions and 0 deletions

View file

@ -653,6 +653,32 @@ personGrant now recipPersonID author body mfwd luGrant grant = do
then done "I'm not the target; Inserted to inbox" then done "I'm not the target; Inserted to inbox"
else done "I'm the target; Inserted to inbox" else done "I'm the target; Inserted to inbox"
-- Meaning: A remote actor has revoked some previously published Grants
-- Behavior: Insert to my inbox
personRevoke
:: UTCTime
-> PersonId
-> RemoteAuthor
-> ActivityBody
-> Maybe (RecipientRoutes, ByteString)
-> LocalURI
-> AP.Revoke URIMode
-> ActE (Text, Act (), Next)
personRevoke now recipPersonID author body _mfwd luRevoke (AP.Revoke _lus) = do
maybeRevoke <- lift $ withDB $ do
-- Grab recipient person from DB
(_personRecip, actorRecip) <- do
p <- getJust recipPersonID
(p,) <$> getJust (personActor p)
insertToInbox now author body (actorInbox actorRecip) luRevoke True
case maybeRevoke of
Nothing -> done "I already have this activity in my inbox"
Just _revokeID -> done "Inserted to my inbox"
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Main behavior function -- Main behavior function
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
@ -718,6 +744,8 @@ personBehavior now personID (Right (VerseRemote author body mfwd luActivity)) =
personJoin now personID author body mfwd luActivity join personJoin now personID author body mfwd luActivity join
AP.RejectActivity reject -> AP.RejectActivity reject ->
personReject now personID author body mfwd luActivity reject personReject now personID author body mfwd luActivity reject
AP.RevokeActivity revoke ->
personRevoke now personID author body mfwd luActivity revoke
AP.UndoActivity undo -> AP.UndoActivity undo ->
personUndo now personID author body mfwd luActivity undo personUndo now personID author body mfwd luActivity undo
_ -> throwE "Unsupported activity type for Person" _ -> throwE "Unsupported activity type for Person"

View file

@ -81,6 +81,7 @@ module Web.ActivityPub
, Push (..) , Push (..)
, Reject (..) , Reject (..)
, Resolve (..) , Resolve (..)
, Revoke (..)
, Undo (..) , Undo (..)
, Audience (..) , Audience (..)
, ProofConfig (..) , ProofConfig (..)
@ -1905,6 +1906,18 @@ parseResolve o = Resolve <$> o .: "object"
encodeResolve :: UriMode u => Resolve u -> Series encodeResolve :: UriMode u => Resolve u -> Series
encodeResolve (Resolve obj) = "object" .= obj encodeResolve (Resolve obj) = "object" .= obj
data Revoke u = Revoke
{ revokeObject :: NonEmpty LocalURI
}
parseRevoke :: UriMode u => Authority u -> Object -> Parser (Revoke u)
parseRevoke h o = do
us <- o .:*+ "object"
Revoke <$> for us (withAuthorityO h . pure)
encodeRevoke :: UriMode u => Authority u -> Revoke u -> Series
encodeRevoke h (Revoke obj) = "object" .=*+ (NE.map (ObjURI h) obj)
data Undo u = Undo data Undo u = Undo
{ undoObject :: ObjURI u { undoObject :: ObjURI u
} }
@ -1979,6 +1992,7 @@ data SpecificActivity u
| PushActivity (Push u) | PushActivity (Push u)
| RejectActivity (Reject u) | RejectActivity (Reject u)
| ResolveActivity (Resolve u) | ResolveActivity (Resolve u)
| RevokeActivity (Revoke u)
| UndoActivity (Undo u) | UndoActivity (Undo u)
activityType :: SpecificActivity u -> Text activityType :: SpecificActivity u -> Text
@ -1994,6 +2008,7 @@ activityType (OfferActivity _) = "Offer"
activityType (PushActivity _) = "Push" activityType (PushActivity _) = "Push"
activityType (RejectActivity _) = "Reject" activityType (RejectActivity _) = "Reject"
activityType (ResolveActivity _) = "Resolve" activityType (ResolveActivity _) = "Resolve"
activityType (RevokeActivity _) = "Revoke"
activityType (UndoActivity _) = "Undo" activityType (UndoActivity _) = "Undo"
data Action u = Action data Action u = Action
@ -2057,6 +2072,7 @@ instance ActivityPub Activity where
"Push" -> PushActivity <$> parsePush a o "Push" -> PushActivity <$> parsePush a o
"Reject" -> RejectActivity <$> parseReject o "Reject" -> RejectActivity <$> parseReject o
"Resolve" -> ResolveActivity <$> parseResolve o "Resolve" -> ResolveActivity <$> parseResolve o
"Revoke" -> RevokeActivity <$> parseRevoke a o
"Undo" -> UndoActivity <$> parseUndo a o "Undo" -> UndoActivity <$> parseUndo a o
_ -> _ ->
fail $ fail $
@ -2084,6 +2100,7 @@ instance ActivityPub Activity where
encodeSpecific h _ (PushActivity a) = encodePush h a encodeSpecific h _ (PushActivity a) = encodePush h a
encodeSpecific _ _ (RejectActivity a) = encodeReject a encodeSpecific _ _ (RejectActivity a) = encodeReject a
encodeSpecific _ _ (ResolveActivity a) = encodeResolve a encodeSpecific _ _ (ResolveActivity a) = encodeResolve a
encodeSpecific h _ (RevokeActivity a) = encodeRevoke h a
encodeSpecific h _ (UndoActivity a) = encodeUndo h a encodeSpecific h _ (UndoActivity a) = encodeUndo h a
emptyAudience :: Audience u emptyAudience :: Audience u