This commit is contained in:
qvalentin 2023-01-27 18:34:28 +01:00
parent cdfc0849cf
commit 839f6df5f8
9 changed files with 346 additions and 61 deletions

View file

@ -0,0 +1,29 @@
{-# LANGUAGE DerivingVia #-}
module Types.AppTypes (Env (..), App (..), getConnectedClientState, HasConnectedClientState, App, AppProfile (Prod, Dev)) where
import ClassyPrelude
import Types.ConnectionState (ConnectedClientsState)
data AppProfile = Prod | Dev
data Env = Env
{ connectedClientsState :: ConnectedClientsState,
profile :: AppProfile
}
class HasConnectedClientState a where
getConnectedClientState :: a -> ConnectedClientsState
instance HasConnectedClientState Env where
getConnectedClientState = connectedClientsState
newtype App env a = App {unApp :: env -> IO a}
deriving
( Functor,
Applicative,
Monad,
MonadReader env,
MonadIO
)
via ReaderT env IO

View file

@ -0,0 +1,21 @@
module Types.ConnectionState
( Client (..),
Client,
ConnectedClientsState,
ConnectedClients,
)
where
import ClassyPrelude
import Data.UUID (UUID)
import Network.WebSockets qualified as WS
data Client = Client
{ uuid :: UUID,
name :: Text,
conn :: WS.Connection
}
type ConnectedClientsState = MVar ConnectedClients
type ConnectedClients = [Client]

View file

@ -0,0 +1,18 @@
{-# LANGUAGE DeriveGeneric #-}
module Types.Participant (Participant) where
import ClassyPrelude
import Data.Aeson (FromJSON, ToJSON)
data Participant = Participant
{ jid :: Text,
email :: Text,
displayName :: Text,
avatarURL :: Text
}
deriving (Generic, Show)
instance ToJSON Participant
instance FromJSON Participant

View file

@ -0,0 +1,19 @@
{-# LANGUAGE DeriveGeneric #-}
module Types.RoomData (RoomData) where
import ClassyPrelude
import Data.Aeson (FromJSON, ToJSON)
import Types.Participant (Participant)
data RoomData = RoomData
{ roomName :: RoomName,
participants :: [Participant]
}
deriving (Generic, Show)
type RoomName = Text
instance ToJSON RoomData
instance FromJSON RoomData