mirror of
https://code.sup39.dev/repos/Wqawg
synced 2025-01-16 07:15:10 +09:00
Move AP Ticket local URI fields into a dedicated TicketLocal type
This commit is contained in:
parent
e31c8c600b
commit
b69442b448
2 changed files with 77 additions and 39 deletions
|
@ -282,37 +282,45 @@ getTicketR shar proj num = do
|
||||||
TSNew -> wffNew filt
|
TSNew -> wffNew filt
|
||||||
TSTodo -> wffTodo filt
|
TSTodo -> wffTodo filt
|
||||||
TSClosed -> wffClosed filt
|
TSClosed -> wffClosed filt
|
||||||
|
hLocal <- getsYesod siteInstanceHost
|
||||||
encodeRouteLocal <- getEncodeRouteLocal
|
encodeRouteLocal <- getEncodeRouteLocal
|
||||||
encodeRouteHome <- getEncodeRouteHome
|
encodeRouteHome <- getEncodeRouteHome
|
||||||
let siblingUri =
|
let siblingUri =
|
||||||
encodeRouteHome . TicketR shar proj . ticketNumber . entityVal
|
encodeRouteHome . TicketR shar proj . ticketNumber . entityVal
|
||||||
ticketAP = AP.Ticket
|
ticketAP = AP.Ticket
|
||||||
|
{ AP.ticketLocal = Just
|
||||||
|
( hLocal
|
||||||
|
, AP.TicketLocal
|
||||||
{ AP.ticketId =
|
{ AP.ticketId =
|
||||||
Just $ encodeRouteLocal $ TicketR shar proj num
|
encodeRouteLocal $ TicketR shar proj num
|
||||||
|
, AP.ticketContext =
|
||||||
|
encodeRouteLocal $ ProjectR shar proj
|
||||||
|
, AP.ticketReplies =
|
||||||
|
encodeRouteLocal $ TicketDiscussionR shar proj num
|
||||||
|
, AP.ticketParticipants =
|
||||||
|
encodeRouteLocal $ TicketParticipantsR shar proj num
|
||||||
|
, AP.ticketTeam =
|
||||||
|
encodeRouteLocal $ TicketTeamR shar proj num
|
||||||
|
, AP.ticketEvents =
|
||||||
|
encodeRouteLocal $ TicketEventsR shar proj num
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
, AP.ticketAttributedTo =
|
, AP.ticketAttributedTo =
|
||||||
encodeRouteHome $ SharerR $ sharerIdent author
|
encodeRouteLocal $ SharerR $ sharerIdent author
|
||||||
, AP.ticketPublished = Just $ ticketCreated ticket
|
, AP.ticketPublished = Just $ ticketCreated ticket
|
||||||
, AP.ticketUpdated = Nothing
|
, AP.ticketUpdated = Nothing
|
||||||
, AP.ticketContext = encodeRouteLocal $ ProjectR shar proj
|
|
||||||
, AP.ticketName = Just $ "#" <> T.pack (show num)
|
, AP.ticketName = Just $ "#" <> T.pack (show num)
|
||||||
, AP.ticketSummary =
|
, AP.ticketSummary =
|
||||||
TextHtml $ TL.toStrict $ renderHtml $ toHtml $
|
TextHtml $ TL.toStrict $ renderHtml $ toHtml $
|
||||||
ticketTitle ticket
|
ticketTitle ticket
|
||||||
, AP.ticketContent = TextHtml $ ticketDescription ticket
|
, AP.ticketContent = TextHtml $ ticketDescription ticket
|
||||||
, AP.ticketSource = TextPandocMarkdown $ ticketSource ticket
|
, AP.ticketSource = TextPandocMarkdown $ ticketSource ticket
|
||||||
, AP.ticketReplies =
|
|
||||||
Just $ encodeRouteLocal $ TicketDiscussionR shar proj num
|
|
||||||
, AP.ticketAssignedTo =
|
, AP.ticketAssignedTo =
|
||||||
encodeRouteHome . SharerR . sharerIdent . fst <$> massignee
|
encodeRouteHome . SharerR . sharerIdent . fst <$> massignee
|
||||||
, AP.ticketIsResolved = ticketStatus ticket == TSClosed
|
, AP.ticketIsResolved = ticketStatus ticket == TSClosed
|
||||||
, AP.ticketParticipants =
|
|
||||||
Just $ encodeRouteLocal $ TicketParticipantsR shar proj num
|
|
||||||
, AP.ticketTeam =
|
|
||||||
Just $ encodeRouteLocal $ TicketTeamR shar proj num
|
|
||||||
, AP.ticketDependsOn = map siblingUri deps
|
, AP.ticketDependsOn = map siblingUri deps
|
||||||
, AP.ticketDependedBy = map siblingUri rdeps
|
, AP.ticketDependedBy = map siblingUri rdeps
|
||||||
, AP.ticketEvents =
|
|
||||||
Just $ encodeRouteLocal $ TicketEventsR shar proj num
|
|
||||||
}
|
}
|
||||||
provideHtmlAndAP ticketAP $(widgetFile "ticket/one")
|
provideHtmlAndAP ticketAP $(widgetFile "ticket/one")
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ module Web.ActivityPub
|
||||||
, Note (..)
|
, Note (..)
|
||||||
, TextHtml (..)
|
, TextHtml (..)
|
||||||
, TextPandocMarkdown (..)
|
, TextPandocMarkdown (..)
|
||||||
|
, TicketLocal (..)
|
||||||
, Ticket (..)
|
, Ticket (..)
|
||||||
|
|
||||||
-- * Activity
|
-- * Activity
|
||||||
|
@ -115,7 +116,7 @@ import qualified Data.ByteString as B
|
||||||
import qualified Data.ByteString.Base64 as B64
|
import qualified Data.ByteString.Base64 as B64
|
||||||
import qualified Data.ByteString.Char8 as BC
|
import qualified Data.ByteString.Char8 as BC
|
||||||
import qualified Data.ByteString.Lazy as BL
|
import qualified Data.ByteString.Lazy as BL
|
||||||
import qualified Data.HashMap.Strict as M (lookup)
|
import qualified Data.HashMap.Strict as M
|
||||||
import qualified Data.Text as T (pack, unpack)
|
import qualified Data.Text as T (pack, unpack)
|
||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
import qualified Network.HTTP.Signature as S
|
import qualified Network.HTTP.Signature as S
|
||||||
|
@ -615,24 +616,63 @@ newtype TextPandocMarkdown = TextPandocMarkdown
|
||||||
}
|
}
|
||||||
deriving (FromJSON, ToJSON)
|
deriving (FromJSON, ToJSON)
|
||||||
|
|
||||||
|
data TicketLocal = TicketLocal
|
||||||
|
{ ticketId :: LocalURI
|
||||||
|
, ticketContext :: LocalURI
|
||||||
|
, ticketReplies :: LocalURI
|
||||||
|
, ticketParticipants :: LocalURI
|
||||||
|
, ticketTeam :: LocalURI
|
||||||
|
, ticketEvents :: LocalURI
|
||||||
|
}
|
||||||
|
|
||||||
|
parseTicketLocal :: Object -> Parser (Maybe (Text, TicketLocal))
|
||||||
|
parseTicketLocal o = do
|
||||||
|
mid <- fmap f2l <$> o .:? "id"
|
||||||
|
case mid of
|
||||||
|
Nothing -> do
|
||||||
|
verifyNothing "context"
|
||||||
|
verifyNothing "replies"
|
||||||
|
verifyNothing $ frg <> "participants"
|
||||||
|
verifyNothing $ frg <> "team"
|
||||||
|
verifyNothing $ frg <> "events"
|
||||||
|
return Nothing
|
||||||
|
Just (h, id_) ->
|
||||||
|
fmap (Just . (h,)) $
|
||||||
|
TicketLocal
|
||||||
|
<$> pure id_
|
||||||
|
<*> withHost h (f2l <$> o .: "context")
|
||||||
|
<*> withHost h (f2l <$> o .: "replies")
|
||||||
|
<*> withHost h (f2l <$> o .: (frg <> "participants"))
|
||||||
|
<*> withHost h (f2l <$> o .: (frg <> "team"))
|
||||||
|
<*> withHost h (f2l <$> o .: (frg <> "events"))
|
||||||
|
where
|
||||||
|
verifyNothing t =
|
||||||
|
if t `M.member` o
|
||||||
|
then fail $ T.unpack t ++ " field found, expected none"
|
||||||
|
else return ()
|
||||||
|
|
||||||
|
encodeTicketLocal :: Text -> TicketLocal -> Series
|
||||||
|
encodeTicketLocal h (TicketLocal id_ context replies participants team events)
|
||||||
|
= "id" .= l2f h id_
|
||||||
|
<> "context" .= l2f h context
|
||||||
|
<> "replies" .= l2f h replies
|
||||||
|
<> (frg <> "participants") .= l2f h participants
|
||||||
|
<> (frg <> "team") .= l2f h team
|
||||||
|
<> (frg <> "events") .= l2f h events
|
||||||
|
|
||||||
data Ticket = Ticket
|
data Ticket = Ticket
|
||||||
{ ticketId :: Maybe LocalURI
|
{ ticketLocal :: Maybe (Text, TicketLocal)
|
||||||
, ticketAttributedTo :: FedURI
|
, ticketAttributedTo :: LocalURI
|
||||||
, ticketPublished :: Maybe UTCTime
|
, ticketPublished :: Maybe UTCTime
|
||||||
, ticketUpdated :: Maybe UTCTime
|
, ticketUpdated :: Maybe UTCTime
|
||||||
, ticketContext :: LocalURI
|
|
||||||
, ticketName :: Maybe Text
|
, ticketName :: Maybe Text
|
||||||
, ticketSummary :: TextHtml
|
, ticketSummary :: TextHtml
|
||||||
, ticketContent :: TextHtml
|
, ticketContent :: TextHtml
|
||||||
, ticketSource :: TextPandocMarkdown
|
, ticketSource :: TextPandocMarkdown
|
||||||
, ticketReplies :: Maybe LocalURI
|
|
||||||
, ticketAssignedTo :: Maybe FedURI
|
, ticketAssignedTo :: Maybe FedURI
|
||||||
, ticketIsResolved :: Bool
|
, ticketIsResolved :: Bool
|
||||||
, ticketParticipants :: Maybe LocalURI
|
|
||||||
, ticketTeam :: Maybe LocalURI
|
|
||||||
, ticketDependsOn :: [FedURI]
|
, ticketDependsOn :: [FedURI]
|
||||||
, ticketDependedBy :: [FedURI]
|
, ticketDependedBy :: [FedURI]
|
||||||
, ticketEvents :: Maybe LocalURI
|
|
||||||
}
|
}
|
||||||
|
|
||||||
instance ActivityPub Ticket where
|
instance ActivityPub Ticket where
|
||||||
|
@ -651,38 +691,32 @@ instance ActivityPub Ticket where
|
||||||
unless (sourceType == ("text/markdown; variant=Pandoc" :: Text)) $
|
unless (sourceType == ("text/markdown; variant=Pandoc" :: Text)) $
|
||||||
fail "source mediaType isn't Pandoc Markdown"
|
fail "source mediaType isn't Pandoc Markdown"
|
||||||
|
|
||||||
(h, context) <- f2l <$> o .: "context"
|
(h, attributedTo) <- f2l <$> o .: "attributedTo"
|
||||||
|
|
||||||
fmap (h,) $
|
fmap (h,) $
|
||||||
Ticket
|
Ticket
|
||||||
<$> withHostMaybe h (fmap f2l <$> o .:? "id")
|
<$> parseTicketLocal o
|
||||||
<*> o .: "attributedTo"
|
<*> pure attributedTo
|
||||||
<*> o .:? "published"
|
<*> o .:? "published"
|
||||||
<*> o .:? "updated"
|
<*> o .:? "updated"
|
||||||
<*> pure context
|
|
||||||
<*> o .:? "name"
|
<*> o .:? "name"
|
||||||
<*> (TextHtml . sanitizeBalance <$> o .: "summary")
|
<*> (TextHtml . sanitizeBalance <$> o .: "summary")
|
||||||
<*> (TextHtml . sanitizeBalance <$> o .: "content")
|
<*> (TextHtml . sanitizeBalance <$> o .: "content")
|
||||||
<*> source .: "content"
|
<*> source .: "content"
|
||||||
<*> withHostMaybe h (fmap f2l <$> o .:? "replies")
|
|
||||||
<*> o .:? (frg <> "assignedTo")
|
<*> o .:? (frg <> "assignedTo")
|
||||||
<*> o .: (frg <> "isResolved")
|
<*> o .: (frg <> "isResolved")
|
||||||
<*> withHostMaybe h (fmap f2l <$> o .:? (frg <> "participants"))
|
|
||||||
<*> withHostMaybe h (fmap f2l <$> o .:? (frg <> "team"))
|
|
||||||
<*> o .:? (frg <> "dependsOn") .!= []
|
<*> o .:? (frg <> "dependsOn") .!= []
|
||||||
<*> o .:? (frg <> "dependedBy") .!= []
|
<*> o .:? (frg <> "dependedBy") .!= []
|
||||||
<*> withHostMaybe h (fmap f2l <$> o .:? (frg <> "events"))
|
|
||||||
|
|
||||||
toSeries host
|
toSeries host
|
||||||
(Ticket id_ attributedTo published updated context name summary content
|
(Ticket local attributedTo published updated name summary content
|
||||||
source replies assignedTo isResolved participants team
|
source assignedTo isResolved dependsOn dependedBy)
|
||||||
dependsOn dependedBy events)
|
|
||||||
= "type" .= ("Ticket" :: Text)
|
= maybe mempty (uncurry encodeTicketLocal) local
|
||||||
<> "id" .=? (l2f host <$> id_)
|
<> "type" .= ("Ticket" :: Text)
|
||||||
<> "attributedTo" .= attributedTo
|
<> "attributedTo" .= l2f host attributedTo
|
||||||
<> "published" .=? published
|
<> "published" .=? published
|
||||||
<> "updated" .=? updated
|
<> "updated" .=? updated
|
||||||
<> "context" .= l2f host context
|
|
||||||
<> "name" .=? name
|
<> "name" .=? name
|
||||||
<> "summary" .= summary
|
<> "summary" .= summary
|
||||||
<> "content" .= content
|
<> "content" .= content
|
||||||
|
@ -691,14 +725,10 @@ instance ActivityPub Ticket where
|
||||||
[ "content" .= source
|
[ "content" .= source
|
||||||
, "mediaType" .= ("text/markdown; variant=Pandoc" :: Text)
|
, "mediaType" .= ("text/markdown; variant=Pandoc" :: Text)
|
||||||
]
|
]
|
||||||
<> "replies" .=? (l2f host <$> replies)
|
|
||||||
<> (frg <> "assignedTo") .=? assignedTo
|
<> (frg <> "assignedTo") .=? assignedTo
|
||||||
<> (frg <> "isResolved") .= isResolved
|
<> (frg <> "isResolved") .= isResolved
|
||||||
<> (frg <> "participants") .=? (l2f host <$> participants)
|
|
||||||
<> (frg <> "team") .=? (l2f host <$> team)
|
|
||||||
<> (frg <> "dependsOn") .=% dependsOn
|
<> (frg <> "dependsOn") .=% dependsOn
|
||||||
<> (frg <> "dependedBy") .=% dependedBy
|
<> (frg <> "dependedBy") .=% dependedBy
|
||||||
<> (frg <> "events") .=? (l2f host <$> events)
|
|
||||||
|
|
||||||
data Accept = Accept
|
data Accept = Accept
|
||||||
{ acceptObject :: FedURI
|
{ acceptObject :: FedURI
|
||||||
|
|
Loading…
Reference in a new issue