From a9ffe4e039babb053bda0d892ff4b22c6670b55f Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 4 Dec 2022 08:36:19 +0000 Subject: [PATCH] android: function to call api on background thread, use it for marking items read (#1493) --- .../app/src/main/java/chat/simplex/app/views/chat/ChatView.kt | 2 +- .../app/src/main/java/chat/simplex/app/views/helpers/Util.kt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/ChatView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/ChatView.kt index a1299f9e7b..2277a6c71b 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/ChatView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/ChatView.kt @@ -217,7 +217,7 @@ fun ChatView(chatId: String, chatModel: ChatModel, onComposed: () -> Unit) { markRead = { range, unreadCountAfter -> chatModel.markChatItemsRead(chat.chatInfo, range, unreadCountAfter) chatModel.controller.ntfManager.cancelNotificationsForChat(chat.id) - withApi { + withBGApi { chatModel.controller.apiChatRead( chat.chatInfo.chatType, chat.chatInfo.apiId, diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/helpers/Util.kt b/apps/android/app/src/main/java/chat/simplex/app/views/helpers/Util.kt index 2490a903bb..337bc7a1ed 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/helpers/Util.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/helpers/Util.kt @@ -40,6 +40,9 @@ fun withApi(action: suspend CoroutineScope.() -> Unit): Job = withScope(GlobalSc fun withScope(scope: CoroutineScope, action: suspend CoroutineScope.() -> Unit): Job = scope.launch { withContext(Dispatchers.Main, action) } +fun withBGApi(action: suspend CoroutineScope.() -> Unit): Job = + CoroutineScope(Dispatchers.Default).launch(block = action) + enum class KeyboardState { Opened, Closed }