mirror of
https://code.naskya.net/repos/ndqEd
synced 2025-01-10 16:26:46 +09:00
Web.ActivityPub: Allow Create object to be a Ticket
This commit is contained in:
parent
0de98a9cdd
commit
6d25d7ec2c
4 changed files with 30 additions and 10 deletions
|
@ -352,7 +352,7 @@ createNoteC host (Note mluNote luAttrib aud muParent muContext mpublished source
|
|||
Just $ TextHtml $ TL.toStrict $ renderHtml summary
|
||||
, activityAudience = aud
|
||||
, activitySpecific = CreateActivity Create
|
||||
{ createObject = Note
|
||||
{ createObject = CreateNote Note
|
||||
{ noteId = Just luNote
|
||||
, noteAttrib = luAttrib
|
||||
, noteAudience = aud
|
||||
|
|
|
@ -266,8 +266,11 @@ handleSharerInbox now shrRecip (ActivityAuthRemote author) body =
|
|||
case activitySpecific $ actbActivity body of
|
||||
AcceptActivity accept ->
|
||||
sharerAcceptF shrRecip now author body accept
|
||||
CreateActivity (Create note) ->
|
||||
sharerCreateNoteF now shrRecip author body note
|
||||
CreateActivity (Create obj) ->
|
||||
case obj of
|
||||
CreateNote note ->
|
||||
sharerCreateNoteF now shrRecip author body note
|
||||
_ -> return "Unsupported create object type for sharers"
|
||||
FollowActivity follow ->
|
||||
sharerFollowF shrRecip now author body follow
|
||||
OfferActivity offer ->
|
||||
|
@ -293,8 +296,11 @@ handleProjectInbox now shrRecip prjRecip auth body = do
|
|||
ActivityAuthLocal local -> throwE $ errorLocalForwarded local
|
||||
ActivityAuthRemote ra -> return ra
|
||||
case activitySpecific $ actbActivity body of
|
||||
CreateActivity (Create note) ->
|
||||
projectCreateNoteF now shrRecip prjRecip remoteAuthor body note
|
||||
CreateActivity (Create obj) ->
|
||||
case obj of
|
||||
CreateNote note ->
|
||||
projectCreateNoteF now shrRecip prjRecip remoteAuthor body note
|
||||
_ -> error "Unsupported create object type for projects"
|
||||
FollowActivity follow ->
|
||||
projectFollowF shrRecip prjRecip now remoteAuthor body follow
|
||||
OfferActivity offer ->
|
||||
|
|
|
@ -467,7 +467,7 @@ changes hLocal ctx =
|
|||
, activitySummary = Nothing
|
||||
, activityAudience = aud
|
||||
, activitySpecific = CreateActivity Create
|
||||
{ createObject = Note
|
||||
{ createObject = CreateNote Note
|
||||
{ noteId = Just luNote
|
||||
, noteAttrib = luAttrib
|
||||
, noteAudience = aud
|
||||
|
|
|
@ -55,6 +55,7 @@ module Web.ActivityPub
|
|||
|
||||
-- * Activity
|
||||
, Accept (..)
|
||||
, CreateObject (..)
|
||||
, Create (..)
|
||||
, Follow (..)
|
||||
, Offer (..)
|
||||
|
@ -1074,15 +1075,28 @@ encodeAccept authority (Accept obj mresult)
|
|||
= "object" .= obj
|
||||
<> "result" .=? (ObjURI authority <$> mresult)
|
||||
|
||||
data CreateObject u = CreateNote (Note u) | CreateTicket (Ticket u)
|
||||
|
||||
instance ActivityPub CreateObject where
|
||||
jsonldContext = error "jsonldContext CreateObject"
|
||||
parseObject o
|
||||
= second CreateNote <$> parseObject o
|
||||
<|> second CreateTicket <$> parseObject o
|
||||
toSeries au (CreateNote o) = toSeries au o
|
||||
toSeries au (CreateTicket o) = toSeries au o
|
||||
|
||||
data Create u = Create
|
||||
{ createObject :: Note u
|
||||
{ createObject :: CreateObject u
|
||||
}
|
||||
|
||||
parseCreate :: UriMode u => Object -> Authority u -> LocalURI -> Parser (Create u)
|
||||
parseCreate o a luActor = do
|
||||
note <- withAuthorityT a $ parseObject =<< o .: "object"
|
||||
unless (luActor == noteAttrib note) $ fail "Create actor != Note attrib"
|
||||
return $ Create note
|
||||
obj <- withAuthorityT a $ parseObject =<< o .: "object"
|
||||
unless (luActor == attrib obj) $ fail "Create actor != object attrib"
|
||||
return $ Create obj
|
||||
where
|
||||
attrib (CreateNote note) = noteAttrib note
|
||||
attrib (CreateTicket ticket) = ticketAttributedTo ticket
|
||||
|
||||
encodeCreate :: UriMode u => Authority u -> LocalURI -> Create u -> Series
|
||||
encodeCreate authority actor (Create obj) =
|
||||
|
|
Loading…
Reference in a new issue