feat: show loading indicator on login when requesting mailserver messages
This commit is contained in:
parent
a0c4839d48
commit
b9d59f44cc
|
@ -92,6 +92,7 @@ proc handleMailserverEvents(self: ChatController) =
|
|||
self.status.mailservers.addMailserverTopic(topic)
|
||||
|
||||
if(self.status.mailservers.isActiveMailserverAvailable):
|
||||
self.view.setLoadingMessages(true)
|
||||
self.status.mailservers.requestMessages(topics.map(t => t.topic))
|
||||
|
||||
self.status.events.on("mailserverAvailable") do(e:Args):
|
||||
|
@ -100,4 +101,6 @@ proc handleMailserverEvents(self: ChatController) =
|
|||
|
||||
if mailserverTopics.len > 0:
|
||||
fromValue = min(mailserverTopics.map(topic => topic.lastRequest))
|
||||
|
||||
self.view.setLoadingMessages(true)
|
||||
self.status.mailservers.requestMessages(mailserverTopics.map(t => t.topic), fromValue)
|
||||
|
|
|
@ -18,3 +18,14 @@ proc handleSignals(self: ChatController) =
|
|||
if self.status.messages.messages.hasKey(messageId):
|
||||
let chatId = self.status.messages.messages[messageId].chatId
|
||||
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()
|
||||
|
|
@ -497,22 +497,27 @@ QtObject:
|
|||
self.setLastMessageTimestamp()
|
||||
self.messagesLoaded();
|
||||
|
||||
proc loadingMessagesChanged*(self: ChatsView) {.signal.}
|
||||
proc loadingMessagesChanged*(self: ChatsView, value: bool) {.signal.}
|
||||
|
||||
proc hideLoadingIndicator*(self: ChatsView) {.slot.} =
|
||||
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.} =
|
||||
return newQVariant(self.loadingMessages)
|
||||
|
||||
QtProperty[QVariant] loadingMessages:
|
||||
read = isLoadingMessages
|
||||
write = setLoadingMessages
|
||||
notify = loadingMessagesChanged
|
||||
|
||||
proc requestMoreMessages*(self: ChatsView, fetchRange: int) {.slot.} =
|
||||
self.loadingMessages = true
|
||||
self.loadingMessagesChanged()
|
||||
self.loadingMessagesChanged(true)
|
||||
let topics = self.status.mailservers.getMailserverTopicsByChatId(self.activeChannel.id).map(topic => topic.topic)
|
||||
let currentOldestMessageTimestamp = self.oldestMessageTimestamp
|
||||
self.oldestMessageTimestamp = self.oldestMessageTimestamp - fetchRange
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import NimQml, tables, json, chronicles, strutils, json_serialization
|
||||
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 ../../eventemitter
|
||||
|
||||
|
@ -46,24 +46,17 @@ QtObject:
|
|||
signalType = SignalType.Unknown
|
||||
return
|
||||
|
||||
var signal: Signal
|
||||
case signalType:
|
||||
of SignalType.Message:
|
||||
signal = messages.fromEvent(jsonSignal)
|
||||
of SignalType.EnvelopeSent:
|
||||
signal = envelopes.fromEvent(jsonSignal)
|
||||
of SignalType.EnvelopeExpired:
|
||||
signal = expired.fromEvent(jsonSignal)
|
||||
of SignalType.WhisperFilterAdded:
|
||||
signal = whisperFilter.fromEvent(jsonSignal)
|
||||
of SignalType.Wallet:
|
||||
signal = wallet.fromEvent(jsonSignal)
|
||||
of SignalType.NodeLogin:
|
||||
signal = Json.decode($jsonSignal, NodeSignal)
|
||||
of SignalType.DiscoverySummary:
|
||||
signal = discovery.fromEvent(jsonSignal)
|
||||
else:
|
||||
discard
|
||||
var signal: Signal = case signalType:
|
||||
of SignalType.Message: messages.fromEvent(jsonSignal)
|
||||
of SignalType.EnvelopeSent: envelopes.fromEvent(jsonSignal)
|
||||
of SignalType.EnvelopeExpired: expired.fromEvent(jsonSignal)
|
||||
of SignalType.WhisperFilterAdded: whisperFilter.fromEvent(jsonSignal)
|
||||
of SignalType.Wallet: wallet.fromEvent(jsonSignal)
|
||||
of SignalType.NodeLogin: Json.decode($jsonSignal, NodeSignal)
|
||||
of SignalType.DiscoverySummary: discovery.fromEvent(jsonSignal)
|
||||
of SignalType.MailserverRequestCompleted: mailserver.fromCompletedEvent(jsonSignal)
|
||||
of SignalType.MailserverRequestExpired: mailserver.fromExpiredEvent(jsonSignal)
|
||||
else: Signal()
|
||||
|
||||
self.status.events.emit(signalType.event, signal)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
@ -34,6 +34,16 @@ type MessageSignal* = ref object of Signal
|
|||
installations*: seq[Installation]
|
||||
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
|
||||
chatId*: string
|
||||
symKeyId*: string
|
||||
|
|
|
@ -189,7 +189,20 @@ StackLayout {
|
|||
Layout.preferredHeight: height
|
||||
color: "transparent"
|
||||
|
||||
Connections {
|
||||
target: chatsModel
|
||||
onLoadingMessagesChanged:
|
||||
if(value){
|
||||
loadingMessagesIndicator.active = true
|
||||
} else {
|
||||
timer.setTimeout(function(){
|
||||
loadingMessagesIndicator.active = false;
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: loadingMessagesIndicator
|
||||
active: chatsModel.loadingMessages
|
||||
sourceComponent: loadingIndicator
|
||||
anchors.right: parent.right
|
||||
|
|
Loading…
Reference in New Issue