module TD.Data.MessageReaction
(MessageReaction(..)) 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.ReactionType as ReactionType
import qualified TD.Data.MessageSender as MessageSender
data MessageReaction
= MessageReaction
{ MessageReaction -> Maybe ReactionType
_type :: Maybe ReactionType.ReactionType
, MessageReaction -> Maybe Int
total_count :: Maybe Int
, MessageReaction -> Maybe Bool
is_chosen :: Maybe Bool
, MessageReaction -> Maybe MessageSender
used_sender_id :: Maybe MessageSender.MessageSender
, MessageReaction -> Maybe [MessageSender]
recent_sender_ids :: Maybe [MessageSender.MessageSender]
}
deriving (MessageReaction -> MessageReaction -> Bool
(MessageReaction -> MessageReaction -> Bool)
-> (MessageReaction -> MessageReaction -> Bool)
-> Eq MessageReaction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageReaction -> MessageReaction -> Bool
== :: MessageReaction -> MessageReaction -> Bool
$c/= :: MessageReaction -> MessageReaction -> Bool
/= :: MessageReaction -> MessageReaction -> Bool
Eq, Int -> MessageReaction -> ShowS
[MessageReaction] -> ShowS
MessageReaction -> String
(Int -> MessageReaction -> ShowS)
-> (MessageReaction -> String)
-> ([MessageReaction] -> ShowS)
-> Show MessageReaction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageReaction -> ShowS
showsPrec :: Int -> MessageReaction -> ShowS
$cshow :: MessageReaction -> String
show :: MessageReaction -> String
$cshowList :: [MessageReaction] -> ShowS
showList :: [MessageReaction] -> ShowS
Show)
instance I.ShortShow MessageReaction where
shortShow :: MessageReaction -> String
shortShow MessageReaction
{ _type :: MessageReaction -> Maybe ReactionType
_type = Maybe ReactionType
_type_
, total_count :: MessageReaction -> Maybe Int
total_count = Maybe Int
total_count_
, is_chosen :: MessageReaction -> Maybe Bool
is_chosen = Maybe Bool
is_chosen_
, used_sender_id :: MessageReaction -> Maybe MessageSender
used_sender_id = Maybe MessageSender
used_sender_id_
, recent_sender_ids :: MessageReaction -> Maybe [MessageSender]
recent_sender_ids = Maybe [MessageSender]
recent_sender_ids_
}
= String
"MessageReaction"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_type" String -> Maybe ReactionType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ReactionType
_type_
, String
"total_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
total_count_
, String
"is_chosen" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_chosen_
, String
"used_sender_id" String -> Maybe MessageSender -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSender
used_sender_id_
, String
"recent_sender_ids" String -> Maybe [MessageSender] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [MessageSender]
recent_sender_ids_
]
instance AT.FromJSON MessageReaction where
parseJSON :: Value -> Parser MessageReaction
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
"messageReaction" -> Value -> Parser MessageReaction
parseMessageReaction Value
v
String
_ -> Parser MessageReaction
forall a. Monoid a => a
mempty
where
parseMessageReaction :: A.Value -> AT.Parser MessageReaction
parseMessageReaction :: Value -> Parser MessageReaction
parseMessageReaction = String
-> (Object -> Parser MessageReaction)
-> Value
-> Parser MessageReaction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageReaction" ((Object -> Parser MessageReaction)
-> Value -> Parser MessageReaction)
-> (Object -> Parser MessageReaction)
-> Value
-> Parser MessageReaction
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe ReactionType
_type_ <- Object
o Object -> Key -> Parser (Maybe ReactionType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
Maybe Int
total_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"total_count"
Maybe Bool
is_chosen_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_chosen"
Maybe MessageSender
used_sender_id_ <- Object
o Object -> Key -> Parser (Maybe MessageSender)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"used_sender_id"
Maybe [MessageSender]
recent_sender_ids_ <- Object
o Object -> Key -> Parser (Maybe [MessageSender])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"recent_sender_ids"
MessageReaction -> Parser MessageReaction
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageReaction -> Parser MessageReaction)
-> MessageReaction -> Parser MessageReaction
forall a b. (a -> b) -> a -> b
$ MessageReaction
{ _type :: Maybe ReactionType
_type = Maybe ReactionType
_type_
, total_count :: Maybe Int
total_count = Maybe Int
total_count_
, is_chosen :: Maybe Bool
is_chosen = Maybe Bool
is_chosen_
, used_sender_id :: Maybe MessageSender
used_sender_id = Maybe MessageSender
used_sender_id_
, recent_sender_ids :: Maybe [MessageSender]
recent_sender_ids = Maybe [MessageSender]
recent_sender_ids_
}
parseJSON Value
_ = Parser MessageReaction
forall a. Monoid a => a
mempty