diff options
-rw-r--r-- | erebos-webapp.cabal | 2 | ||||
-rw-r--r-- | src/Main.hs | 34 |
2 files changed, 18 insertions, 18 deletions
diff --git a/erebos-webapp.cabal b/erebos-webapp.cabal index 703a583..057b7d4 100644 --- a/erebos-webapp.cabal +++ b/erebos-webapp.cabal @@ -57,7 +57,7 @@ executable erebos-webapp base ^>= { 4.21 }, blaze-html ^>= { 0.9 }, bytestring ^>= { 0.12 }, - erebos ^>= { 0.1.8 }, + erebos ^>= { 0.2 }, ghc-experimental ^>= { 9.1201, 9.1202 }, http-types ^>= { 0.12.4 }, mtl ^>= { 2.3 }, diff --git a/src/Main.hs b/src/Main.hs index 9c8d552..644b2d3 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -60,13 +60,14 @@ data CurrentConversation initGlobalState :: IO GlobalState initGlobalState = do globalStorage <- memoryStorage - identity <- createIdentity globalStorage Nothing Nothing - globalHead <- storeHead globalStorage $ LocalState - { lsPrev = Nothing, lsIdentity = idExtData identity, lsShared = [], lsOther = [] } - peerListVar <- newMVar [] - currentConversationVar <- newMVar NoCurrentConversation - conversationsVar <- newMVar [] - return GlobalState {..} + (either (fail . showErebosError) return =<<) $ runExceptT $ flip runReaderT globalStorage $ do + identity <- createIdentity Nothing Nothing + globalHead <- storeHead globalStorage $ LocalState + { lsPrev = Nothing, lsIdentity = idExtData identity, lsShared = [], lsOther = [] } + peerListVar <- liftIO $ newMVar [] + currentConversationVar <- liftIO $ newMVar NoCurrentConversation + conversationsVar <- liftIO $ newMVar [] + return GlobalState {..} foreign export javascript setup :: IO () setup :: IO () @@ -112,16 +113,15 @@ setup = do watchConversations gs let devName = T.pack "WebApp" - let st = globalStorage - owner <- createIdentity st Nothing Nothing - identity <- createIdentity st (Just devName) (Just owner) - - shared <- wrappedStore st $ SharedState - { ssPrev = [] - , ssType = Just $ sharedTypeID @(Maybe ComposedIdentity) Proxy - , ssValue = [ storedRef $ idExtData owner ] - } - flip runReaderT globalHead $ do + (either (fail . showErebosError) return =<<) $ runExceptT $ flip runReaderT globalHead $ do + owner <- createIdentity Nothing Nothing + identity <- createIdentity (Just devName) (Just owner) + + shared <- mstore SharedState + { ssPrev = [] + , ssType = Just $ sharedTypeID @(Maybe ComposedIdentity) Proxy + , ssValue = [ storedRef $ idExtData owner ] + } updateLocalState_ $ \_ -> do mstore $ LocalState { lsPrev = Nothing |