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 =
|
||||
let idx = self.chats.findIndexById(channel.id)
|
||||
if not channel.active: return -1
|
||||
|
||||
if idx == -1:
|
||||
result = self.addChatItemToList(channel)
|
||||
|
|
|
@ -42,7 +42,7 @@ proc newChat*(id: string, chatType: ChatType): Chat =
|
|||
result = Chat(
|
||||
id: id,
|
||||
color: channelColors[rand(channelColors.len - 1)],
|
||||
active: true,
|
||||
isActive: true,
|
||||
chatType: chatType,
|
||||
timestamp: 0,
|
||||
lastClockValue: 0,
|
||||
|
@ -62,7 +62,7 @@ proc toChat*(jsonChat: JsonNode): Chat =
|
|||
name: jsonChat{"name"}.getStr,
|
||||
identicon: "",
|
||||
color: jsonChat{"color"}.getStr,
|
||||
active: jsonChat{"active"}.getBool,
|
||||
isActive: jsonChat{"active"}.getBool,
|
||||
chatType: ChatType(jsonChat{"chatType"}.getInt),
|
||||
timestamp: jsonChat{"timestamp"}.getBiggestInt,
|
||||
lastClockValue: jsonChat{"lastClockValue"}.getBiggestInt,
|
||||
|
|
|
@ -45,8 +45,7 @@ proc delete*(self: ChatModel) =
|
|||
discard
|
||||
|
||||
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 =
|
||||
self.channels.hasKey(chatId)
|
||||
|
@ -108,10 +107,11 @@ proc leave*(self: ChatModel, chatId: string) =
|
|||
if self.channels[chatId].chatType == ChatType.PrivateGroupChat:
|
||||
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.deactivateChat(chatId)
|
||||
status_chat.deactivateChat(self.channels[chatId])
|
||||
# TODO: REMOVE MAILSERVER TOPIC
|
||||
# TODO: REMOVE HISTORY
|
||||
self.filters.del(chatId)
|
||||
|
|
|
@ -20,7 +20,7 @@ type Chat* = ref object
|
|||
name*: string
|
||||
color*: 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
|
||||
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
|
||||
|
|
|
@ -9,18 +9,25 @@ 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 =
|
||||
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
|
||||
}
|
||||
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 loadFilters*(filters: seq[JsonNode]): string =
|
||||
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, %* [
|
||||
{
|
||||
"lastClockValue": 0,
|
||||
"color": "",
|
||||
"name": chatId,
|
||||
"lastMessage": nil,
|
||||
"lastClockValue": 0, # TODO:
|
||||
"color": chat.color,
|
||||
"name": chat.name, #TODO: 0x04acde for 1:1?
|
||||
"lastMessage": nil, # TODO:
|
||||
"active": false,
|
||||
"id": chatId,
|
||||
"unviewedMessagesCount": 0,
|
||||
"timestamp": 0
|
||||
"id": chat.id,
|
||||
"unviewedMessagesCount": 0, #TODO:
|
||||
"chatType": chat.chatType.int,
|
||||
"timestamp": 0 # TODO:
|
||||
}
|
||||
])
|
||||
|
||||
|
@ -68,7 +76,7 @@ proc loadChats*(): seq[Chat] =
|
|||
if jsonResponse["result"].kind != JNull:
|
||||
for jsonChat in jsonResponse{"result"}:
|
||||
let chat = jsonChat.toChat
|
||||
if chat.active and chat.chatType != ChatType.Unknown:
|
||||
if chat.isActive and chat.chatType != ChatType.Unknown:
|
||||
result.add(jsonChat.toChat)
|
||||
|
||||
proc chatMessages*(chatId: string, cursor: string = ""): (string, seq[Message]) =
|
||||
|
|
Loading…
Reference in New Issue