summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2025-07-13 12:38:11 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2025-07-13 12:38:11 +0200
commit829a46ab5b15fbf5cc1ad7eb6d40ec89f82f837d (patch)
treee1bd17c03f14b3362e538c89a635fda2a23609f2 /src/Main.hs
parentd84781cdf884ee931d180095d83b81d9f190d628 (diff)
Move peer list to global stateHEADmaster
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs5
1 files changed, 3 insertions, 2 deletions
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")