Ask mailserver messages when joining a channel
This commit is contained in:
parent
aaf023015e
commit
61b70fb969
|
@ -50,6 +50,8 @@ proc handleChatEvents(self: ChatController) =
|
|||
proc handleMailserverEvents(self: ChatController) =
|
||||
self.status.events.on("mailserverTopics") do(e: Args):
|
||||
self.status.mailservers.addTopics(TopicArgs(e).topics)
|
||||
if(self.status.mailservers.isSelectedMailserverAvailable):
|
||||
self.status.mailservers.requestMessages()
|
||||
|
||||
self.status.events.on("mailserverAvailable") do(e:Args):
|
||||
self.status.mailservers.requestMessages()
|
||||
|
|
|
@ -6,6 +6,7 @@ import tables
|
|||
import sets
|
||||
import chronicles
|
||||
import eventemitter
|
||||
import sequtils
|
||||
|
||||
|
||||
logScope:
|
||||
|
@ -26,7 +27,7 @@ type
|
|||
events*: EventEmitter
|
||||
nodes*: Table[string, MailserverStatus]
|
||||
selectedMailserver*: string
|
||||
topics*: seq[string]
|
||||
topics*: HashSet[string]
|
||||
|
||||
|
||||
proc cmpMailserverReply(x, y: (string, int)): int =
|
||||
|
@ -41,10 +42,10 @@ proc newMailserverModel*(events: EventEmitter): MailserverModel =
|
|||
result.events = events
|
||||
result.nodes = initTable[string, MailserverStatus]()
|
||||
result.selectedMailserver = ""
|
||||
result.topics = @[]
|
||||
result.topics = initHashSet[string]()
|
||||
|
||||
proc addTopics*(self: MailserverModel, topics: seq[string]) =
|
||||
self.topics = self.topics & topics
|
||||
for t in topics: self.topics.incl(t)
|
||||
|
||||
proc trustPeer*(self: MailserverModel, enode:string) =
|
||||
markTrustedPeer(enode)
|
||||
|
@ -57,6 +58,9 @@ proc selectedServerStatus*(self: MailserverModel): MailserverStatus =
|
|||
if self.selectedMailserver == "": MailserverStatus.Unknown
|
||||
else: self.nodes[self.selectedMailserver]
|
||||
|
||||
proc isSelectedMailserverAvailable*(self:MailserverModel): bool =
|
||||
self.nodes[self.selectedMailserver] == MailserverStatus.Trusted
|
||||
|
||||
proc connect*(self: MailserverModel, enode: string) =
|
||||
debug "Connecting to mailserver", enode
|
||||
self.selectedMailserver = enode
|
||||
|
@ -117,5 +121,5 @@ proc init*(self: MailserverModel) =
|
|||
proc requestMessages*(self: MailserverModel) =
|
||||
debug "Requesting messages from", mailserver=self.selectedMailserver
|
||||
let generatedSymKey = status_chat.generateSymKeyFromPassword()
|
||||
status_chat.requestMessages(self.topics, generatedSymKey, self.selectedMailserver, 1000)
|
||||
status_chat.requestMessages(toSeq(self.topics), generatedSymKey, self.selectedMailserver, 1000)
|
||||
|
||||
|
|
Loading…
Reference in New Issue