From cd423336e1bcaa88768b15a62bcb16b820529afc Mon Sep 17 00:00:00 2001 From: Andrei Smirnov Date: Wed, 14 Jul 2021 13:10:08 +0300 Subject: [PATCH] fix(@desktop): windows application unresponsive when fetching Status updates --- src/app/chat/views/messages.nim | 8 +++++--- src/status/tasks/marathon/mailserver/model.nim | 4 ++++ src/status/tasks/marathon/mailserver/worker.nim | 7 +++++++ ui/app/AppLayouts/Timeline/TimelineLayout.qml | 9 +++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/app/chat/views/messages.nim b/src/app/chat/views/messages.nim index d3c856c268..28192d0192 100644 --- a/src/app/chat/views/messages.nim +++ b/src/app/chat/views/messages.nim @@ -9,6 +9,7 @@ import ../../../status/utils as status_utils import ../../../status/chat/[chat, message] import ../../../status/profile/profile import ../../../status/tasks/[qt, task_runner_impl] +import ../../../status/tasks/marathon/mailserver/worker import communities, chat_item, channels_list, communities, community_list, message_list, channel, message_item @@ -375,9 +376,10 @@ QtObject: notify = loadingMessagesChanged proc fillGaps*(self: MessageView, messageId: string) {.slot.} = - self.loadingMessages = true - self.loadingMessagesChanged(true) - discard self.status.mailservers.fillGaps(self.channelView.activeChannel.id, @[messageId]) + self.setLoadingMessages(true) + let mailserverWorker = self.status.tasks.marathon[MailserverWorker().name] + let task = FillGapsTaskArg( `method`: "fillGaps", chatId: self.channelView.activeChannel.id, messageIds: @[messageId]) + mailserverWorker.start(task) proc unreadMessages*(self: MessageView): int {.slot.} = result = self.unreadMessageCnt diff --git a/src/status/tasks/marathon/mailserver/model.nim b/src/status/tasks/marathon/mailserver/model.nim index f11ef8f3e3..183f4a0421 100644 --- a/src/status/tasks/marathon/mailserver/model.nim +++ b/src/status/tasks/marathon/mailserver/model.nim @@ -150,6 +150,10 @@ proc requestMoreMessages*(self: MailserverModel, chatId: string) = debug "Requesting more messages from", mailserver=self.activeMailserver, chatId=chatId discard status_mailservers.syncChatFromSyncedFrom(chatId) +proc fillGaps*(self: MailserverModel, chatId: string, messageIds: seq[string]) = + debug "Requesting fill gaps from", mailserver=self.activeMailserver, chatId=chatId + discard status_mailservers.fillGaps(chatId, messageIds) + proc findNewMailserver(self: MailserverModel) = warn "Finding a new mailserver..." diff --git a/src/status/tasks/marathon/mailserver/worker.nim b/src/status/tasks/marathon/mailserver/worker.nim index 51419786cc..9896f869ce 100644 --- a/src/status/tasks/marathon/mailserver/worker.nim +++ b/src/status/tasks/marathon/mailserver/worker.nim @@ -23,6 +23,9 @@ type GetActiveMailserverTaskArg* = ref object of MarathonTaskArg RequestMessagesTaskArg* = ref object of MarathonTaskArg chatId*: string + FillGapsTaskArg* = ref object of MarathonTaskArg + chatId*: string + messageIds*: seq[string] AddMailserverTopicTaskArg* = ref object of MarathonTaskArg PeerSummaryChangeTaskArg* = ref object of MarathonTaskArg peers*: seq[string] @@ -97,6 +100,10 @@ proc processMessage(mailserverModel: MailserverModel, received: string) = let taskArg = decode[RequestMessagesTaskArg](received) mailserverModel.requestMoreMessages(taskArg.chatId) + of "fillGaps": + let taskArg = decode[FillGapsTaskArg](received) + mailserverModel.fillGaps(taskArg.chatId, taskArg.messageIds) + of "getActiveMailserver": let taskArg = decode[GetActiveMailserverTaskArg](received) diff --git a/ui/app/AppLayouts/Timeline/TimelineLayout.qml b/ui/app/AppLayouts/Timeline/TimelineLayout.qml index 375dbff28b..cb83c3c88b 100644 --- a/ui/app/AppLayouts/Timeline/TimelineLayout.qml +++ b/ui/app/AppLayouts/Timeline/TimelineLayout.qml @@ -164,5 +164,14 @@ ScrollView { timeout: model.timeout } } + + Loader { + active: chatsModel.messageView.loadingMessages + sourceComponent: LoadingAnimation {} + anchors.right: timelineContainer.right + anchors.top: statusUpdateInput.bottom + anchors.rightMargin: Style.current.padding + anchors.topMargin: Style.current.padding + } } }