module TD.Data.MessageReplyTo
(MessageReplyTo(..)) 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.TextQuote as TextQuote
import qualified TD.Data.MessageOrigin as MessageOrigin
import qualified TD.Data.MessageContent as MessageContent
data MessageReplyTo
= MessageReplyToMessage
{ MessageReplyTo -> Maybe Int
chat_id :: Maybe Int
, MessageReplyTo -> Maybe Int
message_id :: Maybe Int
, MessageReplyTo -> Maybe TextQuote
quote :: Maybe TextQuote.TextQuote
, MessageReplyTo -> Maybe MessageOrigin
origin :: Maybe MessageOrigin.MessageOrigin
, MessageReplyTo -> Maybe Int
origin_send_date :: Maybe Int
, MessageReplyTo -> Maybe MessageContent
content :: Maybe MessageContent.MessageContent
}
| MessageReplyToStory
{ MessageReplyTo -> Maybe Int
story_sender_chat_id :: Maybe Int
, MessageReplyTo -> Maybe Int
story_id :: Maybe Int
}
deriving (MessageReplyTo -> MessageReplyTo -> Bool
(MessageReplyTo -> MessageReplyTo -> Bool)
-> (MessageReplyTo -> MessageReplyTo -> Bool) -> Eq MessageReplyTo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageReplyTo -> MessageReplyTo -> Bool
== :: MessageReplyTo -> MessageReplyTo -> Bool
$c/= :: MessageReplyTo -> MessageReplyTo -> Bool
/= :: MessageReplyTo -> MessageReplyTo -> Bool
Eq, Int -> MessageReplyTo -> ShowS
[MessageReplyTo] -> ShowS
MessageReplyTo -> String
(Int -> MessageReplyTo -> ShowS)
-> (MessageReplyTo -> String)
-> ([MessageReplyTo] -> ShowS)
-> Show MessageReplyTo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageReplyTo -> ShowS
showsPrec :: Int -> MessageReplyTo -> ShowS
$cshow :: MessageReplyTo -> String
show :: MessageReplyTo -> String
$cshowList :: [MessageReplyTo] -> ShowS
showList :: [MessageReplyTo] -> ShowS
Show)
instance I.ShortShow MessageReplyTo where
shortShow :: MessageReplyTo -> String
shortShow MessageReplyToMessage
{ chat_id :: MessageReplyTo -> Maybe Int
chat_id = Maybe Int
chat_id_
, message_id :: MessageReplyTo -> Maybe Int
message_id = Maybe Int
message_id_
, quote :: MessageReplyTo -> Maybe TextQuote
quote = Maybe TextQuote
quote_
, origin :: MessageReplyTo -> Maybe MessageOrigin
origin = Maybe MessageOrigin
origin_
, origin_send_date :: MessageReplyTo -> Maybe Int
origin_send_date = Maybe Int
origin_send_date_
, content :: MessageReplyTo -> Maybe MessageContent
content = Maybe MessageContent
content_
}
= String
"MessageReplyToMessage"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
, String
"message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_id_
, String
"quote" String -> Maybe TextQuote -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe TextQuote
quote_
, String
"origin" String -> Maybe MessageOrigin -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageOrigin
origin_
, String
"origin_send_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
origin_send_date_
, String
"content" String -> Maybe MessageContent -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageContent
content_
]
shortShow MessageReplyToStory
{ story_sender_chat_id :: MessageReplyTo -> Maybe Int
story_sender_chat_id = Maybe Int
story_sender_chat_id_
, story_id :: MessageReplyTo -> Maybe Int
story_id = Maybe Int
story_id_
}
= String
"MessageReplyToStory"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"story_sender_chat_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
story_sender_chat_id_
, String
"story_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
story_id_
]
instance AT.FromJSON MessageReplyTo where
parseJSON :: Value -> Parser MessageReplyTo
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
"messageReplyToMessage" -> Value -> Parser MessageReplyTo
parseMessageReplyToMessage Value
v
String
"messageReplyToStory" -> Value -> Parser MessageReplyTo
parseMessageReplyToStory Value
v
String
_ -> Parser MessageReplyTo
forall a. Monoid a => a
mempty
where
parseMessageReplyToMessage :: A.Value -> AT.Parser MessageReplyTo
parseMessageReplyToMessage :: Value -> Parser MessageReplyTo
parseMessageReplyToMessage = String
-> (Object -> Parser MessageReplyTo)
-> Value
-> Parser MessageReplyTo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageReplyToMessage" ((Object -> Parser MessageReplyTo)
-> Value -> Parser MessageReplyTo)
-> (Object -> Parser MessageReplyTo)
-> Value
-> Parser MessageReplyTo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
chat_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"chat_id"
Maybe Int
message_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"message_id"
Maybe TextQuote
quote_ <- Object
o Object -> Key -> Parser (Maybe TextQuote)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"quote"
Maybe MessageOrigin
origin_ <- Object
o Object -> Key -> Parser (Maybe MessageOrigin)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"origin"
Maybe Int
origin_send_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"origin_send_date"
Maybe MessageContent
content_ <- Object
o Object -> Key -> Parser (Maybe MessageContent)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"content"
MessageReplyTo -> Parser MessageReplyTo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageReplyTo -> Parser MessageReplyTo)
-> MessageReplyTo -> Parser MessageReplyTo
forall a b. (a -> b) -> a -> b
$ MessageReplyToMessage
{ chat_id :: Maybe Int
chat_id = Maybe Int
chat_id_
, message_id :: Maybe Int
message_id = Maybe Int
message_id_
, quote :: Maybe TextQuote
quote = Maybe TextQuote
quote_
, origin :: Maybe MessageOrigin
origin = Maybe MessageOrigin
origin_
, origin_send_date :: Maybe Int
origin_send_date = Maybe Int
origin_send_date_
, content :: Maybe MessageContent
content = Maybe MessageContent
content_
}
parseMessageReplyToStory :: A.Value -> AT.Parser MessageReplyTo
parseMessageReplyToStory :: Value -> Parser MessageReplyTo
parseMessageReplyToStory = String
-> (Object -> Parser MessageReplyTo)
-> Value
-> Parser MessageReplyTo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageReplyToStory" ((Object -> Parser MessageReplyTo)
-> Value -> Parser MessageReplyTo)
-> (Object -> Parser MessageReplyTo)
-> Value
-> Parser MessageReplyTo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
story_sender_chat_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"story_sender_chat_id"
Maybe Int
story_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"story_id"
MessageReplyTo -> Parser MessageReplyTo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageReplyTo -> Parser MessageReplyTo)
-> MessageReplyTo -> Parser MessageReplyTo
forall a b. (a -> b) -> a -> b
$ MessageReplyToStory
{ story_sender_chat_id :: Maybe Int
story_sender_chat_id = Maybe Int
story_sender_chat_id_
, story_id :: Maybe Int
story_id = Maybe Int
story_id_
}
parseJSON Value
_ = Parser MessageReplyTo
forall a. Monoid a => a
mempty