core: prevent making all users inactive when duplicate user is created (#1862)

* core: prevent making all users inactive when duplicate user is created

* skip async group test
This commit is contained in:
Evgeny Poberezkin
2023-01-31 12:24:18 +00:00
committed by GitHub
parent a1ed0a84b8
commit 13bd51b97d
5 changed files with 11 additions and 6 deletions
+5 -2
View File
@@ -273,13 +273,16 @@ toView event = do
processChatCommand :: forall m. ChatMonad m => ChatCommand -> m ChatResponse
processChatCommand = \case
ShowActiveUser -> withUser' $ pure . CRActiveUser
CreateActiveUser p sameServers -> do
CreateActiveUser p@Profile {displayName} sameServers -> do
u <- asks currentUser
(smp, smpServers) <- chooseServers
auId <-
withStore' getUsers >>= \case
[] -> pure 1
_ -> withAgent (`createUser` smp)
users -> do
when (any (\User {localDisplayName = n} -> n == displayName) users) $
throwChatError $ CEUserExists displayName
withAgent (`createUser` smp)
user <- withStore $ \db -> createUserRecord db (AgentUserId auId) p True
unless (null smpServers) $
withStore $ \db -> overwriteSMPServers db user smpServers