mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-21 20:09:37 +00:00
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))
|
||||
self.channels[chat.id] = chat
|
||||
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] = @[]
|
||||
let parsedResult = parseJson(filterResult)["result"]
|
||||
@ -82,7 +82,7 @@ proc init*(self: ChatModel) =
|
||||
var filters:seq[JsonNode] = @[]
|
||||
for chat in chatList:
|
||||
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.events.emit("channelJoined", ChannelArgs(chat: chat))
|
||||
|
||||
|
@ -3,34 +3,22 @@ import json
|
||||
import utils
|
||||
import times
|
||||
import strutils
|
||||
import sequtils
|
||||
import chronicles
|
||||
import ../chat/[chat, message]
|
||||
import ../../signals/messages
|
||||
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 =
|
||||
if oneToOne:
|
||||
result = %* {
|
||||
"ChatID": chatId, # identifier of the chat
|
||||
"OneToOne": oneToOne, # if asymmetric encryption is used for this chat
|
||||
"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 buildFilter*(chat: Chat):JsonNode =
|
||||
if chat.chatType == ChatType.PrivateGroupChat:
|
||||
return newJNull()
|
||||
result = %* {
|
||||
"ChatID": chat.id,
|
||||
"OneToOne": chat.chatType == ChatType.OneToOne
|
||||
}
|
||||
|
||||
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) =
|
||||
discard callPrivateRPC("removeFilters".prefix, %* [
|
||||
|
Loading…
x
Reference in New Issue
Block a user