{-# LANGUAGE TemplateHaskell #-}
module Calamity.Types.Model.Channel.DM (DMChannel (..)) where
import {-# SOURCE #-} Calamity.Types.Model.Channel
import {-# SOURCE #-} Calamity.Types.Model.Channel.Message
import Calamity.Types.Model.User
import Calamity.Types.Snowflake
import Data.Aeson ((.:), (.:?))
import Data.Aeson qualified as Aeson
import Data.Time
import Optics.TH
import TextShow qualified
data DMChannel = DMChannel
{ DMChannel -> Snowflake DMChannel
id :: Snowflake DMChannel
, DMChannel -> Maybe (Snowflake Message)
lastMessageID :: Maybe (Snowflake Message)
, DMChannel -> Maybe UTCTime
lastPinTimestamp :: Maybe UTCTime
, DMChannel -> [User]
recipients :: [User]
}
deriving (Int -> DMChannel -> ShowS
[DMChannel] -> ShowS
DMChannel -> String
(Int -> DMChannel -> ShowS)
-> (DMChannel -> String)
-> ([DMChannel] -> ShowS)
-> Show DMChannel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DMChannel -> ShowS
showsPrec :: Int -> DMChannel -> ShowS
$cshow :: DMChannel -> String
show :: DMChannel -> String
$cshowList :: [DMChannel] -> ShowS
showList :: [DMChannel] -> ShowS
Show, DMChannel -> DMChannel -> Bool
(DMChannel -> DMChannel -> Bool)
-> (DMChannel -> DMChannel -> Bool) -> Eq DMChannel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DMChannel -> DMChannel -> Bool
== :: DMChannel -> DMChannel -> Bool
$c/= :: DMChannel -> DMChannel -> Bool
/= :: DMChannel -> DMChannel -> Bool
Eq)
deriving (Int -> DMChannel -> Text
Int -> DMChannel -> Builder
Int -> DMChannel -> Text
[DMChannel] -> Text
[DMChannel] -> Builder
[DMChannel] -> Text
DMChannel -> Text
DMChannel -> Builder
DMChannel -> Text
(Int -> DMChannel -> Builder)
-> (DMChannel -> Builder)
-> ([DMChannel] -> Builder)
-> (Int -> DMChannel -> Text)
-> (DMChannel -> Text)
-> ([DMChannel] -> Text)
-> (Int -> DMChannel -> Text)
-> (DMChannel -> Text)
-> ([DMChannel] -> Text)
-> TextShow DMChannel
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> DMChannel -> Builder
showbPrec :: Int -> DMChannel -> Builder
$cshowb :: DMChannel -> Builder
showb :: DMChannel -> Builder
$cshowbList :: [DMChannel] -> Builder
showbList :: [DMChannel] -> Builder
$cshowtPrec :: Int -> DMChannel -> Text
showtPrec :: Int -> DMChannel -> Text
$cshowt :: DMChannel -> Text
showt :: DMChannel -> Text
$cshowtList :: [DMChannel] -> Text
showtList :: [DMChannel] -> Text
$cshowtlPrec :: Int -> DMChannel -> Text
showtlPrec :: Int -> DMChannel -> Text
$cshowtl :: DMChannel -> Text
showtl :: DMChannel -> Text
$cshowtlList :: [DMChannel] -> Text
showtlList :: [DMChannel] -> Text
TextShow.TextShow) via TextShow.FromStringShow DMChannel
deriving (HasID DMChannel) via HasIDField "id" DMChannel
deriving (HasID Channel) via HasIDFieldCoerce' "id" DMChannel
instance Aeson.FromJSON DMChannel where
parseJSON :: Value -> Parser DMChannel
parseJSON = String -> (Object -> Parser DMChannel) -> Value -> Parser DMChannel
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"DMChannel" ((Object -> Parser DMChannel) -> Value -> Parser DMChannel)
-> (Object -> Parser DMChannel) -> Value -> Parser DMChannel
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Snowflake DMChannel
-> Maybe (Snowflake Message)
-> Maybe UTCTime
-> [User]
-> DMChannel
DMChannel
(Snowflake DMChannel
-> Maybe (Snowflake Message)
-> Maybe UTCTime
-> [User]
-> DMChannel)
-> Parser (Snowflake DMChannel)
-> Parser
(Maybe (Snowflake Message) -> Maybe UTCTime -> [User] -> DMChannel)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Snowflake DMChannel)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
Parser
(Maybe (Snowflake Message) -> Maybe UTCTime -> [User] -> DMChannel)
-> Parser (Maybe (Snowflake Message))
-> Parser (Maybe UTCTime -> [User] -> DMChannel)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe (Snowflake Message))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"last_pin_timestamp"
Parser (Maybe UTCTime -> [User] -> DMChannel)
-> Parser (Maybe UTCTime) -> Parser ([User] -> DMChannel)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe UTCTime)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"last_message_id"
Parser ([User] -> DMChannel) -> Parser [User] -> Parser DMChannel
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser [User]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"recipients"
$(makeFieldLabelsNoPrefix ''DMChannel)