All Chat Backend
This commit is contained in:
parent
b01b637a22
commit
cf1c7625be
10 changed files with 90 additions and 36 deletions
21
backend/src/Types/User.hs
Normal file
21
backend/src/Types/User.hs
Normal file
|
@ -0,0 +1,21 @@
|
|||
{-# LANGUAGE DeriveGeneric #-}
|
||||
|
||||
module Types.User (User, clientToUser) where
|
||||
|
||||
import ClassyPrelude
|
||||
import Data.Aeson (FromJSON, ToJSON)
|
||||
import Data.UUID (UUID)
|
||||
import Types.ConnectionState qualified as C
|
||||
|
||||
data User = User
|
||||
{ uuid :: UUID,
|
||||
name :: Text
|
||||
}
|
||||
deriving (Generic, Show, Eq)
|
||||
|
||||
clientToUser :: C.Client -> User
|
||||
clientToUser C.Client {C.uuid = userUuid, C.name = userName, C.joinedRoom = _, C.conn = _} = User userUuid userName
|
||||
|
||||
instance ToJSON User
|
||||
|
||||
instance FromJSON User
|
|
@ -5,16 +5,17 @@ module Types.UsersData
|
|||
)
|
||||
where
|
||||
|
||||
import ClassyPrelude
|
||||
import Data.Aeson (ToJSON)
|
||||
import Types.RoomData (RoomsData)
|
||||
import ClassyPrelude
|
||||
import Data.Aeson (ToJSON)
|
||||
import Types.RoomData (RoomsData)
|
||||
import Types.User (User)
|
||||
|
||||
data UsersData = UsersData
|
||||
{ roomsData :: RoomsData,
|
||||
{ roomsData :: RoomsData,
|
||||
usersWithOutRoom :: UsersWithoutRoom
|
||||
}
|
||||
deriving (Generic, Show)
|
||||
|
||||
instance ToJSON UsersData
|
||||
|
||||
type UsersWithoutRoom = [Text]
|
||||
type UsersWithoutRoom = [User]
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE DuplicateRecordFields #-}
|
||||
|
||||
module Types.WebSocketMessages.WebSocketMessages
|
||||
( WebSocketMessage (..),
|
||||
SetClientInfo (..),
|
||||
JoinRoom (..),
|
||||
AllChatMessageIncoming (..),
|
||||
AllChatMessageOutgoing (..),
|
||||
)
|
||||
where
|
||||
|
||||
|
@ -12,14 +15,13 @@ import Data.Aeson
|
|||
( FromJSON (parseJSON),
|
||||
Options (sumEncoding),
|
||||
SumEncoding (..),
|
||||
decode,
|
||||
ToJSON,
|
||||
defaultOptions,
|
||||
genericParseJSON,
|
||||
withObject,
|
||||
(.:),
|
||||
)
|
||||
import Types.User (User)
|
||||
|
||||
data WebSocketMessage = ClientInfoMessage SetClientInfo | JoinRoomMessage JoinRoom
|
||||
data WebSocketMessage = ClientInfoMessage SetClientInfo | JoinRoomMessage JoinRoom | AllChatMessageIncomingMessage AllChatMessageIncoming
|
||||
deriving (Generic)
|
||||
|
||||
instance FromJSON WebSocketMessage where
|
||||
|
@ -38,3 +40,18 @@ data JoinRoom = JoinRoom
|
|||
deriving (Generic, Show)
|
||||
|
||||
instance FromJSON JoinRoom
|
||||
|
||||
data AllChatMessageIncoming = AllChatMessageIncoming
|
||||
{ content :: Text
|
||||
}
|
||||
deriving (Generic, Show)
|
||||
|
||||
instance FromJSON AllChatMessageIncoming
|
||||
|
||||
data AllChatMessageOutgoing = AllChatMessageOutgoing
|
||||
{ content :: Text,
|
||||
sender :: User
|
||||
}
|
||||
deriving (Generic, Show)
|
||||
|
||||
instance ToJSON AllChatMessageOutgoing
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue