From 64ec9972be1b54b7b12fd13cdd6559de61b84b1f Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sat, 25 Jan 2025 18:37:03 +0100 Subject: [PATCH] more fixes --- backend/src/RoomDataHandler.hs | 9 ++++----- backend/src/State/RoomsState.hs | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/backend/src/RoomDataHandler.hs b/backend/src/RoomDataHandler.hs index 3f87ae1..5741201 100644 --- a/backend/src/RoomDataHandler.hs +++ b/backend/src/RoomDataHandler.hs @@ -49,13 +49,12 @@ roomDataHandler :: roomDataHandler = do newRoomData <- parseBodyOrBadRequest liftIO $ putStrLn "Got triggered from prosody" - whenM (roomStateDiffers newRoomData) $ do - (openedRooms, closedRooms) <- setRoomDataState newRoomData + (openedRooms, closedRooms) <- setRoomDataState newRoomData - mapM_ notifyRoomOpend openedRooms - mapM_ notifyRoomClosed closedRooms + mapM_ notifyRoomOpend openedRooms + mapM_ notifyRoomClosed closedRooms - broadcastUserData + broadcastUserData success parseBodyOrBadRequest :: diff --git a/backend/src/State/RoomsState.hs b/backend/src/State/RoomsState.hs index 01c9a2c..62a9edc 100644 --- a/backend/src/State/RoomsState.hs +++ b/backend/src/State/RoomsState.hs @@ -26,16 +26,23 @@ class HasRoomsState a where updateRoomState :: ( HasRoomsState env, MonadIO m, - MonadReader env m + MonadReader env m, + MonadRoomDataStateRead m ) => RoomsData -> m RoomsStateDiff updateRoomState newData = do state <- getRoomsState <$> ask - liftIO $ putStrLn "Upating room state" - diff <- updateGenericTVarStateWithQuery state roomStateDiff newData - liftIO $ putStrLn "Done Upating room state" - return diff + current <- getRoomDataState + if not $ eqIgnoreOrdering newData current + then + ( do + liftIO $ putStrLn "Upating room state" + diff <- updateGenericTVarStateWithQuery state roomStateDiff newData + liftIO $ putStrLn "Done Upating room state" + return diff + ) + else return ([], []) getRoomState :: ( HasRoomsState env,