ReaderT
This commit is contained in:
parent
cdfc0849cf
commit
839f6df5f8
9 changed files with 346 additions and 61 deletions
29
backend/src/Types/AppTypes.hs
Normal file
29
backend/src/Types/AppTypes.hs
Normal 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
|
21
backend/src/Types/ConnectionState.hs
Normal file
21
backend/src/Types/ConnectionState.hs
Normal 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]
|
18
backend/src/Types/Participant.hs
Normal file
18
backend/src/Types/Participant.hs
Normal 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
|
19
backend/src/Types/RoomData.hs
Normal file
19
backend/src/Types/RoomData.hs
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue