core: support closing/re-opening store on chat stop/start (#3132)

* core: support closing/re-opening store on chat stop/start

* update .nix refs

* kotlin: types

* add test

* update simplexmq
This commit is contained in:
Evgeny Poberezkin
2023-09-27 15:26:03 +01:00
committed by GitHub
parent 8709ad6ff3
commit 3c7fc6b0ee
11 changed files with 69 additions and 31 deletions
@@ -516,8 +516,8 @@ object ChatController {
throw Exception("failed to delete the user ${r.responseType} ${r.details}")
}
suspend fun apiStartChat(): Boolean {
val r = sendCmd(CC.StartChat(expire = true))
suspend fun apiStartChat(openDBWithKey: String? = null): Boolean {
val r = sendCmd(CC.StartChat(ChatCtrlCfg(subConns = true, enableExpireCIs = true, startXFTPWorkers = true, openDBWithKey = openDBWithKey)))
when (r) {
is CR.ChatStarted -> return true
is CR.ChatRunning -> return false
@@ -525,8 +525,8 @@ object ChatController {
}
}
suspend fun apiStopChat(): Boolean {
val r = sendCmd(CC.ApiStopChat())
suspend fun apiStopChat(closeStore: Boolean): Boolean {
val r = sendCmd(CC.ApiStopChat(closeStore))
when (r) {
is CR.ChatStopped -> return true
else -> throw Error("failed stopping chat: ${r.responseType} ${r.details}")
@@ -1829,8 +1829,8 @@ 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 ApiStopChat: CC()
class StartChat(val cfg: ChatCtrlCfg): CC()
class ApiStopChat(val closeStore: Boolean): CC()
class SetTempFolder(val tempFolder: String): CC()
class SetFilesFolder(val filesFolder: String): CC()
class ApiSetXFTPConfig(val config: XFTPFileConfig?): CC()
@@ -1933,8 +1933,9 @@ 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 ApiStopChat -> "/_stop"
// is StartChat -> "/_start ${json.encodeToString(cfg)}" // this can be used with the new core
is StartChat -> "/_start subscribe=on expire=${onOff(cfg.enableExpireCIs)} xftp=on"
is ApiStopChat -> if (closeStore) "/_stop close" else "/_stop"
is SetTempFolder -> "/_temp_folder $tempFolder"
is SetFilesFolder -> "/_files_folder $filesFolder"
is ApiSetXFTPConfig -> if (config != null) "/_xftp on ${json.encodeToString(config)}" else "/_xftp off"
@@ -2151,6 +2152,14 @@ sealed class CC {
}
}
@Serializable
data class ChatCtrlCfg (
val subConns: Boolean,
val enableExpireCIs: Boolean,
val startXFTPWorkers: Boolean,
val openDBWithKey: String?
)
@Serializable
data class NewUser(
val profile: Profile?,
@@ -419,7 +419,7 @@ private fun stopChat(m: ChatModel) {
}
suspend fun stopChatAsync(m: ChatModel) {
m.controller.apiStopChat()
m.controller.apiStopChat(false)
m.chatRunning.value = false
}