removing topics

This commit is contained in:
Richard Ramos 2020-06-02 16:23:04 -04:00 committed by Iuri Matias
parent 24d0306869
commit aaf023015e
1 changed files with 12 additions and 25 deletions

View File

@ -32,14 +32,12 @@ type
events*: EventEmitter events*: EventEmitter
channels*: HashSet[string] channels*: HashSet[string]
filters*: Table[string, string] filters*: Table[string, string]
topics*: seq[string]
proc newChatModel*(events: EventEmitter): ChatModel = proc newChatModel*(events: EventEmitter): ChatModel =
result = ChatModel() result = ChatModel()
result.events = events result.events = events
result.channels = initHashSet[string]() result.channels = initHashSet[string]()
result.filters = initTable[string, string]() result.filters = initTable[string, string]()
result.topics = newSeq[string](0)
proc delete*(self: ChatModel) = proc delete*(self: ChatModel) =
discard discard
@ -52,42 +50,30 @@ proc getActiveChannel*(self: ChatModel): string =
proc join*(self: ChatModel, chatId: string, chatType: ChatType) = proc join*(self: ChatModel, chatId: string, chatType: ChatType) =
if self.hasChannel(chatId): return if self.hasChannel(chatId): return
self.channels.incl chatId self.channels.incl chatId
let generatedSymKey = status_chat.generateSymKeyFromPassword()
#TODO get this from the connection or something
let peer = "enode://44160e22e8b42bd32a06c1532165fa9e096eebedd7fa6d6e5f8bbef0440bc4a4591fe3651be68193a7ec029021cdb496cfe1d7f9f1dc69eb99226e6f39a7a5d4@35.225.221.245:443"
status_chat.saveChat(chatId, chatType.isOneToOne) status_chat.saveChat(chatId, chatType.isOneToOne)
let filterResult = status_chat.loadFilters(@[status_chat.buildFilter(chatId = chatId, oneToOne = chatType.isOneToOne)]) let filterResult = status_chat.loadFilters(@[status_chat.buildFilter(chatId = chatId, oneToOne = chatType.isOneToOne)])
var topics:seq[string] = @[]
let parsedResult = parseJson(filterResult)["result"] let parsedResult = parseJson(filterResult)["result"]
var topics = newSeq[string](0)
for topicObj in parsedResult: for topicObj in parsedResult:
if (($topicObj["chatId"]).strip(chars = {'"'}) == chatId): if ($topicObj["chatId"].getStr == chatId):
topics.add(($topicObj["topic"]).strip(chars = {'"'})) topics.add($topicObj["topic"].getStr)
if(not self.filters.hasKey(chatId)): self.filters[chatId] = topicObj["filterId"].getStr
if(not self.filters.hasKey(chatId)): self.filters[chatId] = topicObj["filterId"].getStr if (topics.len == 0):
warn "No topics found for chats. Cannot load past messages"
if (topics.len == 0):
warn "No topic found for the chat. Cannot load past messages"
else: else:
self.events.emit("mailserverTopics", TopicArgs(topics: topics)); self.events.emit("mailserverTopics", TopicArgs(topics: topics));
self.events.emit("channelJoined", ChannelArgs(channel: chatId, chatTypeInt: chatType)) self.events.emit("channelJoined", ChannelArgs(channel: chatId, chatTypeInt: chatType))
self.events.emit("activeChannelChanged", ChannelArgs(channel: self.getActiveChannel())) self.events.emit("activeChannelChanged", ChannelArgs(channel: self.getActiveChannel()))
proc init*(self: ChatModel) = proc init*(self: ChatModel) =
let chatList = status_chat.loadChats() let chatList = status_chat.loadChats()
let generatedSymKey = status_chat.generateSymKeyFromPassword()
let peer = "enode://c42f368a23fa98ee546fd247220759062323249ef657d26d357a777443aec04db1b29a3a22ef3e7c548e18493ddaf51a31b0aed6079bd6ebe5ae838fcfaf3a49@178.128.142.54:443"
# TODO this is needed for now for the retrieving of past messages. We'll either move or remove it later
status_core.addPeer(peer)
var filters:seq[JsonNode] = @[] var filters:seq[JsonNode] = @[]
for chat in chatList: for chat in chatList:
@ -103,15 +89,16 @@ proc init*(self: ChatModel) =
self.events.emit("chatsLoaded", ChatArgs(chats: chatList)) self.events.emit("chatsLoaded", ChatArgs(chats: chatList))
var topics:seq[string] = @[]
let parsedResult = parseJson(filterResult)["result"] let parsedResult = parseJson(filterResult)["result"]
for topicObj in parsedResult: for topicObj in parsedResult:
self.topics.add($topicObj["topic"].getStr) topics.add($topicObj["topic"].getStr)
self.filters[$topicObj["chatId"].getStr] = topicObj["filterId"].getStr self.filters[$topicObj["chatId"].getStr] = topicObj["filterId"].getStr
if (self.topics.len == 0): if (topics.len == 0):
warn "No topics found for chats. Cannot load past messages" warn "No topics found for chats. Cannot load past messages"
else: else:
self.events.emit("mailserverTopics", TopicArgs(topics: self.topics)); self.events.emit("mailserverTopics", TopicArgs(topics: topics));
proc leave*(self: ChatModel, chatId: string) = proc leave*(self: ChatModel, chatId: string) =