module TD.Data.MessageReplyInfo
(MessageReplyInfo(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.MessageSender as MessageSender
data MessageReplyInfo
= MessageReplyInfo
{ MessageReplyInfo -> Maybe Int
reply_count :: Maybe Int
, MessageReplyInfo -> Maybe [MessageSender]
recent_replier_ids :: Maybe [MessageSender.MessageSender]
, MessageReplyInfo -> Maybe Int
last_read_inbox_message_id :: Maybe Int
, MessageReplyInfo -> Maybe Int
last_read_outbox_message_id :: Maybe Int
, MessageReplyInfo -> Maybe Int
last_message_id :: Maybe Int
}
deriving (MessageReplyInfo -> MessageReplyInfo -> Bool
(MessageReplyInfo -> MessageReplyInfo -> Bool)
-> (MessageReplyInfo -> MessageReplyInfo -> Bool)
-> Eq MessageReplyInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageReplyInfo -> MessageReplyInfo -> Bool
== :: MessageReplyInfo -> MessageReplyInfo -> Bool
$c/= :: MessageReplyInfo -> MessageReplyInfo -> Bool
/= :: MessageReplyInfo -> MessageReplyInfo -> Bool
Eq, Int -> MessageReplyInfo -> ShowS
[MessageReplyInfo] -> ShowS
MessageReplyInfo -> String
(Int -> MessageReplyInfo -> ShowS)
-> (MessageReplyInfo -> String)
-> ([MessageReplyInfo] -> ShowS)
-> Show MessageReplyInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageReplyInfo -> ShowS
showsPrec :: Int -> MessageReplyInfo -> ShowS
$cshow :: MessageReplyInfo -> String
show :: MessageReplyInfo -> String
$cshowList :: [MessageReplyInfo] -> ShowS
showList :: [MessageReplyInfo] -> ShowS
Show)
instance I.ShortShow MessageReplyInfo where
shortShow :: MessageReplyInfo -> String
shortShow MessageReplyInfo
{ reply_count :: MessageReplyInfo -> Maybe Int
reply_count = Maybe Int
reply_count_
, recent_replier_ids :: MessageReplyInfo -> Maybe [MessageSender]
recent_replier_ids = Maybe [MessageSender]
recent_replier_ids_
, last_read_inbox_message_id :: MessageReplyInfo -> Maybe Int
last_read_inbox_message_id = Maybe Int
last_read_inbox_message_id_
, last_read_outbox_message_id :: MessageReplyInfo -> Maybe Int
last_read_outbox_message_id = Maybe Int
last_read_outbox_message_id_
, last_message_id :: MessageReplyInfo -> Maybe Int
last_message_id = Maybe Int
last_message_id_
}
= String
"MessageReplyInfo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"reply_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
reply_count_
, String
"recent_replier_ids" String -> Maybe [MessageSender] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [MessageSender]
recent_replier_ids_
, String
"last_read_inbox_message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
last_read_inbox_message_id_
, String
"last_read_outbox_message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
last_read_outbox_message_id_
, String
"last_message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
last_message_id_
]
instance AT.FromJSON MessageReplyInfo where
parseJSON :: Value -> Parser MessageReplyInfo
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"messageReplyInfo" -> Value -> Parser MessageReplyInfo
parseMessageReplyInfo Value
v
String
_ -> Parser MessageReplyInfo
forall a. Monoid a => a
mempty
where
parseMessageReplyInfo :: A.Value -> AT.Parser MessageReplyInfo
parseMessageReplyInfo :: Value -> Parser MessageReplyInfo
parseMessageReplyInfo = String
-> (Object -> Parser MessageReplyInfo)
-> Value
-> Parser MessageReplyInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageReplyInfo" ((Object -> Parser MessageReplyInfo)
-> Value -> Parser MessageReplyInfo)
-> (Object -> Parser MessageReplyInfo)
-> Value
-> Parser MessageReplyInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
reply_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"reply_count"
Maybe [MessageSender]
recent_replier_ids_ <- Object
o Object -> Key -> Parser (Maybe [MessageSender])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"recent_replier_ids"
Maybe Int
last_read_inbox_message_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"last_read_inbox_message_id"
Maybe Int
last_read_outbox_message_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"last_read_outbox_message_id"
Maybe Int
last_message_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"last_message_id"
MessageReplyInfo -> Parser MessageReplyInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageReplyInfo -> Parser MessageReplyInfo)
-> MessageReplyInfo -> Parser MessageReplyInfo
forall a b. (a -> b) -> a -> b
$ MessageReplyInfo
{ reply_count :: Maybe Int
reply_count = Maybe Int
reply_count_
, recent_replier_ids :: Maybe [MessageSender]
recent_replier_ids = Maybe [MessageSender]
recent_replier_ids_
, last_read_inbox_message_id :: Maybe Int
last_read_inbox_message_id = Maybe Int
last_read_inbox_message_id_
, last_read_outbox_message_id :: Maybe Int
last_read_outbox_message_id = Maybe Int
last_read_outbox_message_id_
, last_message_id :: Maybe Int
last_message_id = Maybe Int
last_message_id_
}
parseJSON Value
_ = Parser MessageReplyInfo
forall a. Monoid a => a
mempty