module TD.Data.NewChatPrivacySettings
( NewChatPrivacySettings(..)
, defaultNewChatPrivacySettings
) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data NewChatPrivacySettings
= NewChatPrivacySettings
{ NewChatPrivacySettings -> Maybe Bool
allow_new_chats_from_unknown_users :: Maybe Bool
}
deriving (NewChatPrivacySettings -> NewChatPrivacySettings -> Bool
(NewChatPrivacySettings -> NewChatPrivacySettings -> Bool)
-> (NewChatPrivacySettings -> NewChatPrivacySettings -> Bool)
-> Eq NewChatPrivacySettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NewChatPrivacySettings -> NewChatPrivacySettings -> Bool
== :: NewChatPrivacySettings -> NewChatPrivacySettings -> Bool
$c/= :: NewChatPrivacySettings -> NewChatPrivacySettings -> Bool
/= :: NewChatPrivacySettings -> NewChatPrivacySettings -> Bool
Eq, Int -> NewChatPrivacySettings -> ShowS
[NewChatPrivacySettings] -> ShowS
NewChatPrivacySettings -> String
(Int -> NewChatPrivacySettings -> ShowS)
-> (NewChatPrivacySettings -> String)
-> ([NewChatPrivacySettings] -> ShowS)
-> Show NewChatPrivacySettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NewChatPrivacySettings -> ShowS
showsPrec :: Int -> NewChatPrivacySettings -> ShowS
$cshow :: NewChatPrivacySettings -> String
show :: NewChatPrivacySettings -> String
$cshowList :: [NewChatPrivacySettings] -> ShowS
showList :: [NewChatPrivacySettings] -> ShowS
Show)
instance I.ShortShow NewChatPrivacySettings where
shortShow :: NewChatPrivacySettings -> String
shortShow NewChatPrivacySettings
{ allow_new_chats_from_unknown_users :: NewChatPrivacySettings -> Maybe Bool
allow_new_chats_from_unknown_users = Maybe Bool
allow_new_chats_from_unknown_users_
}
= String
"NewChatPrivacySettings"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"allow_new_chats_from_unknown_users" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
allow_new_chats_from_unknown_users_
]
instance AT.FromJSON NewChatPrivacySettings where
parseJSON :: Value -> Parser NewChatPrivacySettings
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
"newChatPrivacySettings" -> Value -> Parser NewChatPrivacySettings
parseNewChatPrivacySettings Value
v
String
_ -> Parser NewChatPrivacySettings
forall a. Monoid a => a
mempty
where
parseNewChatPrivacySettings :: A.Value -> AT.Parser NewChatPrivacySettings
parseNewChatPrivacySettings :: Value -> Parser NewChatPrivacySettings
parseNewChatPrivacySettings = String
-> (Object -> Parser NewChatPrivacySettings)
-> Value
-> Parser NewChatPrivacySettings
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"NewChatPrivacySettings" ((Object -> Parser NewChatPrivacySettings)
-> Value -> Parser NewChatPrivacySettings)
-> (Object -> Parser NewChatPrivacySettings)
-> Value
-> Parser NewChatPrivacySettings
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
allow_new_chats_from_unknown_users_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"allow_new_chats_from_unknown_users"
NewChatPrivacySettings -> Parser NewChatPrivacySettings
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NewChatPrivacySettings -> Parser NewChatPrivacySettings)
-> NewChatPrivacySettings -> Parser NewChatPrivacySettings
forall a b. (a -> b) -> a -> b
$ NewChatPrivacySettings
{ allow_new_chats_from_unknown_users :: Maybe Bool
allow_new_chats_from_unknown_users = Maybe Bool
allow_new_chats_from_unknown_users_
}
parseJSON Value
_ = Parser NewChatPrivacySettings
forall a. Monoid a => a
mempty
instance AT.ToJSON NewChatPrivacySettings where
toJSON :: NewChatPrivacySettings -> Value
toJSON NewChatPrivacySettings
{ allow_new_chats_from_unknown_users :: NewChatPrivacySettings -> Maybe Bool
allow_new_chats_from_unknown_users = Maybe Bool
allow_new_chats_from_unknown_users_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"newChatPrivacySettings"
, Key
"allow_new_chats_from_unknown_users" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
allow_new_chats_from_unknown_users_
]
defaultNewChatPrivacySettings :: NewChatPrivacySettings
defaultNewChatPrivacySettings :: NewChatPrivacySettings
defaultNewChatPrivacySettings =
NewChatPrivacySettings
{ allow_new_chats_from_unknown_users :: Maybe Bool
allow_new_chats_from_unknown_users = Maybe Bool
forall a. Maybe a
Nothing
}