android: function to call api on background thread, use it for marking items read (#1493)

This commit is contained in:
Evgeny Poberezkin
2022-12-04 08:36:19 +00:00
committed by GitHub
parent bf2129c4ae
commit a9ffe4e039
2 changed files with 4 additions and 1 deletions

View File

@@ -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,

View File

@@ -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
}