feat: updated mailserver logic
This commit is contained in:
parent
62d7fc9853
commit
f86611303f
|
@ -125,31 +125,20 @@ proc handleChatEvents(self: ChatController) =
|
|||
|
||||
proc handleMailserverEvents(self: ChatController) =
|
||||
let mailserverWorker = self.status.tasks.marathon[MailserverWorker().name]
|
||||
|
||||
self.status.events.on("mailserverTopics") do(e: Args):
|
||||
var topics = TopicArgs(e).topics
|
||||
for topic in topics:
|
||||
topic.lastRequest = times.toUnix(times.getTime())
|
||||
let task = AddMailserverTopicTaskArg(
|
||||
`method`: "addMailserverTopic",
|
||||
topic: topic
|
||||
)
|
||||
mailserverWorker.start(task)
|
||||
|
||||
# TODO: test mailserver topics when joining chat
|
||||
|
||||
self.status.events.on("channelJoined") do(e:Args):
|
||||
let task = IsActiveMailserverAvailableTaskArg(
|
||||
`method`: "isActiveMailserverAvailable",
|
||||
vptr: cast[ByteAddress](self.view.vptr),
|
||||
slot: "isActiveMailserverResult",
|
||||
topics: topics
|
||||
slot: "isActiveMailserverResult"
|
||||
)
|
||||
mailserverWorker.start(task)
|
||||
|
||||
self.status.events.on("mailserverAvailable") do(e:Args):
|
||||
discard status_mailservers.requestAllHistoricMessages()
|
||||
let task = GetMailserverTopicsTaskArg(
|
||||
`method`: "getMailserverTopics",
|
||||
let task = RequestMessagesTaskArg(
|
||||
`method`: "requestMessages",
|
||||
vptr: cast[ByteAddress](self.view.vptr),
|
||||
slot: "getMailserverTopicsResult"
|
||||
slot: "requestAllHistoricMessagesResult"
|
||||
)
|
||||
mailserverWorker.start(task)
|
||||
|
||||
|
|
|
@ -116,7 +116,6 @@ QtObject:
|
|||
channelOpenTime*: Table[string, int64]
|
||||
connected: bool
|
||||
unreadMessageCnt: int
|
||||
oldestMessageTimestamp: int64
|
||||
loadingMessages: bool
|
||||
timelineChat: Chat
|
||||
pubKey*: string
|
||||
|
@ -193,39 +192,6 @@ QtObject:
|
|||
else:
|
||||
self.chats.updateChat(channel)
|
||||
|
||||
proc oldestMessageTimestampChanged*(self: ChatsView) {.signal.}
|
||||
|
||||
proc getOldestMessageTimestamp*(self: ChatsView): QVariant {.slot.} =
|
||||
newQVariant($self.oldestMessageTimestamp)
|
||||
|
||||
QtProperty[QVariant] oldestMsgTimestamp:
|
||||
read = getOldestMessageTimestamp
|
||||
notify = oldestMessageTimestampChanged
|
||||
|
||||
proc setLastMessageTimestamp*(self: ChatsView, force = false) =
|
||||
if self.status.chat.lastMessageTimestamps.hasKey(self.activeChannel.id):
|
||||
if force or self.status.chat.lastMessageTimestamps[self.activeChannel.id] <= self.oldestMessageTimestamp:
|
||||
self.oldestMessageTimestamp = self.status.chat.lastMessageTimestamps[self.activeChannel.id]
|
||||
self.oldestMessageTimestampChanged()
|
||||
else:
|
||||
let
|
||||
mailserverWorker = self.status.tasks.marathon[MailserverWorker().name]
|
||||
task = GetMailserverTopicsByChatIdTaskArg(
|
||||
`method`: "getMailserverTopicsByChatId",
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "getMailserverTopicsByChatIdResult",
|
||||
chatId: self.activeChannel.id
|
||||
)
|
||||
mailserverWorker.start(task)
|
||||
|
||||
proc getMailserverTopicsByChatIdResult(self: ChatsView, topicsEncoded: string) {.slot.} =
|
||||
let topicsTuple = decode[tuple[topics: seq[MailserverTopic], fetchRange: int]](topicsEncoded)
|
||||
if topicsTuple.topics.len > 0:
|
||||
self.oldestMessageTimestamp = topicsTuple.topics[0].lastRequest
|
||||
else:
|
||||
self.oldestMessageTimestamp = times.toUnix(times.getTime())
|
||||
self.oldestMessageTimestampChanged()
|
||||
|
||||
proc getChatsList(self: ChatsView): QVariant {.slot.} =
|
||||
newQVariant(self.chats)
|
||||
|
||||
|
@ -417,7 +383,6 @@ QtObject:
|
|||
self.activeChannel.setChatItem(selectedChannel)
|
||||
|
||||
discard self.status.chat.markAllChannelMessagesRead(self.activeChannel.id)
|
||||
self.setLastMessageTimestamp(true)
|
||||
self.activeChannelChanged()
|
||||
|
||||
proc getActiveChannel*(self: ChatsView): QVariant {.slot.} =
|
||||
|
@ -607,8 +572,6 @@ QtObject:
|
|||
trace "Loading more messages", chaId = self.activeChannel.id
|
||||
self.status.chat.chatMessages(self.activeChannel.id, false)
|
||||
self.status.chat.chatReactions(self.activeChannel.id, false)
|
||||
if self.status.chat.msgCursor[self.activeChannel.id] == "":
|
||||
self.setLastMessageTimestamp()
|
||||
self.messagesLoaded();
|
||||
|
||||
proc loadMoreMessagesWithIndex*(self: ChatsView, channelIndex: int) {.slot.} =
|
||||
|
@ -618,7 +581,6 @@ QtObject:
|
|||
trace "Loading more messages", chaId = selectedChannel.id
|
||||
self.status.chat.chatMessages(selectedChannel.id, false)
|
||||
self.status.chat.chatReactions(selectedChannel.id, false)
|
||||
self.setLastMessageTimestamp()
|
||||
self.messagesLoaded();
|
||||
|
||||
proc loadingMessagesChanged*(self: ChatsView, value: bool) {.signal.}
|
||||
|
@ -653,56 +615,15 @@ QtObject:
|
|||
write = setLoadingMessages
|
||||
notify = loadingMessagesChanged
|
||||
|
||||
proc getMailserverTopicsByChatIdResult2(self: ChatsView, topicsEncoded: string) {.slot.} =
|
||||
let
|
||||
topicsTuple = decode[tuple[topics: seq[MailserverTopic], fetchRange: int]](topicsEncoded)
|
||||
currentOldestMessageTimestamp = self.oldestMessageTimestamp
|
||||
self.oldestMessageTimestamp = self.oldestMessageTimestamp - topicsTuple.fetchRange
|
||||
|
||||
let
|
||||
mailserverWorker = self.status.tasks.marathon[MailserverWorker().name]
|
||||
task = RequestMessagesTaskArg(
|
||||
`method`: "requestMessages",
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "requestMessagesResult",
|
||||
topics: topicsTuple.topics.map(topic => topic.topic),
|
||||
fromValue: self.oldestMessageTimestamp,
|
||||
toValue: currentOldestMessageTimestamp,
|
||||
force: true
|
||||
)
|
||||
mailserverWorker.start(task)
|
||||
|
||||
proc requestMoreMessages*(self: ChatsView, fetchRange: int) {.slot.} =
|
||||
self.loadingMessages = true
|
||||
self.loadingMessagesChanged(true)
|
||||
let mailserverWorker = self.status.tasks.marathon[MailserverWorker().name]
|
||||
|
||||
if(self.activeChannel.isTimelineChat):
|
||||
var chatIds: seq[string] = @[]
|
||||
for contact in self.status.contacts.getContacts():
|
||||
chatIds.add(getTimelineChatId(contact.id))
|
||||
|
||||
let task = GetMailserverTopicsByChatIdsTaskArg(
|
||||
`method`: "getMailserverTopicsByChatIds",
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "getMailserverTopicsByChatIdResult2",
|
||||
chatIds: chatIds,
|
||||
fetchRange: fetchRange
|
||||
)
|
||||
mailserverWorker.start(task)
|
||||
else:
|
||||
let task = GetMailserverTopicsByChatIdTaskArg(
|
||||
`method`: "getMailserverTopicsByChatId",
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "getMailserverTopicsByChatIdResult2",
|
||||
chatId: self.activeChannel.id,
|
||||
fetchRange: fetchRange
|
||||
)
|
||||
mailserverWorker.start(task)
|
||||
|
||||
proc requestMessagesResult(self: ChatsView, resultEncoded: string) {.slot.} =
|
||||
self.oldestMessageTimestampChanged()
|
||||
self.messagesLoaded();
|
||||
let task = RequestMessagesTaskArg(
|
||||
`method`: "requestMoreMessages",
|
||||
chatId: self.activeChannel.id
|
||||
)
|
||||
mailserverWorker.start(task)
|
||||
|
||||
proc leaveChatByIndex*(self: ChatsView, channelIndex: int) {.slot.} =
|
||||
if (self.chats.chats.len == 0): return
|
||||
|
@ -711,14 +632,6 @@ QtObject:
|
|||
if (self.activeChannel.id == selectedChannel.id):
|
||||
self.activeChannel.chatItem = nil
|
||||
self.status.chat.leave(selectedChannel.id)
|
||||
let
|
||||
mailserverWorker = self.status.tasks.marathon[MailserverWorker().name]
|
||||
task = DeleteMailserverTopicTaskArg(
|
||||
`method`: "deleteMailserverTopic",
|
||||
chatId: selectedChannel.id
|
||||
)
|
||||
mailserverWorker.start(task)
|
||||
|
||||
|
||||
proc fillGaps*(self: ChatsView, messageId: string) {.slot.} =
|
||||
self.loadingMessages = true
|
||||
|
@ -727,13 +640,6 @@ QtObject:
|
|||
|
||||
proc leaveActiveChat*(self: ChatsView) {.slot.} =
|
||||
self.status.chat.leave(self.activeChannel.id)
|
||||
let
|
||||
mailserverWorker = self.status.tasks.marathon[MailserverWorker().name]
|
||||
task = DeleteMailserverTopicTaskArg(
|
||||
`method`: "deleteMailserverTopic",
|
||||
chatId: self.activeChannel.id
|
||||
)
|
||||
mailserverWorker.start(task)
|
||||
|
||||
proc removeChat*(self: ChatsView, chatId: string) =
|
||||
discard self.chats.removeChatItemFromList(chatId)
|
||||
|
@ -930,34 +836,16 @@ QtObject:
|
|||
return idx
|
||||
|
||||
proc isActiveMailserverResult(self: ChatsView, resultEncoded: string) {.slot.} =
|
||||
let arg = decode[tuple[isActiveMailserverAvailable: bool, topics: seq[MailserverTopic]]](resultEncoded)
|
||||
|
||||
if arg.isActiveMailserverAvailable:
|
||||
let isActiveMailserverAvailable = decode[bool](resultEncoded)
|
||||
if isActiveMailserverAvailable:
|
||||
self.setLoadingMessages(true)
|
||||
let
|
||||
mailserverWorker = self.status.tasks.marathon[MailserverWorker().name]
|
||||
task = RequestMessagesTaskArg(
|
||||
`method`: "requestMessages",
|
||||
topics: arg.topics.map(t => t.topic)
|
||||
)
|
||||
task = RequestMessagesTaskArg(`method`: "requestMessages")
|
||||
mailserverWorker.start(task)
|
||||
|
||||
proc getMailserverTopicsResult(self: ChatsView, resultEncoded: string) {.slot.} =
|
||||
let mailserverTopics = decode[seq[MailserverTopic]](resultEncoded)
|
||||
var fromValue = times.toUnix(times.getTime()) - 86400 # today - 24 hours
|
||||
|
||||
if mailserverTopics.len > 0:
|
||||
fromValue = min(mailserverTopics.map(topic => topic.lastRequest))
|
||||
|
||||
proc requestAllHistoricMessagesResult(self: ChatsView, resultEncoded: string) {.slot.} =
|
||||
self.setLoadingMessages(true)
|
||||
let
|
||||
mailserverWorker = self.status.tasks.marathon[MailserverWorker().name]
|
||||
task = RequestMessagesTaskArg(
|
||||
`method`: "requestMessages",
|
||||
topics: mailserverTopics.map(t => t.topic),
|
||||
fromValue: fromValue
|
||||
)
|
||||
mailserverWorker.start(task)
|
||||
|
||||
proc formatInputStuff(self: ChatsView, regex: Regex, inputText: string): string =
|
||||
var matches: seq[tuple[first, last: int]] = @[(-1, 0)]
|
||||
|
|
|
@ -41,8 +41,6 @@ type
|
|||
CommunityActiveChangedArgs* = ref object of Args
|
||||
active*: bool
|
||||
|
||||
TopicArgs* = ref object of Args
|
||||
topics*: seq[MailserverTopic]
|
||||
|
||||
MsgsLoadedArgs* = ref object of Args
|
||||
messages*: seq[Message]
|
||||
|
@ -130,23 +128,6 @@ proc getActiveChannel*(self: ChatModel): string =
|
|||
|
||||
proc emitTopicAndJoin(self: ChatModel, chat: Chat) =
|
||||
let filterResult = status_chat.loadFilters(@[status_chat.buildFilter(chat)])
|
||||
var topics:seq[MailserverTopic] = @[]
|
||||
let parsedResult = parseJson(filterResult)["result"]
|
||||
for topicObj in parsedResult:
|
||||
if ($topicObj["chatId"].getStr == chat.id):
|
||||
topics.add(MailserverTopic(
|
||||
topic: $topicObj["topic"].getStr,
|
||||
discovery: topicObj["discovery"].getBool,
|
||||
negotiated: topicObj["negotiated"].getBool,
|
||||
chatIds: @[chat.id],
|
||||
lastRequest: 1
|
||||
))
|
||||
|
||||
if (topics.len == 0):
|
||||
warn "No topics found for chats. Cannot load past messages"
|
||||
else:
|
||||
self.events.emit("mailserverTopics", TopicArgs(topics: topics));
|
||||
|
||||
self.events.emit("channelJoined", ChannelArgs(chat: chat))
|
||||
|
||||
|
||||
|
@ -234,30 +215,10 @@ proc init*(self: ChatModel, pubKey: string) =
|
|||
|
||||
self.events.emit("chatsLoaded", ChatArgs(chats: chatList))
|
||||
|
||||
var topics:seq[MailserverTopic] = @[]
|
||||
let parsedResult = parseJson(filterResult)["result"]
|
||||
for filter in parsedResult:
|
||||
# Only add topics for chats the user has joined
|
||||
let topic_chat = filter["chatId"].getStr
|
||||
let identity = filter["identity"].getStr
|
||||
let chatId = if self.channels.hasKey(topic_chat): topic_chat else: "0x" & identity
|
||||
|
||||
if self.channels.hasKey(chatId) and self.channels[chatId].isActive:
|
||||
topics.add(MailserverTopic(
|
||||
topic: $filter["topic"].getStr,
|
||||
discovery: filter["discovery"].getBool,
|
||||
negotiated: filter["negotiated"].getBool,
|
||||
chatIds: @[chatId],
|
||||
lastRequest: 1
|
||||
))
|
||||
|
||||
if (topics.len == 0):
|
||||
warn "No topics found for chats. Cannot load past messages"
|
||||
else:
|
||||
self.events.once("mailserverAvailable") do(a: Args):
|
||||
self.mailserverReady = true
|
||||
self.requestMissingCommunityInfos()
|
||||
self.events.emit("mailserverTopics", TopicArgs(topics: topics));
|
||||
self.events.once("mailserverAvailable") do(a: Args):
|
||||
self.mailserverReady = true
|
||||
self.requestMissingCommunityInfos()
|
||||
|
||||
self.events.on("contactUpdate") do(a: Args):
|
||||
var evArgs = ContactUpdateArgs(a)
|
||||
|
@ -272,7 +233,6 @@ proc leave*(self: ChatModel, chatId: string) =
|
|||
|
||||
discard status_chat.deactivateChat(self.channels[chatId])
|
||||
|
||||
# TODO: REMOVE MAILSERVER TOPIC
|
||||
self.channels.del(chatId)
|
||||
discard status_chat.clearChatHistory(chatId)
|
||||
self.events.emit("channelLeft", ChatIdArg(chatId: chatId))
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
import json, times
|
||||
import core, utils
|
||||
|
||||
type
|
||||
MailserverTopic* = ref object
|
||||
topic*: string
|
||||
discovery*: bool
|
||||
negotiated*: bool
|
||||
chatIds*: seq[string]
|
||||
lastRequest*: int64
|
||||
|
||||
proc ping*(mailservers: seq[string], timeoutMs: int): string =
|
||||
var addresses: seq[string] = @[]
|
||||
for mailserver in mailservers:
|
||||
|
@ -23,45 +15,11 @@ proc update*(peer: string) =
|
|||
proc delete*(peer: string) =
|
||||
discard callPrivateRPC("mailservers_deleteMailserver", %* [peer])
|
||||
|
||||
proc requestMessages*(topics: seq[string], symKeyID: string, peer: string, numberOfMessages: int, fromTimestamp: int64 = 0, toTimestamp: int64 = 0, force: bool = false) =
|
||||
var toValue = times.toUnix(times.getTime())
|
||||
var fromValue = toValue - 86400
|
||||
if fromTimestamp != 0:
|
||||
fromValue = fromTimestamp
|
||||
if toTimestamp != 0:
|
||||
toValue = toTimestamp
|
||||
|
||||
discard callPrivateRPC("requestMessages".prefix, %* [
|
||||
{
|
||||
"topics": topics,
|
||||
"mailServerPeer": peer,
|
||||
"symKeyID": symKeyID,
|
||||
"timeout": 30,
|
||||
"limit": numberOfMessages,
|
||||
"cursor": nil,
|
||||
"from": fromValue,
|
||||
"to": toValue,
|
||||
"force": force
|
||||
}
|
||||
])
|
||||
|
||||
proc requestAllHistoricMessages*(): string =
|
||||
return callPrivateRPC("requestAllHistoricMessages".prefix, %*[])
|
||||
|
||||
proc syncChatFromSyncedFrom*(chatId: string): string =
|
||||
return callPrivateRPC("syncChatFromSyncedFrom".prefix, %*[chatId])
|
||||
|
||||
proc fillGaps*(chatId: string, messageIds: seq[string]): string =
|
||||
return callPrivateRPC("fillGaps".prefix, %*[chatId, messageIds])
|
||||
|
||||
proc getMailserverTopics*(): string =
|
||||
return callPrivateRPC("mailservers_getMailserverTopics", %*[])
|
||||
|
||||
proc addMailserverTopic*(topic: MailserverTopic): string =
|
||||
return callPrivateRPC("mailservers_addMailserverTopic", %*[{
|
||||
"topic": topic.topic,
|
||||
"discovery?": topic.discovery,
|
||||
"negotiated?": topic.negotiated,
|
||||
"chat-ids": topic.chatIds,
|
||||
"last-request": topic.lastRequest
|
||||
}])
|
||||
|
||||
proc deleteMailserverTopic*(topic: string): string =
|
||||
return callPrivateRPC("mailservers_deleteMailserverTopic", %*[topic])
|
||||
|
|
|
@ -36,7 +36,6 @@ type
|
|||
events*: MailserverEvents
|
||||
nodes*: Table[string, MailserverStatus]
|
||||
activeMailserver*: string
|
||||
topics*: HashSet[string]
|
||||
lastConnectionAttempt*: float
|
||||
fleet*: FleetModel
|
||||
|
||||
|
@ -101,12 +100,11 @@ proc connect(self: MailserverModel, enode: string) =
|
|||
# Connected
|
||||
|
||||
if self.nodes.hasKey(enode) and self.nodes[enode] == MailserverStatus.Connected:
|
||||
status_mailservers.update(enode)
|
||||
connected = true
|
||||
else:
|
||||
# Attempt to connect to mailserver by adding it as a peer
|
||||
status_mailservers.update(enode)
|
||||
self.nodes[enode] = MailserverStatus.Connecting
|
||||
addPeer(enode)
|
||||
self.lastConnectionAttempt = cpuTime()
|
||||
|
||||
if connected:
|
||||
|
@ -118,6 +116,7 @@ proc peerSummaryChange*(self: MailserverModel, peers: seq[string]) =
|
|||
# change the status of the nodes the app is connected to
|
||||
# Connected / Disconnected and emit peerConnected / peerDisconnected
|
||||
# events.
|
||||
|
||||
var mailserverAvailable = false
|
||||
for knownPeer in self.nodes.keys:
|
||||
if not peers.contains(knownPeer) and self.nodes[knownPeer] != MailserverStatus.Disconnected:
|
||||
|
@ -139,59 +138,17 @@ proc peerSummaryChange*(self: MailserverModel, peers: seq[string]) =
|
|||
if self.activeMailserver == peer:
|
||||
mailserverAvailable = true
|
||||
|
||||
status_mailservers.update(peer)
|
||||
|
||||
if mailserverAvailable:
|
||||
debug "Mailserver available"
|
||||
self.events.emit("mailserverAvailable", MailserverArgs())
|
||||
|
||||
proc requestMessages*(self: MailserverModel, topics: seq[string], fromValue: int64 = 0, toValue: int64 = 0, force: bool = false) =
|
||||
proc requestMessages*(self: MailserverModel) =
|
||||
debug "Requesting messages from", mailserver=self.activeMailserver
|
||||
let generatedSymKey = status_chat.generateSymKeyFromPassword()
|
||||
status_mailservers.requestMessages(topics, generatedSymKey, self.activeMailserver, 1000, fromValue, toValue, force)
|
||||
discard status_mailservers.requestAllHistoricMessages()
|
||||
|
||||
proc getMailserverTopics*(self: MailserverModel): seq[MailserverTopic] =
|
||||
let response = status_mailservers.getMailserverTopics()
|
||||
let topics = parseJson(response)["result"]
|
||||
var newTopic: MailserverTopic
|
||||
result = @[]
|
||||
if topics.kind != JNull:
|
||||
for topic in topics:
|
||||
newTopic = MailserverTopic(
|
||||
topic: topic["topic"].getStr,
|
||||
discovery: topic["discovery?"].getBool,
|
||||
negotiated: topic["negotiated?"].getBool,
|
||||
lastRequest: topic["last-request"].getInt
|
||||
)
|
||||
if (topic["chat-ids"].kind != JNull):
|
||||
newTopic.chatIds = topic["chat-ids"].to(seq[string])
|
||||
|
||||
result.add(newTopic)
|
||||
|
||||
proc getMailserverTopicsByChatIds*(self: MailserverModel, chatIds: seq[string]): seq[MailServerTopic] =
|
||||
var topics: seq[MailserverTopic] = @[]
|
||||
for chatId in chatIds:
|
||||
let filtered = self.getMailserverTopics().filter(topic => topic.chatIds.contains(chatId))
|
||||
topics = topics.concat(filtered)
|
||||
result = topics
|
||||
|
||||
proc getMailserverTopicsByChatId*(self: MailserverModel, chatId: string): seq[MailServerTopic] =
|
||||
result = self.getMailserverTopics()
|
||||
.filter(topic => topic.chatIds.contains(chatId))
|
||||
|
||||
proc addMailserverTopic*(self: MailserverModel, topic: MailserverTopic) =
|
||||
discard status_mailservers.addMailserverTopic(topic)
|
||||
|
||||
proc deleteMailserverTopic*(self: MailserverModel, chatId: string) =
|
||||
var topics = self.getMailserverTopicsByChatId(chatId)
|
||||
if topics.len == 0:
|
||||
return
|
||||
|
||||
var topic:MailserverTopic = topics[0]
|
||||
if(topic.chatIds.len > 1):
|
||||
discard status_mailservers.addMailserverTopic(topic)
|
||||
else:
|
||||
discard status_mailservers.deleteMailserverTopic(topic.topic)
|
||||
proc requestMoreMessages*(self: MailserverModel, chatId: string) =
|
||||
debug "Requesting more messages from", mailserver=self.activeMailserver, chatId=chatId
|
||||
discard status_mailservers.syncChatFromSyncedFrom(chatId)
|
||||
|
||||
proc findNewMailserver(self: MailserverModel) =
|
||||
warn "Finding a new mailserver..."
|
||||
|
|
|
@ -19,17 +19,11 @@ type
|
|||
MailserverWorker* = ref object of MarathonWorker
|
||||
|
||||
# below are all custom marathon task arg definitions
|
||||
GetMailserverTopicsTaskArg* = ref object of MarathonTaskArg
|
||||
IsActiveMailserverAvailableTaskArg* = ref object of MarathonTaskArg
|
||||
topics*: seq[MailserverTopic]
|
||||
GetActiveMailserverTaskArg* = ref object of MarathonTaskArg
|
||||
RequestMessagesTaskArg* = ref object of MarathonTaskArg
|
||||
topics*: seq[string]
|
||||
fromValue*: int64
|
||||
toValue*: int64
|
||||
force*: bool
|
||||
chatId*: string
|
||||
AddMailserverTopicTaskArg* = ref object of MarathonTaskArg
|
||||
topic*: MailserverTopic
|
||||
PeerSummaryChangeTaskArg* = ref object of MarathonTaskArg
|
||||
peers*: seq[string]
|
||||
GetMailserverTopicsByChatIdTaskArg* = ref object of MarathonTaskArg
|
||||
|
@ -38,8 +32,7 @@ type
|
|||
GetMailserverTopicsByChatIdsTaskArg* = ref object of MarathonTaskArg
|
||||
chatIds*: seq[string]
|
||||
fetchRange*: int
|
||||
DeleteMailserverTopicTaskArg* = ref object of MarathonTaskArg
|
||||
chatId*: string
|
||||
|
||||
|
||||
const
|
||||
WORKER_NAME = "mailserver"
|
||||
|
@ -85,22 +78,24 @@ proc processMessage(mailserverModel: MailserverModel, received: string) =
|
|||
trace "initiating mailserver task", methodName=methodName, messageType=messageType
|
||||
|
||||
case methodName
|
||||
of "getMailserverTopics":
|
||||
let
|
||||
taskArg = decode[GetMailserverTopicsTaskArg](received)
|
||||
output = mailserverModel.getMailserverTopics()
|
||||
taskArg.finish(output)
|
||||
of "requestAllHistoricMessages":
|
||||
let taskArg = decode[RequestMessagesTaskArg](received)
|
||||
mailserverModel.requestMessages()
|
||||
taskArg.finish("") # TODO:
|
||||
|
||||
of "isActiveMailserverAvailable":
|
||||
let
|
||||
taskArg = decode[IsActiveMailserverAvailableTaskArg](received)
|
||||
output = mailserverModel.isActiveMailserverAvailable()
|
||||
payload: tuple[isActiveMailserverAvailable: bool, topics: seq[MailserverTopic]] = (output, taskArg.topics)
|
||||
taskArg.finish(payload)
|
||||
taskArg.finish(output)
|
||||
|
||||
of "requestMessages":
|
||||
let taskArg = decode[RequestMessagesTaskArg](received)
|
||||
mailserverModel.requestMessages(taskArg.topics, taskArg.fromValue, taskArg.toValue, taskArg.force)
|
||||
mailserverModel.requestMessages()
|
||||
|
||||
of "requestMoreMessages":
|
||||
let taskArg = decode[RequestMessagesTaskArg](received)
|
||||
mailserverModel.requestMoreMessages(taskArg.chatId)
|
||||
|
||||
of "getActiveMailserver":
|
||||
let
|
||||
|
@ -108,32 +103,10 @@ proc processMessage(mailserverModel: MailserverModel, received: string) =
|
|||
output = mailserverModel.getActiveMailserver()
|
||||
taskArg.finish(output)
|
||||
|
||||
of "getMailserverTopicsByChatId":
|
||||
let
|
||||
taskArg = decode[GetMailserverTopicsByChatIdTaskArg](received)
|
||||
output = mailserverModel.getMailserverTopicsByChatId(taskArg.chatId)
|
||||
payload: tuple[topics: seq[MailserverTopic], fetchRange: int] = (output, taskArg.fetchRange)
|
||||
taskArg.finish(payload)
|
||||
|
||||
of "getMailserverTopicsByChatIds":
|
||||
let
|
||||
taskArg = decode[GetMailserverTopicsByChatIdsTaskArg](received)
|
||||
output = mailserverModel.getMailserverTopicsByChatIds(taskArg.chatIds)
|
||||
payload: tuple[topics: seq[MailserverTopic], fetchRange: int] = (output, taskArg.fetchRange)
|
||||
taskArg.finish(payload)
|
||||
|
||||
of "addMailserverTopic":
|
||||
let taskArg = decode[AddMailserverTopicTaskArg](received)
|
||||
mailserverModel.addMailserverTopic(taskArg.topic)
|
||||
|
||||
of "peerSummaryChange":
|
||||
let taskArg = decode[PeerSummaryChangeTaskArg](received)
|
||||
mailserverModel.peerSummaryChange(taskArg.peers)
|
||||
|
||||
of "deleteMailserverTopic":
|
||||
let taskArg = decode[DeleteMailserverTopicTaskArg](received)
|
||||
mailserverModel.deleteMailserverTopic(taskArg.chatId)
|
||||
|
||||
else:
|
||||
error "unknown message", message=received
|
||||
|
||||
|
|
|
@ -345,6 +345,12 @@ ScrollView {
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
nextMessageIndex: {
|
||||
if (msgDelegate.DelegateModel.itemsIndex <= 1) {
|
||||
return -1
|
||||
}
|
||||
return messageListDelegate.items.get(msgDelegate.DelegateModel.itemsIndex - 1).model.index
|
||||
}
|
||||
scrollToBottom: chatLogView.scrollToBottom
|
||||
timeout: model.timeout
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import QtQuick 2.13
|
||||
import "../../../../shared"
|
||||
import "../../../../shared/status"
|
||||
import "../../../../shared/status/core"
|
||||
import "../../../../imports"
|
||||
import "./MessageComponents"
|
||||
import "../components"
|
||||
|
@ -22,6 +24,7 @@ Item {
|
|||
property string messageId: ""
|
||||
property string emojiReactions: ""
|
||||
property int prevMessageIndex: -1
|
||||
property int nextMessageIndex: -1
|
||||
property bool timeout: false
|
||||
property bool hasMention: false
|
||||
property string linkUrls: ""
|
||||
|
@ -51,6 +54,8 @@ Item {
|
|||
property string authorPrevMsg: "authorPrevMsg"
|
||||
|
||||
property string prevMsgTimestamp: chatsModel.messageList.getMessageData(prevMessageIndex, "timestamp")
|
||||
property string nextMsgTimestamp: chatsModel.messageList.getMessageData(nextMessageIndex, "timestamp")
|
||||
|
||||
property bool shouldRepeatHeader: ((parseInt(timestamp, 10) - parseInt(prevMsgTimestamp, 10)) / 60 / 1000) > Constants.repeatHeaderInterval
|
||||
|
||||
property bool isEmoji: contentType === Constants.emojiType
|
||||
|
@ -181,16 +186,6 @@ Item {
|
|||
}
|
||||
|
||||
Loader {
|
||||
active: {
|
||||
if (contentType === Constants.fetchMoreMessagesButton) {
|
||||
const gapNowAndOldestTimestamp = Date.now() / 1000 - chatsModel.oldestMsgTimestamp
|
||||
return gapNowAndOldestTimestamp < Constants.maxNbDaysToFetch * Constants.fetchRangeLast24Hours &&
|
||||
(chatsModel.activeChannel.chatType !== Constants.chatTypePrivateGroupChat || chatsModel.activeChannel.isMember)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
width: parent.width
|
||||
sourceComponent: {
|
||||
switch(contentType) {
|
||||
|
@ -272,6 +267,20 @@ Item {
|
|||
Separator {
|
||||
id: sep1
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: fetchLoaderIndicator
|
||||
anchors.top: sep1.bottom
|
||||
anchors.topMargin: Style.current.padding
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
active: false
|
||||
sourceComponent: StatusLoadingIndicator {
|
||||
width: 12
|
||||
height: 12
|
||||
}
|
||||
}
|
||||
|
||||
StyledText {
|
||||
id: fetchMoreButton
|
||||
font.weight: Font.Medium
|
||||
|
@ -288,8 +297,14 @@ Item {
|
|||
anchors.fill: parent
|
||||
onClicked: {
|
||||
chatsModel.requestMoreMessages(Constants.fetchRangeLast24Hours);
|
||||
fetchLoaderIndicator.active = true;
|
||||
fetchMoreButton.visible = false;
|
||||
fetchDate.visible = false;
|
||||
timer.setTimeout(function(){
|
||||
chatsModel.hideLoadingIndicator()
|
||||
chatsModel.hideLoadingIndicator();
|
||||
fetchLoaderIndicator.active = false;
|
||||
fetchMoreButton.visible = true;
|
||||
fetchDate.visible = true;
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
|
@ -302,7 +317,7 @@ Item {
|
|||
horizontalAlignment: Text.AlignHCenter
|
||||
color: Style.current.secondaryText
|
||||
//% "before %1"
|
||||
text: qsTrId("before--1").arg(new Date(chatsModel.oldestMsgTimestamp*1000).toDateString())
|
||||
text: qsTrId("before--1").arg((nextMessageIndex > -1 ? new Date(nextMsgTimestamp * 1) : new Date()).toLocaleString(Qt.locale(globalSettings.locale)))
|
||||
}
|
||||
Separator {
|
||||
anchors.top: fetchDate.bottom
|
||||
|
|
Loading…
Reference in New Issue