fix: allow receiving 1:1 messages after deleting chats
This commit is contained in:
parent
f52ae4f994
commit
ccb43acd85
|
@ -73,7 +73,6 @@ QtObject:
|
||||||
|
|
||||||
proc upsertChannel(self: ChannelsList, channel: Chat): int =
|
proc upsertChannel(self: ChannelsList, channel: Chat): int =
|
||||||
let idx = self.chats.findIndexById(channel.id)
|
let idx = self.chats.findIndexById(channel.id)
|
||||||
if not channel.active: return -1
|
|
||||||
|
|
||||||
if idx == -1:
|
if idx == -1:
|
||||||
result = self.addChatItemToList(channel)
|
result = self.addChatItemToList(channel)
|
||||||
|
|
|
@ -42,7 +42,7 @@ proc newChat*(id: string, chatType: ChatType): Chat =
|
||||||
result = Chat(
|
result = Chat(
|
||||||
id: id,
|
id: id,
|
||||||
color: channelColors[rand(channelColors.len - 1)],
|
color: channelColors[rand(channelColors.len - 1)],
|
||||||
active: true,
|
isActive: true,
|
||||||
chatType: chatType,
|
chatType: chatType,
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
lastClockValue: 0,
|
lastClockValue: 0,
|
||||||
|
@ -62,7 +62,7 @@ proc toChat*(jsonChat: JsonNode): Chat =
|
||||||
name: jsonChat{"name"}.getStr,
|
name: jsonChat{"name"}.getStr,
|
||||||
identicon: "",
|
identicon: "",
|
||||||
color: jsonChat{"color"}.getStr,
|
color: jsonChat{"color"}.getStr,
|
||||||
active: jsonChat{"active"}.getBool,
|
isActive: jsonChat{"active"}.getBool,
|
||||||
chatType: ChatType(jsonChat{"chatType"}.getInt),
|
chatType: ChatType(jsonChat{"chatType"}.getInt),
|
||||||
timestamp: jsonChat{"timestamp"}.getBiggestInt,
|
timestamp: jsonChat{"timestamp"}.getBiggestInt,
|
||||||
lastClockValue: jsonChat{"lastClockValue"}.getBiggestInt,
|
lastClockValue: jsonChat{"lastClockValue"}.getBiggestInt,
|
||||||
|
|
|
@ -45,8 +45,7 @@ proc delete*(self: ChatModel) =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc update*(self: ChatModel, chat: Chat) =
|
proc update*(self: ChatModel, chat: Chat) =
|
||||||
if chat.active:
|
self.channels[chat.id] = chat
|
||||||
self.channels[chat.id] = chat
|
|
||||||
|
|
||||||
proc hasChannel*(self: ChatModel, chatId: string): bool =
|
proc hasChannel*(self: ChatModel, chatId: string): bool =
|
||||||
self.channels.hasKey(chatId)
|
self.channels.hasKey(chatId)
|
||||||
|
@ -108,10 +107,11 @@ proc leave*(self: ChatModel, chatId: string) =
|
||||||
if self.channels[chatId].chatType == ChatType.PrivateGroupChat:
|
if self.channels[chatId].chatType == ChatType.PrivateGroupChat:
|
||||||
discard status_chat.leaveGroupChat(chatId)
|
discard status_chat.leaveGroupChat(chatId)
|
||||||
|
|
||||||
if self.filters.hasKey(chatId):
|
# We still want to be able to receive messages unless we block the 1:1 sender
|
||||||
|
if self.filters.hasKey(chatId) and self.channels[chatId].chatType == ChatType.Public:
|
||||||
status_chat.removeFilters(chatId, self.filters[chatId])
|
status_chat.removeFilters(chatId, self.filters[chatId])
|
||||||
|
|
||||||
status_chat.deactivateChat(chatId)
|
status_chat.deactivateChat(self.channels[chatId])
|
||||||
# TODO: REMOVE MAILSERVER TOPIC
|
# TODO: REMOVE MAILSERVER TOPIC
|
||||||
# TODO: REMOVE HISTORY
|
# TODO: REMOVE HISTORY
|
||||||
self.filters.del(chatId)
|
self.filters.del(chatId)
|
||||||
|
|
|
@ -20,7 +20,7 @@ type Chat* = ref object
|
||||||
name*: string
|
name*: string
|
||||||
color*: string
|
color*: string
|
||||||
identicon*: string
|
identicon*: string
|
||||||
active*: bool # indicates whether the chat has been soft deleted
|
isActive*: bool # indicates whether the chat has been soft deleted
|
||||||
chatType*: ChatType
|
chatType*: ChatType
|
||||||
timestamp*: int64 # indicates the last time this chat has received/sent a message
|
timestamp*: int64 # indicates the last time this chat has received/sent a message
|
||||||
lastClockValue*: int64 # indicates the last clock value to be used when sending messages
|
lastClockValue*: int64 # indicates the last clock value to be used when sending messages
|
||||||
|
|
|
@ -9,18 +9,25 @@ 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*(chatId: string, filterId: string = "", symKeyId: string = "", oneToOne: bool = false, identity: string = "", topic: string = "", discovery: bool = false, negotiated: bool = false, listen: bool = true):JsonNode =
|
||||||
result = %* {
|
if oneToOne:
|
||||||
"ChatID": chatId, # identifier of the chat
|
result = %* {
|
||||||
"FilterID": filterId, # whisper filter id generated
|
"ChatID": chatId, # identifier of the chat
|
||||||
"SymKeyID": symKeyId, # symmetric key id used for symmetric filters
|
"OneToOne": oneToOne, # if asymmetric encryption is used for this chat
|
||||||
"OneToOne": oneToOne, # if asymmetric encryption is used for this chat
|
"Identity": identity, # public key of the other recipient for non-public filters.
|
||||||
"Identity": identity, # public key of the other recipient for non-public filters.
|
}
|
||||||
# FIXME: passing empty string to the topic makes it error
|
else:
|
||||||
# "Topic": topic, # whisper topic
|
result = %* {
|
||||||
"Discovery": discovery,
|
"ChatID": chatId, # identifier of the chat
|
||||||
"Negotiated": negotiated,
|
"FilterID": filterId, # whisper filter id generated
|
||||||
"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
|
"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, %* [filters])
|
||||||
|
@ -48,17 +55,18 @@ proc saveChat*(chatId: string, oneToOne: bool = false, active: bool = true, colo
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
proc deactivateChat*(chatId: string) =
|
proc deactivateChat*(chat: Chat) =
|
||||||
discard callPrivateRPC("saveChat".prefix, %* [
|
discard callPrivateRPC("saveChat".prefix, %* [
|
||||||
{
|
{
|
||||||
"lastClockValue": 0,
|
"lastClockValue": 0, # TODO:
|
||||||
"color": "",
|
"color": chat.color,
|
||||||
"name": chatId,
|
"name": chat.name, #TODO: 0x04acde for 1:1?
|
||||||
"lastMessage": nil,
|
"lastMessage": nil, # TODO:
|
||||||
"active": false,
|
"active": false,
|
||||||
"id": chatId,
|
"id": chat.id,
|
||||||
"unviewedMessagesCount": 0,
|
"unviewedMessagesCount": 0, #TODO:
|
||||||
"timestamp": 0
|
"chatType": chat.chatType.int,
|
||||||
|
"timestamp": 0 # TODO:
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -68,7 +76,7 @@ proc loadChats*(): seq[Chat] =
|
||||||
if jsonResponse["result"].kind != JNull:
|
if jsonResponse["result"].kind != JNull:
|
||||||
for jsonChat in jsonResponse{"result"}:
|
for jsonChat in jsonResponse{"result"}:
|
||||||
let chat = jsonChat.toChat
|
let chat = jsonChat.toChat
|
||||||
if chat.active and chat.chatType != ChatType.Unknown:
|
if chat.isActive and chat.chatType != ChatType.Unknown:
|
||||||
result.add(jsonChat.toChat)
|
result.add(jsonChat.toChat)
|
||||||
|
|
||||||
proc chatMessages*(chatId: string, cursor: string = ""): (string, seq[Message]) =
|
proc chatMessages*(chatId: string, cursor: string = ""): (string, seq[Message]) =
|
||||||
|
|
Loading…
Reference in New Issue