diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 819832a1ed..11cd8e33ad 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -1611,7 +1611,7 @@ processChatCommand' vr = \case srvs' <- mapM aUserServer srvs processChatCommand $ APISetUserServers userId $ L.map (updatedServers p srvs') userServers where - aUserServer :: AProtoServerWithAuth -> CM (AUserServer p) + aUserServer :: AProtoServerWithAuth -> CM (AUserServer p) aUserServer (AProtoServerWithAuth p' srv) = case testEquality p p' of Just Refl -> pure $ AUS SDBNew $ newUserServer srv Nothing -> throwChatError $ CECommandError $ "incorrect server protocol: " <> B.unpack (strEncode srv) @@ -2949,8 +2949,17 @@ processChatCommand' vr = \case validateAllUsersServers :: UserServersClass u => Int64 -> [u] -> CM [UserServersError] validateAllUsersServers currUserId userServers = withFastStore $ \db -> do users' <- filter (\User {userId} -> userId /= currUserId) <$> liftIO (getUsers db) - others <- mapM (\user -> liftIO . fmap (user,) . groupByOperator =<< getUserServers db user) users' + others <- mapM (getUserOperatorServers db) users' pure $ validateUserServers userServers others + where + getUserOperatorServers :: DB.Connection -> User -> ExceptT StoreError IO (User, [UserOperatorServers]) + getUserOperatorServers db user = do + uss <- liftIO . groupByOperator =<< getUserServers db user + pure (user, map updatedUserServers uss) + updatedUserServers uss = uss {operator = updatedOp <$> operator' uss} :: UserOperatorServers + updatedOp op = fromMaybe op $ find matchingOp $ mapMaybe operator' userServers + where + matchingOp op' = operatorId op' == operatorId op forwardFile :: ChatName -> FileTransferId -> (ChatName -> CryptoFile -> ChatCommand) -> CM ChatResponse forwardFile chatName fileId sendCommand = withUser $ \user -> do withStore (\db -> getFileTransfer db user fileId) >>= \case diff --git a/src/Simplex/Chat/Operators.hs b/src/Simplex/Chat/Operators.hs index f7a07682f9..1f9b79b56b 100644 --- a/src/Simplex/Chat/Operators.hs +++ b/src/Simplex/Chat/Operators.hs @@ -89,6 +89,8 @@ data DBEntityId' (s :: DBStored) where deriving instance Show (DBEntityId' s) +deriving instance Eq (DBEntityId' s) + type DBEntityId = DBEntityId' 'DBStored type DBNewEntity = DBEntityId' 'DBNew diff --git a/tests/RandomServers.hs b/tests/RandomServers.hs index d0d74724d0..9b83be26c4 100644 --- a/tests/RandomServers.hs +++ b/tests/RandomServers.hs @@ -29,8 +29,6 @@ randomServersTests = describe "choosig random servers" $ do deriving instance Eq ServerRoles -deriving instance Eq (DBEntityId' s) - deriving instance Eq (UserServer' s p) testRandomSMPServers :: IO ()