mirror of
https://code.sup39.dev/repos/Wqawg
synced 2024-12-27 17:24:53 +09:00
Represent a ticket dep using a dedicated TicketDependency
AP type
This commit is contained in:
parent
65edc77747
commit
84765e2b94
3 changed files with 66 additions and 19 deletions
|
@ -80,7 +80,7 @@ import Control.Concurrent.ResultShare
|
||||||
import Crypto.PublicVerifKey
|
import Crypto.PublicVerifKey
|
||||||
import Network.FedURI
|
import Network.FedURI
|
||||||
import Web.ActivityAccess
|
import Web.ActivityAccess
|
||||||
import Web.ActivityPub
|
import Web.ActivityPub hiding (TicketDependency)
|
||||||
import Yesod.ActivityPub
|
import Yesod.ActivityPub
|
||||||
import Yesod.Hashids
|
import Yesod.Hashids
|
||||||
import Yesod.MonadSite
|
import Yesod.MonadSite
|
||||||
|
|
|
@ -91,7 +91,7 @@ import Database.Persist.Sql.Graph.TransitiveReduction (trrFix)
|
||||||
|
|
||||||
import Data.Aeson.Encode.Pretty.ToEncoding
|
import Data.Aeson.Encode.Pretty.ToEncoding
|
||||||
import Network.FedURI
|
import Network.FedURI
|
||||||
import Web.ActivityPub hiding (Ticket (..))
|
import Web.ActivityPub hiding (Ticket (..), TicketDependency)
|
||||||
import Yesod.ActivityPub
|
import Yesod.ActivityPub
|
||||||
import Yesod.Auth.Unverified
|
import Yesod.Auth.Unverified
|
||||||
import Yesod.FedURI
|
import Yesod.FedURI
|
||||||
|
@ -960,18 +960,17 @@ getTicketDepR tdkhid = do
|
||||||
let ticketRoute s j t =
|
let ticketRoute s j t =
|
||||||
TicketR (sharerIdent s) (projectIdent j) (ticketNumber t)
|
TicketR (sharerIdent s) (projectIdent j) (ticketNumber t)
|
||||||
here = TicketDepR tdkhid
|
here = TicketDepR tdkhid
|
||||||
tdepAP = Relationship
|
tdepAP = AP.TicketDependency
|
||||||
{ relationshipId = Just $ encodeRouteHome here
|
{ ticketDepId = Just $ encodeRouteHome here
|
||||||
, relationshipSubject =
|
, ticketDepParent =
|
||||||
encodeRouteHome $ ticketRoute sParent jParent tParent
|
encodeRouteHome $ ticketRoute sParent jParent tParent
|
||||||
, relationshipProperty = Left RelDependsOn
|
, ticketDepChild =
|
||||||
, relationshipObject =
|
|
||||||
encodeRouteHome $ ticketRoute sChild jChild tChild
|
encodeRouteHome $ ticketRoute sChild jChild tChild
|
||||||
, relationshipAttributedTo =
|
, ticketDepAttributedTo =
|
||||||
encodeRouteLocal $ SharerR $ sharerIdent sAuthor
|
encodeRouteLocal $ SharerR $ sharerIdent sAuthor
|
||||||
, relationshipPublished = Just $ ticketDependencyCreated td
|
, ticketDepPublished = Just $ ticketDependencyCreated td
|
||||||
, relationshipUpdated = Just $ ticketDependencyCreated td
|
, ticketDepUpdated = Just $ ticketDependencyCreated td
|
||||||
, relationshipSummary = TextHtml $ ticketDependencySummary td
|
, ticketDepSummary = TextHtml $ ticketDependencySummary td
|
||||||
}
|
}
|
||||||
|
|
||||||
provideHtmlAndAP tdepAP $ redirectToPrettyJSON here
|
provideHtmlAndAP tdepAP $ redirectToPrettyJSON here
|
||||||
|
|
|
@ -40,8 +40,7 @@ module Web.ActivityPub
|
||||||
|
|
||||||
-- * Content objects
|
-- * Content objects
|
||||||
, Note (..)
|
, Note (..)
|
||||||
, RelationshipProperty (..)
|
, TicketDependency (..)
|
||||||
, Relationship (..)
|
|
||||||
, TextHtml (..)
|
, TextHtml (..)
|
||||||
, TextPandocMarkdown (..)
|
, TextPandocMarkdown (..)
|
||||||
, TicketLocal (..)
|
, TicketLocal (..)
|
||||||
|
@ -95,6 +94,7 @@ import Data.Bifunctor
|
||||||
import Data.Bitraversable (bitraverse)
|
import Data.Bitraversable (bitraverse)
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import Data.Foldable (for_)
|
import Data.Foldable (for_)
|
||||||
|
import Data.List
|
||||||
import Data.List.NonEmpty (NonEmpty (..), nonEmpty)
|
import Data.List.NonEmpty (NonEmpty (..), nonEmpty)
|
||||||
import Data.Proxy
|
import Data.Proxy
|
||||||
import Data.PEM
|
import Data.PEM
|
||||||
|
@ -556,7 +556,7 @@ instance ActivityPub Note where
|
||||||
<> "content" .= content
|
<> "content" .= content
|
||||||
<> "mediaType" .= ("text/html" :: Text)
|
<> "mediaType" .= ("text/html" :: Text)
|
||||||
|
|
||||||
data RelationshipProperty = RelDependsOn
|
data RelationshipProperty = RelDependsOn deriving Eq
|
||||||
|
|
||||||
instance FromJSON RelationshipProperty where
|
instance FromJSON RelationshipProperty where
|
||||||
parseJSON = withText "RelationshipProperty" parse
|
parseJSON = withText "RelationshipProperty" parse
|
||||||
|
@ -573,6 +573,7 @@ instance ToJSON RelationshipProperty where
|
||||||
|
|
||||||
data Relationship = Relationship
|
data Relationship = Relationship
|
||||||
{ relationshipId :: Maybe FedURI
|
{ relationshipId :: Maybe FedURI
|
||||||
|
, relationshipExtraTypes :: [Text]
|
||||||
, relationshipSubject :: FedURI
|
, relationshipSubject :: FedURI
|
||||||
, relationshipProperty :: Either RelationshipProperty Text
|
, relationshipProperty :: Either RelationshipProperty Text
|
||||||
, relationshipObject :: FedURI
|
, relationshipObject :: FedURI
|
||||||
|
@ -585,8 +586,8 @@ data Relationship = Relationship
|
||||||
instance ActivityPub Relationship where
|
instance ActivityPub Relationship where
|
||||||
jsonldContext _ = [as2Context, forgeContext]
|
jsonldContext _ = [as2Context, forgeContext]
|
||||||
parseObject o = do
|
parseObject o = do
|
||||||
typ <- o .: "type"
|
typs <- o .: "type"
|
||||||
unless (typ == ("Relationship" :: Text)) $
|
unless (("Relationship" :: Text) `elem` typs) $
|
||||||
fail "type isn't Relationship"
|
fail "type isn't Relationship"
|
||||||
|
|
||||||
(h, attributedTo) <- f2l <$> o .: "attributedTo"
|
(h, attributedTo) <- f2l <$> o .: "attributedTo"
|
||||||
|
@ -594,6 +595,7 @@ instance ActivityPub Relationship where
|
||||||
fmap (h,) $
|
fmap (h,) $
|
||||||
Relationship
|
Relationship
|
||||||
<$> o .:? "id"
|
<$> o .:? "id"
|
||||||
|
<*> pure (delete "Relationship" typs)
|
||||||
<*> o .: "subject"
|
<*> o .: "subject"
|
||||||
<*> o .:+ "relationship"
|
<*> o .:+ "relationship"
|
||||||
<*> o .: "object"
|
<*> o .: "object"
|
||||||
|
@ -603,18 +605,64 @@ instance ActivityPub Relationship where
|
||||||
<*> (TextHtml . sanitizeBalance <$> o .: "summary")
|
<*> (TextHtml . sanitizeBalance <$> o .: "summary")
|
||||||
|
|
||||||
toSeries host
|
toSeries host
|
||||||
(Relationship id_ subject property object attributedTo published
|
(Relationship id_ typs subject property object attributedTo published
|
||||||
updated summary)
|
updated summary)
|
||||||
= "id" .=? id_
|
= "id" .=? id_
|
||||||
<> "type" .= ("Relationship" :: Text)
|
<> "type" .= ("Relationship" : typs)
|
||||||
<> "subject" .= subject
|
<> "subject" .= subject
|
||||||
<> "relationship" .=+ property
|
<> "relationship" .=+ property
|
||||||
<> "object" .= object
|
<> "object" .= object
|
||||||
<> "attributedTo" .= l2f host attributedTo
|
<> "attributedTo" .= l2f host attributedTo
|
||||||
<> "published" .=? published
|
<> "published" .=? published
|
||||||
<> "updated" .=? updated
|
<> "updated" .=? updated
|
||||||
<> "summary" .= summary
|
<> "summary" .= summary
|
||||||
|
|
||||||
|
data TicketDependency = TicketDependency
|
||||||
|
{ ticketDepId :: Maybe FedURI
|
||||||
|
, ticketDepParent :: FedURI
|
||||||
|
, ticketDepChild :: FedURI
|
||||||
|
, ticketDepAttributedTo :: LocalURI
|
||||||
|
, ticketDepPublished :: Maybe UTCTime
|
||||||
|
, ticketDepUpdated :: Maybe UTCTime
|
||||||
|
, ticketDepSummary :: TextHtml
|
||||||
|
}
|
||||||
|
|
||||||
|
instance ActivityPub TicketDependency where
|
||||||
|
jsonldContext _ = [as2Context, forgeContext]
|
||||||
|
parseObject o = do
|
||||||
|
(h, rel) <- parseObject o
|
||||||
|
unless ("TicketDependency" `elem` relationshipExtraTypes rel) $
|
||||||
|
fail "type isn't TicketDependency"
|
||||||
|
|
||||||
|
unless (relationshipProperty rel == Left RelDependsOn) $
|
||||||
|
fail "relationship isn't dependsOn"
|
||||||
|
|
||||||
|
return (h, rel2td rel)
|
||||||
|
where
|
||||||
|
rel2td rel = TicketDependency
|
||||||
|
{ ticketDepId = relationshipId rel
|
||||||
|
, ticketDepParent = relationshipSubject rel
|
||||||
|
, ticketDepChild = relationshipObject rel
|
||||||
|
, ticketDepAttributedTo = relationshipAttributedTo rel
|
||||||
|
, ticketDepPublished = relationshipPublished rel
|
||||||
|
, ticketDepUpdated = relationshipUpdated rel
|
||||||
|
, ticketDepSummary = relationshipSummary rel
|
||||||
|
}
|
||||||
|
|
||||||
|
toSeries h = toSeries h . td2rel
|
||||||
|
where
|
||||||
|
td2rel td = Relationship
|
||||||
|
{ relationshipId = ticketDepId td
|
||||||
|
, relationshipExtraTypes = ["TicketDependency"]
|
||||||
|
, relationshipSubject = ticketDepParent td
|
||||||
|
, relationshipProperty = Left RelDependsOn
|
||||||
|
, relationshipObject = ticketDepChild td
|
||||||
|
, relationshipAttributedTo = ticketDepAttributedTo td
|
||||||
|
, relationshipPublished = ticketDepPublished td
|
||||||
|
, relationshipUpdated = ticketDepUpdated td
|
||||||
|
, relationshipSummary = ticketDepSummary td
|
||||||
|
}
|
||||||
|
|
||||||
newtype TextHtml = TextHtml
|
newtype TextHtml = TextHtml
|
||||||
{ unTextHtml :: Text
|
{ unTextHtml :: Text
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue