fix: buildFilter
This commit is contained in:
parent
d7f9120840
commit
0ca50b4e06
|
@ -59,7 +59,7 @@ proc join*(self: ChatModel, chatId: string, chatType: ChatType) =
|
||||||
var chat = newChat(chatId, ChatType(chatType))
|
var chat = newChat(chatId, ChatType(chatType))
|
||||||
self.channels[chat.id] = chat
|
self.channels[chat.id] = chat
|
||||||
status_chat.saveChat(chatId, chatType.isOneToOne, true, chat.color)
|
status_chat.saveChat(chatId, chatType.isOneToOne, true, chat.color)
|
||||||
let filterResult = status_chat.loadFilters(@[status_chat.buildFilter(chatId = chatId, oneToOne = chatType.isOneToOne)])
|
let filterResult = status_chat.loadFilters(@[status_chat.buildFilter(chat)])
|
||||||
|
|
||||||
var topics:seq[string] = @[]
|
var topics:seq[string] = @[]
|
||||||
let parsedResult = parseJson(filterResult)["result"]
|
let parsedResult = parseJson(filterResult)["result"]
|
||||||
|
@ -82,7 +82,7 @@ proc init*(self: ChatModel) =
|
||||||
var filters:seq[JsonNode] = @[]
|
var filters:seq[JsonNode] = @[]
|
||||||
for chat in chatList:
|
for chat in chatList:
|
||||||
if self.hasChannel(chat.id): continue
|
if self.hasChannel(chat.id): continue
|
||||||
filters.add status_chat.buildFilter(chatId = chat.id, oneToOne = chat.chatType.isOneToOne)
|
filters.add status_chat.buildFilter(chat)
|
||||||
self.channels[chat.id] = chat
|
self.channels[chat.id] = chat
|
||||||
self.events.emit("channelJoined", ChannelArgs(chat: chat))
|
self.events.emit("channelJoined", ChannelArgs(chat: chat))
|
||||||
|
|
||||||
|
|
|
@ -3,34 +3,22 @@ import json
|
||||||
import utils
|
import utils
|
||||||
import times
|
import times
|
||||||
import strutils
|
import strutils
|
||||||
|
import sequtils
|
||||||
import chronicles
|
import chronicles
|
||||||
import ../chat/[chat, message]
|
import ../chat/[chat, message]
|
||||||
import ../../signals/messages
|
import ../../signals/messages
|
||||||
import ../profile
|
import ../profile
|
||||||
|
|
||||||
proc buildFilter*(chatId: string, filterId: string = "", symKeyId: string = "", oneToOne: bool = false, identity: string = "", topic: string = "", discovery: bool = false, negotiated: bool = false, listen: bool = true):JsonNode =
|
proc buildFilter*(chat: Chat):JsonNode =
|
||||||
if oneToOne:
|
if chat.chatType == ChatType.PrivateGroupChat:
|
||||||
|
return newJNull()
|
||||||
result = %* {
|
result = %* {
|
||||||
"ChatID": chatId, # identifier of the chat
|
"ChatID": chat.id,
|
||||||
"OneToOne": oneToOne, # if asymmetric encryption is used for this chat
|
"OneToOne": chat.chatType == ChatType.OneToOne
|
||||||
"Identity": identity, # public key of the other recipient for non-public filters.
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
result = %* {
|
|
||||||
"ChatID": chatId, # identifier of the chat
|
|
||||||
"FilterID": filterId, # whisper filter id generated
|
|
||||||
"SymKeyID": symKeyId, # symmetric key id used for symmetric filters
|
|
||||||
"OneToOne": oneToOne, # if asymmetric encryption is used for this chat
|
|
||||||
"Identity": identity, # public key of the other recipient for non-public filters.
|
|
||||||
# FIXME: passing empty string to the topic makes it error
|
|
||||||
# "Topic": topic, # whisper topic
|
|
||||||
"Discovery": discovery,
|
|
||||||
"Negotiated": negotiated,
|
|
||||||
"Listen": listen # whether we are actually listening for messages on this chat, or the filter is only created in order to be able to post on the topic
|
|
||||||
}
|
}
|
||||||
|
|
||||||
proc loadFilters*(filters: seq[JsonNode]): string =
|
proc loadFilters*(filters: seq[JsonNode]): string =
|
||||||
result = callPrivateRPC("loadFilters".prefix, %* [filters])
|
result = callPrivateRPC("loadFilters".prefix, %* [filter(filters, proc(x:JsonNode):bool = x.kind != JNull)])
|
||||||
|
|
||||||
proc removeFilters*(chatId: string, filterId: string) =
|
proc removeFilters*(chatId: string, filterId: string) =
|
||||||
discard callPrivateRPC("removeFilters".prefix, %* [
|
discard callPrivateRPC("removeFilters".prefix, %* [
|
||||||
|
|
Loading…
Reference in New Issue