feat: show loading indicator on login when requesting mailserver messages

This commit is contained in:
Richard Ramos 2020-12-01 13:18:49 -04:00 committed by Iuri Matias
parent a0c4839d48
commit b9d59f44cc
7 changed files with 75 additions and 22 deletions

View File

@ -92,6 +92,7 @@ proc handleMailserverEvents(self: ChatController) =
self.status.mailservers.addMailserverTopic(topic) self.status.mailservers.addMailserverTopic(topic)
if(self.status.mailservers.isActiveMailserverAvailable): if(self.status.mailservers.isActiveMailserverAvailable):
self.view.setLoadingMessages(true)
self.status.mailservers.requestMessages(topics.map(t => t.topic)) self.status.mailservers.requestMessages(topics.map(t => t.topic))
self.status.events.on("mailserverAvailable") do(e:Args): self.status.events.on("mailserverAvailable") do(e:Args):
@ -100,4 +101,6 @@ proc handleMailserverEvents(self: ChatController) =
if mailserverTopics.len > 0: if mailserverTopics.len > 0:
fromValue = min(mailserverTopics.map(topic => topic.lastRequest)) fromValue = min(mailserverTopics.map(topic => topic.lastRequest))
self.view.setLoadingMessages(true)
self.status.mailservers.requestMessages(mailserverTopics.map(t => t.topic), fromValue) self.status.mailservers.requestMessages(mailserverTopics.map(t => t.topic), fromValue)

View File

@ -18,3 +18,14 @@ proc handleSignals(self: ChatController) =
if self.status.messages.messages.hasKey(messageId): if self.status.messages.messages.hasKey(messageId):
let chatId = self.status.messages.messages[messageId].chatId let chatId = self.status.messages.messages[messageId].chatId
self.view.messageList[chatId].checkTimeout(messageId) self.view.messageList[chatId].checkTimeout(messageId)
self.status.events.on(SignalType.MailserverRequestCompleted.event) do(e:Args):
# TODO: if the signal contains a cursor, request additional messages
# else:
self.view.hideLoadingIndicator()
self.status.events.on(SignalType.MailserverRequestExpired.event) do(e:Args):
# TODO: retry mailserver request up to N times or change mailserver
# If > N, then
self.view.hideLoadingIndicator()

View File

@ -497,22 +497,27 @@ QtObject:
self.setLastMessageTimestamp() self.setLastMessageTimestamp()
self.messagesLoaded(); self.messagesLoaded();
proc loadingMessagesChanged*(self: ChatsView) {.signal.} proc loadingMessagesChanged*(self: ChatsView, value: bool) {.signal.}
proc hideLoadingIndicator*(self: ChatsView) {.slot.} = proc hideLoadingIndicator*(self: ChatsView) {.slot.} =
self.loadingMessages = false self.loadingMessages = false
self.loadingMessagesChanged() self.loadingMessagesChanged(false)
proc setLoadingMessages*(self: ChatsView, value: bool) {.slot.} =
self.loadingMessages = value
self.loadingMessagesChanged(value)
proc isLoadingMessages(self: ChatsView): QVariant {.slot.} = proc isLoadingMessages(self: ChatsView): QVariant {.slot.} =
return newQVariant(self.loadingMessages) return newQVariant(self.loadingMessages)
QtProperty[QVariant] loadingMessages: QtProperty[QVariant] loadingMessages:
read = isLoadingMessages read = isLoadingMessages
write = setLoadingMessages
notify = loadingMessagesChanged notify = loadingMessagesChanged
proc requestMoreMessages*(self: ChatsView, fetchRange: int) {.slot.} = proc requestMoreMessages*(self: ChatsView, fetchRange: int) {.slot.} =
self.loadingMessages = true self.loadingMessages = true
self.loadingMessagesChanged() self.loadingMessagesChanged(true)
let topics = self.status.mailservers.getMailserverTopicsByChatId(self.activeChannel.id).map(topic => topic.topic) let topics = self.status.mailservers.getMailserverTopicsByChatId(self.activeChannel.id).map(topic => topic.topic)
let currentOldestMessageTimestamp = self.oldestMessageTimestamp let currentOldestMessageTimestamp = self.oldestMessageTimestamp
self.oldestMessageTimestamp = self.oldestMessageTimestamp - fetchRange self.oldestMessageTimestamp = self.oldestMessageTimestamp - fetchRange

