{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE TemplateHaskell #-}
module Matterhorn.Types.Posts
( ClientMessage
, newClientMessage
, cmDate
, cmType
, cmText
, ClientMessageType(..)
, Attachment
, mkAttachment
, attachmentName
, attachmentFileId
, attachmentURL
, ClientPostType(..)
, ClientPost
, toClientPost
, cpUserOverride
, cpMarkdownSource
, cpUser
, cpText
, cpType
, cpReactions
, cpPending
, cpOriginalPost
, cpFromWebhook
, cpInReplyToPost
, cpDate
, cpChannelId
, cpAttachments
, cpDeleted
, cpPostId
, cpPinned
, unEmote
, postIsLeave
, postIsJoin
, postIsTopicChange
, postIsEmote
)
where
import Prelude ()
import Matterhorn.Prelude
import qualified Data.Foldable as F
import qualified Data.Map.Strict as Map
import qualified Data.Sequence as Seq
import qualified Data.Text as T
import qualified Data.Set as S
import Data.Time.Clock ( getCurrentTime )
import Lens.Micro.Platform ( makeLenses )
import Network.Mattermost.Lenses
import Network.Mattermost.Types
import Matterhorn.Types.Common
import Matterhorn.Types.RichText ( Blocks(..), Block(..)
, TeamBaseURL, Inlines(..), Inline(..)
, ListType(..), ListSpacing(..)
, parseMarkdown, singleB, singleI
)
data ClientMessage = ClientMessage
{ ClientMessage -> Text
_cmText :: Text
, ClientMessage -> ServerTime
_cmDate :: ServerTime
, ClientMessage -> ClientMessageType
_cmType :: ClientMessageType
} deriving (Int -> ClientMessage -> ShowS
[ClientMessage] -> ShowS
ClientMessage -> String
(Int -> ClientMessage -> ShowS)
-> (ClientMessage -> String)
-> ([ClientMessage] -> ShowS)
-> Show ClientMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClientMessage -> ShowS
showsPrec :: Int -> ClientMessage -> ShowS
$cshow :: ClientMessage -> String
show :: ClientMessage -> String
$cshowList :: [ClientMessage] -> ShowS
showList :: [ClientMessage] -> ShowS
Show)
newClientMessage :: (MonadIO m) => ClientMessageType -> Text -> m ClientMessage
newClientMessage :: forall (m :: * -> *).
MonadIO m =>
ClientMessageType -> Text -> m ClientMessage
newClientMessage ClientMessageType
ty Text
msg = do
UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
ClientMessage -> m ClientMessage
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> ServerTime -> ClientMessageType -> ClientMessage
ClientMessage Text
msg (UTCTime -> ServerTime
ServerTime UTCTime
now) ClientMessageType
ty)
data ClientMessageType =
Informative
| Error
| DateTransition
| NewMessagesTransition
| UnknownGapBefore
| UnknownGapAfter
deriving (Int -> ClientMessageType -> ShowS
[ClientMessageType] -> ShowS
ClientMessageType -> String
(Int -> ClientMessageType -> ShowS)
-> (ClientMessageType -> String)
-> ([ClientMessageType] -> ShowS)
-> Show ClientMessageType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClientMessageType -> ShowS
showsPrec :: Int -> ClientMessageType -> ShowS
$cshow :: ClientMessageType -> String
show :: ClientMessageType -> String
$cshowList :: [ClientMessageType] -> ShowS
showList :: [ClientMessageType] -> ShowS
Show, ClientMessageType -> ClientMessageType -> Bool
(ClientMessageType -> ClientMessageType -> Bool)
-> (ClientMessageType -> ClientMessageType -> Bool)
-> Eq ClientMessageType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClientMessageType -> ClientMessageType -> Bool
== :: ClientMessageType -> ClientMessageType -> Bool
$c/= :: ClientMessageType -> ClientMessageType -> Bool
/= :: ClientMessageType -> ClientMessageType -> Bool
Eq)
makeLenses ''ClientMessage
data ClientPost = ClientPost
{ ClientPost -> Blocks
_cpText :: Blocks
, ClientPost -> Text
_cpMarkdownSource :: Text
, ClientPost -> Maybe UserId
_cpUser :: Maybe UserId
, ClientPost -> Maybe Text
_cpUserOverride :: Maybe Text
, ClientPost -> ServerTime
_cpDate :: ServerTime
, ClientPost -> ClientPostType
_cpType :: ClientPostType
, ClientPost -> Bool
_cpPending :: Bool
, ClientPost -> Bool
_cpDeleted :: Bool
, ClientPost -> Seq Attachment
_cpAttachments :: Seq Attachment
, ClientPost -> Maybe PostId
_cpInReplyToPost :: Maybe PostId
, ClientPost -> PostId
_cpPostId :: PostId
, ClientPost -> ChannelId
_cpChannelId :: ChannelId
, ClientPost -> Map Text (Set UserId)
_cpReactions :: Map.Map Text (S.Set UserId)
, ClientPost -> Post
_cpOriginalPost :: Post
, ClientPost -> Bool
_cpFromWebhook :: Bool
, ClientPost -> Bool
_cpPinned :: Bool
} deriving (Int -> ClientPost -> ShowS
[ClientPost] -> ShowS
ClientPost -> String
(Int -> ClientPost -> ShowS)
-> (ClientPost -> String)
-> ([ClientPost] -> ShowS)
-> Show ClientPost
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClientPost -> ShowS
showsPrec :: Int -> ClientPost -> ShowS
$cshow :: ClientPost -> String
show :: ClientPost -> String
$cshowList :: [ClientPost] -> ShowS
showList :: [ClientPost] -> ShowS
Show)
data Attachment = Attachment
{ Attachment -> Text
_attachmentName :: Text
, Attachment -> Text
_attachmentURL :: Text
, Attachment -> FileId
_attachmentFileId :: FileId
} deriving (Attachment -> Attachment -> Bool
(Attachment -> Attachment -> Bool)
-> (Attachment -> Attachment -> Bool) -> Eq Attachment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Attachment -> Attachment -> Bool
== :: Attachment -> Attachment -> Bool
$c/= :: Attachment -> Attachment -> Bool
/= :: Attachment -> Attachment -> Bool
Eq, Int -> Attachment -> ShowS
[Attachment] -> ShowS
Attachment -> String
(Int -> Attachment -> ShowS)
-> (Attachment -> String)
-> ([Attachment] -> ShowS)
-> Show Attachment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Attachment -> ShowS
showsPrec :: Int -> Attachment -> ShowS
$cshow :: Attachment -> String
show :: Attachment -> String
$cshowList :: [Attachment] -> ShowS
showList :: [Attachment] -> ShowS
Show)
mkAttachment :: Text -> Text -> FileId -> Attachment
mkAttachment :: Text -> Text -> FileId -> Attachment
mkAttachment = Text -> Text -> FileId -> Attachment
Attachment
data ClientPostType =
NormalPost
| Emote
| Join
| Leave
| TopicChange
deriving (ClientPostType -> ClientPostType -> Bool
(ClientPostType -> ClientPostType -> Bool)
-> (ClientPostType -> ClientPostType -> Bool) -> Eq ClientPostType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClientPostType -> ClientPostType -> Bool
== :: ClientPostType -> ClientPostType -> Bool
$c/= :: ClientPostType -> ClientPostType -> Bool
/= :: ClientPostType -> ClientPostType -> Bool
Eq, Int -> ClientPostType -> ShowS
[ClientPostType] -> ShowS
ClientPostType -> String
(Int -> ClientPostType -> ShowS)
-> (ClientPostType -> String)
-> ([ClientPostType] -> ShowS)
-> Show ClientPostType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClientPostType -> ShowS
showsPrec :: Int -> ClientPostType -> ShowS
$cshow :: ClientPostType -> String
show :: ClientPostType -> String
$cshowList :: [ClientPostType] -> ShowS
showList :: [ClientPostType] -> ShowS
Show)
postClientPostType :: Post -> ClientPostType
postClientPostType :: Post -> ClientPostType
postClientPostType Post
cp =
if | Post -> Bool
postIsEmote Post
cp -> ClientPostType
Emote
| Post -> Bool
postIsJoin Post
cp -> ClientPostType
Join
| Post -> Bool
postIsLeave Post
cp -> ClientPostType
Leave
| Post -> Bool
postIsTopicChange Post
cp -> ClientPostType
TopicChange
| Bool
otherwise -> ClientPostType
NormalPost
postIsTopicChange :: Post -> Bool
postIsTopicChange :: Post -> Bool
postIsTopicChange Post
p = Post -> PostType
postType Post
p PostType -> PostType -> Bool
forall a. Eq a => a -> a -> Bool
== PostType
PostTypeHeaderChange
postIsEmote :: Post -> Bool
postIsEmote :: Post -> Bool
postIsEmote Post
p =
[Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and [ Post
pPost -> Getting (Maybe Text) Post (Maybe Text) -> Maybe Text
forall s a. s -> Getting a s a -> a
^.(PostProps -> Const (Maybe Text) PostProps)
-> Post -> Const (Maybe Text) Post
Lens' Post PostProps
postPropsL((PostProps -> Const (Maybe Text) PostProps)
-> Post -> Const (Maybe Text) Post)
-> ((Maybe Text -> Const (Maybe Text) (Maybe Text))
-> PostProps -> Const (Maybe Text) PostProps)
-> Getting (Maybe Text) Post (Maybe Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe Text -> Const (Maybe Text) (Maybe Text))
-> PostProps -> Const (Maybe Text) PostProps
Lens' PostProps (Maybe Text)
postPropsOverrideIconUrlL Maybe Text -> Maybe Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Maybe Text
forall a. a -> Maybe a
Just (Text
""::Text)
, (Text
"*" Text -> Text -> Bool
`T.isPrefixOf` (UserText -> Text
sanitizeUserText (UserText -> Text) -> UserText -> Text
forall a b. (a -> b) -> a -> b
$ Post -> UserText
postMessage Post
p))
, (Text
"*" Text -> Text -> Bool
`T.isSuffixOf` (UserText -> Text
sanitizeUserText (UserText -> Text) -> UserText -> Text
forall a b. (a -> b) -> a -> b
$ Post -> UserText
postMessage Post
p))
]
postIsJoin :: Post -> Bool
postIsJoin :: Post -> Bool
postIsJoin Post
p =
Post
pPost -> Getting PostType Post PostType -> PostType
forall s a. s -> Getting a s a -> a
^.Getting PostType Post PostType
Lens' Post PostType
postTypeL PostType -> PostType -> Bool
forall a. Eq a => a -> a -> Bool
== PostType
PostTypeJoinChannel
postIsLeave :: Post -> Bool
postIsLeave :: Post -> Bool
postIsLeave Post
p =
Post
pPost -> Getting PostType Post PostType -> PostType
forall s a. s -> Getting a s a -> a
^.Getting PostType Post PostType
Lens' Post PostType
postTypeL PostType -> PostType -> Bool
forall a. Eq a => a -> a -> Bool
== PostType
PostTypeLeaveChannel
unEmote :: ClientPostType -> Text -> Text
unEmote :: ClientPostType -> Text -> Text
unEmote ClientPostType
Emote Text
t = if Text
"*" Text -> Text -> Bool
`T.isPrefixOf` Text
t Bool -> Bool -> Bool
&& Text
"*" Text -> Text -> Bool
`T.isSuffixOf` Text
t
then HasCallStack => Text -> Text
Text -> Text
T.init (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ HasCallStack => Text -> Text
Text -> Text
T.tail Text
t
else Text
t
unEmote ClientPostType
_ Text
t = Text
t
attachmentFromFileInfo :: T.Text -> FileInfo -> Attachment
attachmentFromFileInfo :: Text -> FileInfo -> Attachment
attachmentFromFileInfo Text
hostname FileInfo
info =
let scheme :: Text
scheme = Text
"https://"
attUrl :: Text
attUrl = Text
scheme Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
hostname Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> FileId -> Text
urlForFile FileId
fId
fId :: FileId
fId = FileInfo -> FileId
fileInfoId FileInfo
info
in Text -> Text -> FileId -> Attachment
mkAttachment (FileInfo -> Text
fileInfoName FileInfo
info) Text
attUrl FileId
fId
toClientPost :: T.Text -> Maybe TeamBaseURL -> Post -> Maybe PostId -> ClientPost
toClientPost :: Text -> Maybe TeamBaseURL -> Post -> Maybe PostId -> ClientPost
toClientPost Text
hostname Maybe TeamBaseURL
baseUrl Post
p Maybe PostId
parentId =
let src :: Text
src = ClientPostType -> Text -> Text
unEmote (Post -> ClientPostType
postClientPostType Post
p) (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ UserText -> Text
sanitizeUserText (UserText -> Text) -> UserText -> Text
forall a b. (a -> b) -> a -> b
$ Post -> UserText
postMessage Post
p
in ClientPost { _cpText :: Blocks
_cpText = Maybe TeamBaseURL -> Text -> Blocks
parseMarkdown Maybe TeamBaseURL
baseUrl Text
src Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> Post -> Blocks
getAttachmentText Post
p
, _cpMarkdownSource :: Text
_cpMarkdownSource = Text
src
, _cpUser :: Maybe UserId
_cpUser = Post -> Maybe UserId
postUserId Post
p
, _cpUserOverride :: Maybe Text
_cpUserOverride = Post
pPost -> Getting (Maybe Text) Post (Maybe Text) -> Maybe Text
forall s a. s -> Getting a s a -> a
^.(PostProps -> Const (Maybe Text) PostProps)
-> Post -> Const (Maybe Text) Post
Lens' Post PostProps
postPropsL((PostProps -> Const (Maybe Text) PostProps)
-> Post -> Const (Maybe Text) Post)
-> ((Maybe Text -> Const (Maybe Text) (Maybe Text))
-> PostProps -> Const (Maybe Text) PostProps)
-> Getting (Maybe Text) Post (Maybe Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe Text -> Const (Maybe Text) (Maybe Text))
-> PostProps -> Const (Maybe Text) PostProps
Lens' PostProps (Maybe Text)
postPropsOverrideUsernameL
, _cpDate :: ServerTime
_cpDate = Post -> ServerTime
postCreateAt Post
p
, _cpType :: ClientPostType
_cpType = Post -> ClientPostType
postClientPostType Post
p
, _cpPending :: Bool
_cpPending = Bool
False
, _cpDeleted :: Bool
_cpDeleted = Bool
False
, _cpPinned :: Bool
_cpPinned = Bool -> Maybe Bool -> Bool
forall a. a -> Maybe a -> a
fromMaybe Bool
False (Maybe Bool -> Bool) -> Maybe Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Post -> Maybe Bool
postPinned Post
p
, _cpAttachments :: Seq Attachment
_cpAttachments = Text -> FileInfo -> Attachment
attachmentFromFileInfo Text
hostname (FileInfo -> Attachment) -> Seq FileInfo -> Seq Attachment
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PostMetadata -> Seq FileInfo
postMetadataFiles (Post -> PostMetadata
postMetadata Post
p)
, _cpInReplyToPost :: Maybe PostId
_cpInReplyToPost = Maybe PostId
parentId
, _cpPostId :: PostId
_cpPostId = Post
pPost -> Getting PostId Post PostId -> PostId
forall s a. s -> Getting a s a -> a
^.Getting PostId Post PostId
Lens' Post PostId
postIdL
, _cpChannelId :: ChannelId
_cpChannelId = Post
pPost -> Getting ChannelId Post ChannelId -> ChannelId
forall s a. s -> Getting a s a -> a
^.Getting ChannelId Post ChannelId
Lens' Post ChannelId
postChannelIdL
, _cpReactions :: Map Text (Set UserId)
_cpReactions = Seq Reaction -> Map Text (Set UserId)
mkReactionMap (Seq Reaction -> Map Text (Set UserId))
-> Seq Reaction -> Map Text (Set UserId)
forall a b. (a -> b) -> a -> b
$ PostMetadata -> Seq Reaction
postMetadataReactions (Post -> PostMetadata
postMetadata Post
p)
, _cpOriginalPost :: Post
_cpOriginalPost = Post
p
, _cpFromWebhook :: Bool
_cpFromWebhook = Bool -> Maybe Bool -> Bool
forall a. a -> Maybe a -> a
fromMaybe Bool
False (Maybe Bool -> Bool) -> Maybe Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Post
pPost -> Getting (Maybe Bool) Post (Maybe Bool) -> Maybe Bool
forall s a. s -> Getting a s a -> a
^.(PostProps -> Const (Maybe Bool) PostProps)
-> Post -> Const (Maybe Bool) Post
Lens' Post PostProps
postPropsL((PostProps -> Const (Maybe Bool) PostProps)
-> Post -> Const (Maybe Bool) Post)
-> ((Maybe Bool -> Const (Maybe Bool) (Maybe Bool))
-> PostProps -> Const (Maybe Bool) PostProps)
-> Getting (Maybe Bool) Post (Maybe Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe Bool -> Const (Maybe Bool) (Maybe Bool))
-> PostProps -> Const (Maybe Bool) PostProps
Lens' PostProps (Maybe Bool)
postPropsFromWebhookL
}
mkReactionMap :: Seq Reaction -> Map.Map T.Text (S.Set UserId)
mkReactionMap :: Seq Reaction -> Map Text (Set UserId)
mkReactionMap Seq Reaction
rs =
let inserter :: Reaction -> Map Text (Set UserId) -> Map Text (Set UserId)
inserter Reaction
r Map Text (Set UserId)
m = (Set UserId -> Set UserId -> Set UserId)
-> Text
-> Set UserId
-> Map Text (Set UserId)
-> Map Text (Set UserId)
forall k a. Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
Map.insertWith Set UserId -> Set UserId -> Set UserId
forall a. Ord a => Set a -> Set a -> Set a
S.union (Reaction -> Text
reactionEmojiName Reaction
r) (UserId -> Set UserId
forall a. a -> Set a
S.singleton (UserId -> Set UserId) -> UserId -> Set UserId
forall a b. (a -> b) -> a -> b
$ Reaction -> UserId
reactionUserId Reaction
r) Map Text (Set UserId)
m
in (Reaction -> Map Text (Set UserId) -> Map Text (Set UserId))
-> Map Text (Set UserId) -> Seq Reaction -> Map Text (Set UserId)
forall a b. (a -> b -> b) -> b -> Seq a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr Reaction -> Map Text (Set UserId) -> Map Text (Set UserId)
inserter Map Text (Set UserId)
forall a. Monoid a => a
mempty Seq Reaction
rs
getAttachmentText :: Post -> Blocks
getAttachmentText :: Post -> Blocks
getAttachmentText Post
p =
case Post
pPost
-> Getting
(Maybe (Seq PostPropAttachment))
Post
(Maybe (Seq PostPropAttachment))
-> Maybe (Seq PostPropAttachment)
forall s a. s -> Getting a s a -> a
^.(PostProps -> Const (Maybe (Seq PostPropAttachment)) PostProps)
-> Post -> Const (Maybe (Seq PostPropAttachment)) Post
Lens' Post PostProps
postPropsL((PostProps -> Const (Maybe (Seq PostPropAttachment)) PostProps)
-> Post -> Const (Maybe (Seq PostPropAttachment)) Post)
-> ((Maybe (Seq PostPropAttachment)
-> Const
(Maybe (Seq PostPropAttachment)) (Maybe (Seq PostPropAttachment)))
-> PostProps -> Const (Maybe (Seq PostPropAttachment)) PostProps)
-> Getting
(Maybe (Seq PostPropAttachment))
Post
(Maybe (Seq PostPropAttachment))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe (Seq PostPropAttachment)
-> Const
(Maybe (Seq PostPropAttachment)) (Maybe (Seq PostPropAttachment)))
-> PostProps -> Const (Maybe (Seq PostPropAttachment)) PostProps
Lens' PostProps (Maybe (Seq PostPropAttachment))
postPropsAttachmentsL of
Maybe (Seq PostPropAttachment)
Nothing -> Blocks
forall a. Monoid a => a
mempty
Just Seq PostPropAttachment
attachments ->
Seq Block -> Blocks
Blocks (Seq Block -> Blocks) -> Seq Block -> Blocks
forall a b. (a -> b) -> a -> b
$ (PostPropAttachment -> Block)
-> Seq PostPropAttachment -> Seq Block
forall a b. (a -> b) -> Seq a -> Seq b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Blocks -> Block
Blockquote (Blocks -> Block)
-> (PostPropAttachment -> Blocks) -> PostPropAttachment -> Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PostPropAttachment -> Blocks
render) Seq PostPropAttachment
attachments
where render :: PostPropAttachment -> Blocks
render PostPropAttachment
att = Maybe TeamBaseURL -> Text -> Blocks
parseMarkdown Maybe TeamBaseURL
forall a. Maybe a
Nothing (PostPropAttachment
attPostPropAttachment -> Getting Text PostPropAttachment Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text PostPropAttachment Text
Lens' PostPropAttachment Text
ppaTextL) Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<>
Maybe TeamBaseURL -> Text -> Blocks
parseMarkdown Maybe TeamBaseURL
forall a. Maybe a
Nothing (PostPropAttachment
attPostPropAttachment -> Getting Text PostPropAttachment Text -> Text
forall s a. s -> Getting a s a -> a
^.Getting Text PostPropAttachment Text
Lens' PostPropAttachment Text
ppaFallbackL) Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<>
Seq PostPropAttachmentField -> Blocks
renderAttFields (PostPropAttachment
attPostPropAttachment
-> Getting
(Seq PostPropAttachmentField)
PostPropAttachment
(Seq PostPropAttachmentField)
-> Seq PostPropAttachmentField
forall s a. s -> Getting a s a -> a
^.Getting
(Seq PostPropAttachmentField)
PostPropAttachment
(Seq PostPropAttachmentField)
Lens' PostPropAttachment (Seq PostPropAttachmentField)
ppaFieldsL)
renderAttFields :: Seq PostPropAttachmentField -> Blocks
renderAttFields :: Seq PostPropAttachmentField -> Blocks
renderAttFields Seq PostPropAttachmentField
fs = Block -> Blocks
singleB (Block -> Blocks) -> Block -> Blocks
forall a b. (a -> b) -> a -> b
$
ListType -> ListSpacing -> Seq Blocks -> Block
List (Char -> ListType
BulletList Char
'*') ListSpacing
LooseList (Seq Blocks -> Block) -> Seq Blocks -> Block
forall a b. (a -> b) -> a -> b
$
(PostPropAttachmentField -> Blocks)
-> Seq PostPropAttachmentField -> Seq Blocks
forall a b. (a -> b) -> Seq a -> Seq b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PostPropAttachmentField -> Blocks
renderAttFieldItem Seq PostPropAttachmentField
fs
renderAttFieldItem :: PostPropAttachmentField -> Blocks
renderAttFieldItem :: PostPropAttachmentField -> Blocks
renderAttFieldItem PostPropAttachmentField
f = Block -> Blocks
singleB (Block -> Blocks) -> Block -> Blocks
forall a b. (a -> b) -> a -> b
$ Inlines -> Block
Para (Inlines -> Block) -> Inlines -> Block
forall a b. (a -> b) -> a -> b
$ PostPropAttachmentField -> Inlines
renderAttFieldItemContent PostPropAttachmentField
f
renderAttFieldItemContent :: PostPropAttachmentField -> Inlines
renderAttFieldItemContent :: PostPropAttachmentField -> Inlines
renderAttFieldItemContent PostPropAttachmentField
f = Seq Inline -> Inlines
Inlines (Seq Inline -> Inlines) -> Seq Inline -> Inlines
forall a b. (a -> b) -> a -> b
$ [Inline] -> Seq Inline
forall a. [a] -> Seq a
Seq.fromList ([Inline] -> Seq Inline) -> [Inline] -> Seq Inline
forall a b. (a -> b) -> a -> b
$
PostPropAttachmentField -> [Inline]
renderAttFieldItemName PostPropAttachmentField
f [Inline] -> [Inline] -> [Inline]
forall a. Semigroup a => a -> a -> a
<>
[Text -> Inline
EText (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ PostPropAttachmentField -> Text
ppafValue PostPropAttachmentField
f]
renderAttFieldItemName :: PostPropAttachmentField -> [Inline]
renderAttFieldItemName :: PostPropAttachmentField -> [Inline]
renderAttFieldItemName PostPropAttachmentField
f =
if PostPropAttachmentField -> Text
ppafTitle PostPropAttachmentField
f Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
T.empty
then []
else [Inlines -> Inline
EStrong (Inlines -> Inline) -> Inlines -> Inline
forall a b. (a -> b) -> a -> b
$ Inline -> Inlines
singleI (Inline -> Inlines) -> Inline -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inline
EText (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ PostPropAttachmentField -> Text
ppafTitle PostPropAttachmentField
f, Inline
ELineBreak]
makeLenses ''Attachment
makeLenses ''ClientPost