mirror of
https://code.naskya.net/repos/ndqEd
synced 2025-01-10 16:26:46 +09:00
Vocabulary for Project
This commit is contained in:
parent
cc87b6e17d
commit
050e8d09bc
1 changed files with 59 additions and 0 deletions
|
@ -46,6 +46,7 @@ module Web.ActivityPub
|
||||||
, CollectionPage (..)
|
, CollectionPage (..)
|
||||||
, Recipient (..)
|
, Recipient (..)
|
||||||
, Resource (..)
|
, Resource (..)
|
||||||
|
, Project (..)
|
||||||
|
|
||||||
-- * Content objects
|
-- * Content objects
|
||||||
, Note (..)
|
, Note (..)
|
||||||
|
@ -374,6 +375,7 @@ data ActorType
|
||||||
| ActorTypeRepo
|
| ActorTypeRepo
|
||||||
| ActorTypeTicketTracker
|
| ActorTypeTicketTracker
|
||||||
| ActorTypePatchTracker
|
| ActorTypePatchTracker
|
||||||
|
| ActorTypeProject
|
||||||
| ActorTypeOther Text
|
| ActorTypeOther Text
|
||||||
deriving Eq
|
deriving Eq
|
||||||
|
|
||||||
|
@ -385,6 +387,7 @@ instance FromJSON ActorType where
|
||||||
| t == "Repository" = ActorTypeRepo
|
| t == "Repository" = ActorTypeRepo
|
||||||
| t == "TicketTracker" = ActorTypeTicketTracker
|
| t == "TicketTracker" = ActorTypeTicketTracker
|
||||||
| t == "PatchTracker" = ActorTypePatchTracker
|
| t == "PatchTracker" = ActorTypePatchTracker
|
||||||
|
| t == "Project" = ActorTypeProject
|
||||||
| otherwise = ActorTypeOther t
|
| otherwise = ActorTypeOther t
|
||||||
|
|
||||||
instance ToJSON ActorType where
|
instance ToJSON ActorType where
|
||||||
|
@ -395,6 +398,7 @@ instance ToJSON ActorType where
|
||||||
ActorTypeRepo -> "Repository"
|
ActorTypeRepo -> "Repository"
|
||||||
ActorTypeTicketTracker -> "TicketTracker"
|
ActorTypeTicketTracker -> "TicketTracker"
|
||||||
ActorTypePatchTracker -> "PatchTracker"
|
ActorTypePatchTracker -> "PatchTracker"
|
||||||
|
ActorTypeProject -> "Project"
|
||||||
ActorTypeOther t -> t
|
ActorTypeOther t -> t
|
||||||
|
|
||||||
data Owner = OwnerInstance | OwnerActor LocalURI
|
data Owner = OwnerInstance | OwnerActor LocalURI
|
||||||
|
@ -810,6 +814,61 @@ instance ActivityPub Resource where
|
||||||
= "id" .= ObjURI h luId
|
= "id" .= ObjURI h luId
|
||||||
<> "managedBy" .= ObjURI h luManager
|
<> "managedBy" .= ObjURI h luManager
|
||||||
|
|
||||||
|
data Project u = Project
|
||||||
|
{ projectActor :: Actor u
|
||||||
|
, projectTracker :: Maybe (ObjURI u)
|
||||||
|
, projectChildren :: [ObjURI u]
|
||||||
|
, projectParents :: [ObjURI u]
|
||||||
|
, projectComponents :: [ObjURI u]
|
||||||
|
}
|
||||||
|
|
||||||
|
instance ActivityPub Project where
|
||||||
|
jsonldContext _ = [as2Context, secContext, forgeContext]
|
||||||
|
parseObject o = do
|
||||||
|
(h, a) <- parseObject o
|
||||||
|
unless (actorType (actorDetail a) == ActorTypeProject) $
|
||||||
|
fail "Actor type isn't Project"
|
||||||
|
fmap (h,) $
|
||||||
|
Project a
|
||||||
|
<$> o .:? "ticketsTrackedBy"
|
||||||
|
<*> (do c <- o .: "subprojects"
|
||||||
|
typ <- c .: "type"
|
||||||
|
unless (typ == ("Collection" :: Text)) $
|
||||||
|
fail "subprojects.type isn't Collection"
|
||||||
|
items <- c .: "items"
|
||||||
|
mtotal <- c .:? "totalItems"
|
||||||
|
for_ mtotal $ \ total ->
|
||||||
|
unless (length items == total) $
|
||||||
|
fail "Incorrect totalItems"
|
||||||
|
return items
|
||||||
|
)
|
||||||
|
<*> o .:? "context" .!= []
|
||||||
|
<*> (do c <- o .: "components"
|
||||||
|
typ <- c .: "type"
|
||||||
|
unless (typ == ("Collection" :: Text)) $
|
||||||
|
fail "components.type isn't Collection"
|
||||||
|
items <- c .: "items"
|
||||||
|
mtotal <- c .:? "totalItems"
|
||||||
|
for_ mtotal $ \ total ->
|
||||||
|
unless (length items == total) $
|
||||||
|
fail "Incorrect totalItems"
|
||||||
|
return items
|
||||||
|
)
|
||||||
|
toSeries h (Project actor tracker children parents components)
|
||||||
|
= toSeries h actor
|
||||||
|
<> "ticketsTrackedBy" .=? tracker
|
||||||
|
<> "subprojects" `pair` pairs
|
||||||
|
( "type" .= ("Collection" :: Text)
|
||||||
|
<> "items" .= children
|
||||||
|
<> "totalItems" .= length children
|
||||||
|
)
|
||||||
|
<> "context" .= parents
|
||||||
|
<> "components" `pair` pairs
|
||||||
|
( "type" .= ("Collection" :: Text)
|
||||||
|
<> "items" .= components
|
||||||
|
<> "totalItems" .= length components
|
||||||
|
)
|
||||||
|
|
||||||
data Audience u = Audience
|
data Audience u = Audience
|
||||||
{ audienceTo :: [ObjURI u]
|
{ audienceTo :: [ObjURI u]
|
||||||
, audienceBto :: [ObjURI u]
|
, audienceBto :: [ObjURI u]
|
||||||
|
|
Loading…
Reference in a new issue