Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/incomplete patterns #567

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions IHP/AutoRefresh.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ autoRefresh runAction = do
id <- UUID.nextRandom
let controllerContext = ?context
let renderView = \requestContext -> let ?context = controllerContext { requestContext } in action ?theAction

putContext (AutoRefreshEnabled id)

-- We save the allowed session ids to the session cookie to only grant a client access
-- to sessions it initially opened itself
--
--
-- Otherwise you might try to guess session UUIDs to access other peoples auto refresh sessions
setSession "autoRefreshSessions" (map UUID.toText (id:availableSessions) |> Text.intercalate "")

Expand All @@ -77,9 +77,10 @@ autoRefresh runAction = do
async (gcSessions autoRefreshServer)

registerNotificationTrigger ?touchedTables autoRefreshServer

throw exception

_ -> error "Unimplemented WAI response type."

runAction `Exception.catch` handleResponse
AutoRefreshEnabled {} -> do
-- When this function calls the 'action ?theAction' in the other case
Expand Down Expand Up @@ -109,6 +110,7 @@ instance WSApp AutoRefreshWSApp where
when (html /= lastResponse) do
updateSession sessionId (\session -> session { lastResponse = html })
sendTextData html
_ -> error "Unimplemented WAI response type."

async $ forever do
MVar.takeMVar event
Expand Down Expand Up @@ -139,7 +141,7 @@ registerNotificationTrigger :: (?modelContext :: ModelContext) => IORef (Set Tex
registerNotificationTrigger touchedTablesVar autoRefreshServer = do
touchedTables <- Set.toList <$> readIORef touchedTablesVar
subscribedTables <- (get #subscribedTables) <$> (autoRefreshServer |> readIORef)

let subscriptionRequired = touchedTables |> filter (\table -> subscribedTables |> Set.notMember table)
modifyIORef autoRefreshServer (\server -> server { subscribedTables = get #subscribedTables server <> Set.fromList subscriptionRequired })
forEach subscriptionRequired \table -> do
Expand Down
1 change: 1 addition & 0 deletions IHP/WebSocket.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ startWSApp connection = do
let
handleException Websocket.ConnectionClosed = onClose @state
handleException (Websocket.CloseRequest {}) = onClose @state
handleException e = error ("Unhandled Websocket exception: " <> show e)
result <- Exception.try ((Websocket.withPingThread connection 30 (onPing @state) (run @state)) `Exception.catch` handleException)
case result of
Left (Exception.SomeException e) -> putStrLn (tshow e)
Expand Down