From 0ca50b4e066ad68144338d13db8925e16bdd589c Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Sat, 13 Jun 2020 15:04:19 -0400 Subject: [PATCH] fix: buildFilter --- src/status/chat.nim | 4 ++-- src/status/libstatus/chat.nim | 30 +++++++++--------------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/status/chat.nim b/src/status/chat.nim index 01d6527c34..0c867f223f 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -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)) diff --git a/src/status/libstatus/chat.nim b/src/status/libstatus/chat.nim index 68eda4b5a5..2876028c6e 100644 --- a/src/status/libstatus/chat.nim +++ b/src/status/libstatus/chat.nim @@ -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, %* [