From 829a46ab5b15fbf5cc1ad7eb6d40ec89f82f837d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 13 Jul 2025 12:38:11 +0200 Subject: Move peer list to global state --- src/Main.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Main.hs b/src/Main.hs index 2071015..563f3af 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -46,6 +46,7 @@ main = error "unused" data GlobalState = GlobalState { globalStorage :: Storage , globalHead :: Head LocalState + , peerListVar :: MVar [ ( Peer, String ) ] , currentConversationVar :: MVar (Maybe Conversation) } @@ -55,6 +56,7 @@ initGlobalState = do identity <- createIdentity globalStorage Nothing Nothing globalHead <- storeHead globalStorage $ LocalState { lsPrev = Nothing, lsIdentity = idExtData identity, lsShared = [], lsOther = [] } + peerListVar <- newMVar [] currentConversationVar <- newMVar Nothing return GlobalState {..} @@ -217,7 +219,6 @@ selectConversation GlobalState {..} conv = do watchPeers :: GlobalState -> Server -> JSVal -> IO () watchPeers gs@GlobalState {..} server htmlList = do - peers <- liftIO $ newMVar [] void $ forkIO $ void $ forever $ do peer <- getNextPeerChange server peerIdentity peer >>= \case @@ -229,7 +230,7 @@ watchPeers gs@GlobalState {..} server htmlList = do | p == peer && dropped = ( ps, ( Nothing, "DEL" ) ) | p == peer = ( ( peer, shown ) : ps, ( Just s, "UPD" ) ) | otherwise = first ( ( p, s ) :) $ update ps - (op, updateType) <- modifyMVar peers (return . update) + (op, updateType) <- modifyMVar peerListVar (return . update) let updateType' = if dropped then "DEL" else updateType when (Just shown /= op) $ do a <- js_document_createElement (toJSString "a") -- cgit v1.2.3