View File

@ -1,6 +1,6 @@
import NimQml, tables, json, chronicles, strutils, json_serialization import NimQml, tables, json, chronicles, strutils, json_serialization
import ../libstatus/types as status_types import ../libstatus/types as status_types
import types, messages, discovery, whisperFilter, envelopes, expired, wallet import types, messages, discovery, whisperFilter, envelopes, expired, wallet, mailserver
import ../status import ../status
import ../../eventemitter import ../../eventemitter
@ -46,24 +46,17 @@ QtObject:
signalType = SignalType.Unknown signalType = SignalType.Unknown
return return
var signal: Signal var signal: Signal = case signalType:
case signalType: of SignalType.Message: messages.fromEvent(jsonSignal)
of SignalType.Message: of SignalType.EnvelopeSent: envelopes.fromEvent(jsonSignal)
signal = messages.fromEvent(jsonSignal) of SignalType.EnvelopeExpired: expired.fromEvent(jsonSignal)
of SignalType.EnvelopeSent: of SignalType.WhisperFilterAdded: whisperFilter.fromEvent(jsonSignal)
signal = envelopes.fromEvent(jsonSignal) of SignalType.Wallet: wallet.fromEvent(jsonSignal)
of SignalType.EnvelopeExpired: of SignalType.NodeLogin: Json.decode($jsonSignal, NodeSignal)
signal = expired.fromEvent(jsonSignal) of SignalType.DiscoverySummary: discovery.fromEvent(jsonSignal)
of SignalType.WhisperFilterAdded: of SignalType.MailserverRequestCompleted: mailserver.fromCompletedEvent(jsonSignal)
signal = whisperFilter.fromEvent(jsonSignal) of SignalType.MailserverRequestExpired: mailserver.fromExpiredEvent(jsonSignal)
of SignalType.Wallet: else: Signal()
signal = wallet.fromEvent(jsonSignal)
of SignalType.NodeLogin:
signal = Json.decode($jsonSignal, NodeSignal)
of SignalType.DiscoverySummary:
signal = discovery.fromEvent(jsonSignal)
else:
discard
self.status.events.emit(signalType.event, signal) self.status.events.emit(signalType.event, signal)

View File

@ -0,0 +1,18 @@
import json
import types
proc fromCompletedEvent*(jsonSignal: JsonNode): Signal =
var signal:MailserverRequestCompletedSignal = MailserverRequestCompletedSignal()
if jsonSignal["event"].kind != JNull:
signal.requestID = jsonSignal["event"]{"requestID"}.getStr()
signal.lastEnvelopeHash = jsonSignal["event"]{"lastEnvelopeHash"}.getStr()
signal.cursor = jsonSignal["event"]{"cursor"}.getStr()
signal.errorMessage = jsonSignal["event"]{"errorMessage"}.getStr()
signal.error = signal.errorMessage != ""
result = signal
proc fromExpiredEvent*(jsonSignal: JsonNode): Signal =
var signal:MailserverRequestExpiredSignal = MailserverRequestExpiredSignal()
# TODO: parse signal
result = signal

View File

@ -33,7 +33,17 @@ type MessageSignal* = ref object of Signal
contacts*: seq[Profile] contacts*: seq[Profile]
installations*: seq[Installation] installations*: seq[Installation]
emojiReactions*: seq[Reaction] emojiReactions*: seq[Reaction]
type MailserverRequestCompletedSignal* = ref object of Signal
requestID*: string
lastEnvelopeHash*: string
cursor*: string
errorMessage*: string
error*: bool
type MailserverRequestExpiredSignal* = ref object of Signal
# TODO
type Filter* = object type Filter* = object
chatId*: string chatId*: string
symKeyId*: string symKeyId*: string

View File

@ -189,7 +189,20 @@ StackLayout {
Layout.preferredHeight: height Layout.preferredHeight: height
color: "transparent" color: "transparent"
Connections {
target: chatsModel
onLoadingMessagesChanged:
if(value){
loadingMessagesIndicator.active = true
} else {
timer.setTimeout(function(){
loadingMessagesIndicator.active = false;
}, 5000);
}
}
Loader { Loader {
id: loadingMessagesIndicator
active: chatsModel.loadingMessages active: chatsModel.loadingMessages
sourceComponent: loadingIndicator sourceComponent: loadingIndicator
anchors.right: parent.right anchors.right: parent.right