[websocket] add Subscription data

parent 245bc254
...@@ -53,7 +53,7 @@ server and client. ...@@ -53,7 +53,7 @@ server and client.
-- | Various update actions -- | Various update actions
data UpdateAction = data Topic =
-- | Update given Servant Job (we currently send a request every -- | Update given Servant Job (we currently send a request every
-- | second to get job status). -- | second to get job status).
-- UpdateJob JobID -- UpdateJob JobID
...@@ -63,7 +63,7 @@ data UpdateAction = ...@@ -63,7 +63,7 @@ data UpdateAction =
deriving (Eq, Show) deriving (Eq, Show)
-- NOTE: I'm not sure if UserAction/UserSource is needed. I initially -- TODO: I'm not sure if UserAction/UserSource is needed. I initially
-- created that to mark who initiated the action, but I think we don't -- created that to mark who initiated the action, but I think we don't
-- need it. -- need it.
-- --
...@@ -78,7 +78,7 @@ data UserSource = ...@@ -78,7 +78,7 @@ data UserSource =
-- | Action possibly associated with user who triggered it (there can -- | Action possibly associated with user who triggered it (there can
-- be system actions as well) -- be system actions as well)
data UserAction = data UserAction =
UserAction UserSource UpdateAction UserAction UserSource Topic
deriving (Eq, Show) deriving (Eq, Show)
...@@ -99,16 +99,27 @@ notificationsForUserAction :: UserAction -> m [ UserNotification ] ...@@ -99,16 +99,27 @@ notificationsForUserAction :: UserAction -> m [ UserNotification ]
notificationsForUserAction = undefined notificationsForUserAction = undefined
-- | Stores connection type associated with given user. -- | A connected user can be either associated with his UserId or
-- don't have it, since he's not logged in (for public messages).
data ConnectedUser =
CUUser UserId
| CUPublic
deriving (Eq, Show)
-- | Stores connection type associated with given user, subscribed to
-- | a given topic.
--
-- We probably should set conn = Servant.API.WebSocket.Connection -- We probably should set conn = Servant.API.WebSocket.Connection
data ConnectedUser conn = data Subscription conn =
ConnectedUser UserId conn Subscription ConnectedUser conn Topic
-- | Given a UserNotification and all connected users, send it to -- | Given a UserNotification and all subscriptions, send it to all
-- interested ones. Possibly we could make this function as part of -- matching ones. Possibly we could make this function as part of a
-- a typeclass so that we can decide how to send the notification -- typeclass so that we can decide how to send the notification
-- based on whether we choose pure WebSockets, NATS or something -- based on whether we choose pure WebSockets, NATS or something
-- else. -- else.
sendNotification :: UserNotification -> [ ConnectedUser conn ] -> m () sendNotification :: UserNotification -> [ Subscription conn ] -> m ()
sendNotification = undefined sendNotification = undefined
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment