diff --git a/apps/ios/Shared/Model/SimpleXAPI.swift b/apps/ios/Shared/Model/SimpleXAPI.swift index 442ba2079..6a5de6b25 100644 --- a/apps/ios/Shared/Model/SimpleXAPI.swift +++ b/apps/ios/Shared/Model/SimpleXAPI.swift @@ -211,7 +211,7 @@ func apiDeleteUser(_ userId: Int64, _ delSMPQueues: Bool, viewPwd: String?) asyn } func apiStartChat() throws -> Bool { - let r = chatSendCmdSync(.startChat(subscribe: true, expire: true, xftp: true)) + let r = chatSendCmdSync(.startChat(mainApp: true)) switch r { case .chatStarted: return true case .chatRunning: return false diff --git a/apps/ios/SimpleX NSE/NotificationService.swift b/apps/ios/SimpleX NSE/NotificationService.swift index 5b1988e89..529192423 100644 --- a/apps/ios/SimpleX NSE/NotificationService.swift +++ b/apps/ios/SimpleX NSE/NotificationService.swift @@ -697,7 +697,7 @@ func apiGetActiveUser() -> User? { } func apiStartChat() throws -> Bool { - let r = sendSimpleXCmd(.startChat(subscribe: false, expire: false, xftp: false)) + let r = sendSimpleXCmd(.startChat(mainApp: false)) switch r { case .chatStarted: return true case .chatRunning: return false diff --git a/apps/ios/SimpleXChat/APITypes.swift b/apps/ios/SimpleXChat/APITypes.swift index a199966ba..411a1ab9c 100644 --- a/apps/ios/SimpleXChat/APITypes.swift +++ b/apps/ios/SimpleXChat/APITypes.swift @@ -25,7 +25,7 @@ public enum ChatCommand { case apiMuteUser(userId: Int64) case apiUnmuteUser(userId: Int64) case apiDeleteUser(userId: Int64, delSMPQueues: Bool, viewPwd: String?) - case startChat(subscribe: Bool, expire: Bool, xftp: Bool) + case startChat(mainApp: Bool) case apiStopChat case apiActivateChat(restoreChat: Bool) case apiSuspendChat(timeoutMicroseconds: Int) @@ -154,7 +154,7 @@ public enum ChatCommand { case let .apiMuteUser(userId): return "/_mute user \(userId)" case let .apiUnmuteUser(userId): return "/_unmute user \(userId)" case let .apiDeleteUser(userId, delSMPQueues, viewPwd): return "/_delete user \(userId) del_smp=\(onOff(delSMPQueues))\(maybePwd(viewPwd))" - case let .startChat(subscribe, expire, xftp): return "/_start subscribe=\(onOff(subscribe)) expire=\(onOff(expire)) xftp=\(onOff(xftp))" + case let .startChat(mainApp): return "/_start main=\(onOff(mainApp))" case .apiStopChat: return "/_stop" case let .apiActivateChat(restore): return "/_app activate restore=\(onOff(restore))" case let .apiSuspendChat(timeoutMicroseconds): return "/_app suspend \(timeoutMicroseconds)" diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt index 4af3e3f2e..38f47b8b2 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt @@ -583,7 +583,7 @@ object ChatController { } suspend fun apiStartChat(): Boolean { - val r = sendCmd(null, CC.StartChat(expire = true)) + val r = sendCmd(null, CC.StartChat(mainApp = true)) when (r) { is CR.ChatStarted -> return true is CR.ChatRunning -> return false @@ -2161,7 +2161,7 @@ sealed class CC { class ApiMuteUser(val userId: Long): CC() class ApiUnmuteUser(val userId: Long): CC() class ApiDeleteUser(val userId: Long, val delSMPQueues: Boolean, val viewPwd: String?): CC() - class StartChat(val expire: Boolean): CC() + class StartChat(val mainApp: Boolean): CC() class ApiStopChat: CC() class SetTempFolder(val tempFolder: String): CC() class SetFilesFolder(val filesFolder: String): CC() @@ -2288,7 +2288,7 @@ sealed class CC { is ApiMuteUser -> "/_mute user $userId" is ApiUnmuteUser -> "/_unmute user $userId" is ApiDeleteUser -> "/_delete user $userId del_smp=${onOff(delSMPQueues)}${maybePwd(viewPwd)}" - is StartChat -> "/_start subscribe=on expire=${onOff(expire)} xftp=on" + is StartChat -> "/_start main=${onOff(mainApp)}" is ApiStopChat -> "/_stop" is SetTempFolder -> "/_temp_folder $tempFolder" is SetFilesFolder -> "/_files_folder $filesFolder" diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index eb16a492e..2feb51fc1 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -311,10 +311,10 @@ cfgServers p s = case p of SPSMP -> s.smp SPXFTP -> s.xftp -startChatController :: forall m. ChatMonad' m => Bool -> Bool -> Bool -> m (Async ()) -startChatController subConns enableExpireCIs startXFTPWorkers = do +startChatController :: forall m. ChatMonad' m => Bool -> m (Async ()) +startChatController mainApp = do asks smpAgent >>= resumeAgentClient - unless subConns $ + unless mainApp $ chatWriteVar subscriptionMode SMOnlyCreate users <- fromRight [] <$> runExceptT (withStoreCtx' (Just "startChatController, getUsers") getUsers) restoreCalls @@ -324,15 +324,15 @@ startChatController subConns enableExpireCIs startXFTPWorkers = do start s users = do a1 <- async agentSubscriber a2 <- - if subConns + if mainApp then Just <$> async (subscribeUsers False users) else pure Nothing atomically . writeTVar s $ Just (a1, a2) - when startXFTPWorkers $ do + when mainApp $ do startXFTP void $ forkIO $ startFilesToReceive users - startCleanupManager - when enableExpireCIs $ startExpireCIs users + startCleanupManager + startExpireCIs users pure a1 startXFTP = do tmp <- readTVarIO =<< asks tempDirectory @@ -544,10 +544,10 @@ processChatCommand' vr = \case checkDeleteChatUser user' withChatLock "deleteUser" . procCmd $ deleteChatUser user' delSMPQueues DeleteUser uName delSMPQueues viewPwd_ -> withUserName uName $ \userId -> APIDeleteUser userId delSMPQueues viewPwd_ - StartChat subConns enableExpireCIs startXFTPWorkers -> withUser' $ \_ -> + StartChat mainApp -> withUser' $ \_ -> asks agentAsync >>= readTVarIO >>= \case Just _ -> pure CRChatRunning - _ -> checkStoreNotChanged $ startChatController subConns enableExpireCIs startXFTPWorkers $> CRChatStarted + _ -> checkStoreNotChanged $ startChatController mainApp $> CRChatStarted APIStopChat -> do ask >>= stopChatController pure CRChatStopped @@ -6153,8 +6153,8 @@ chatCommandP = "/_delete user " *> (APIDeleteUser <$> A.decimal <* " del_smp=" <*> onOffP <*> optional (A.space *> jsonP)), "/delete user " *> (DeleteUser <$> displayName <*> pure True <*> optional (A.space *> pwdP)), ("/user" <|> "/u") $> ShowActiveUser, - "/_start subscribe=" *> (StartChat <$> onOffP <* " expire=" <*> onOffP <* " xftp=" <*> onOffP), - "/_start" $> StartChat True True True, + "/_start main=" *> (StartChat <$> onOffP), + "/_start" $> StartChat True, "/_stop" $> APIStopChat, "/_app activate restore=" *> (APIActivateChat <$> onOffP), "/_app activate" $> APIActivateChat True, diff --git a/src/Simplex/Chat/Controller.hs b/src/Simplex/Chat/Controller.hs index b198cccbf..52181b3c9 100644 --- a/src/Simplex/Chat/Controller.hs +++ b/src/Simplex/Chat/Controller.hs @@ -233,7 +233,7 @@ data ChatCommand | UnmuteUser | APIDeleteUser UserId Bool (Maybe UserPwd) | DeleteUser UserName Bool (Maybe UserPwd) - | StartChat {subscribeConnections :: Bool, enableExpireChatItems :: Bool, startXFTPWorkers :: Bool} + | StartChat {mainApp :: Bool} | APIStopChat | APIActivateChat {restoreChat :: Bool} | APISuspendChat {suspendTimeout :: Int} diff --git a/src/Simplex/Chat/Core.hs b/src/Simplex/Chat/Core.hs index 1d870bf38..0444723de 100644 --- a/src/Simplex/Chat/Core.hs +++ b/src/Simplex/Chat/Core.hs @@ -35,7 +35,7 @@ runSimplexChat :: ChatOpts -> User -> ChatController -> (User -> ChatController runSimplexChat ChatOpts {maintenance} u cc chat | maintenance = wait =<< async (chat u cc) | otherwise = do - a1 <- runReaderT (startChatController True True True) cc + a1 <- runReaderT (startChatController True) cc a2 <- async $ chat u cc waitEither_ a1 a2 diff --git a/tests/ChatTests/Direct.hs b/tests/ChatTests/Direct.hs index 64fa6ff3b..a53bbff3d 100644 --- a/tests/ChatTests/Direct.hs +++ b/tests/ChatTests/Direct.hs @@ -1149,7 +1149,7 @@ testSubscribeAppNSE tmp = alice ##> "/_app suspend 1" alice <## "ok" alice <## "chat suspended" - nseAlice ##> "/_start subscribe=off expire=off xftp=off" + nseAlice ##> "/_start main=off" nseAlice <## "chat started" nseAlice ##> "/ad" cLink <- getContactLink nseAlice True