feat(chat): preserve 1-1 chat history when closing it + rename copy

Fixes #12754
This commit is contained in:
Jonathan Rainville 2023-11-16 13:45:01 -05:00
parent db49c5995f
commit 7b302c07ef
4 changed files with 10 additions and 13 deletions

View File

@ -489,7 +489,7 @@ QtObject:
let leaveGroupResponse = status_chat.leaveGroupChat(chatId)
self.emitUpdate(leaveGroupResponse)
discard status_chat.deactivateChat(chatId)
discard status_chat.deactivateChat(chatId, preserveHistory = chat.chatType == chat_dto.ChatType.OneToOne)
var channelGroupId = chat.communityId
if (channelGroupId == ""):
@ -497,7 +497,6 @@ QtObject:
self.channelGroups[channelGroupId].chats.delete(self.getChatIndex(channelGroupId, chatId))
self.chats.del(chatId)
discard status_chat.deleteMessagesByChatId(chatId)
self.events.emit(SIGNAL_CHAT_LEFT, ChatArgs(chatId: chatId))
except Exception as e:
error "Error deleting channel", chatId, msg = e.msg

View File

@ -190,12 +190,6 @@ QtObject:
result.msgCursor = initTable[string, MessageCursor]()
result.pinnedMsgCursor = initTable[string, MessageCursor]()
proc removeMessageWithId(messages: var seq[MessageDto], msgId: string) =
for i in 0..<messages.len:
if (messages[i].id == msgId):
messages.delete(i)
return
proc isChatCursorInitialized(self: Service, chatId: string): bool =
return self.msgCursor.hasKey(chatId)
@ -442,6 +436,10 @@ QtObject:
self.resetMessageCursor(receivedData.channelId)
self.asyncLoadMoreMessagesForChat(receivedData.channelId)
self.events.on(SIGNAL_CHAT_LEFT) do(e: Args):
var chatArg = ChatArgs(e)
self.resetMessageCursor(chatArg.chatId)
proc getTransactionDetails*(self: Service, message: MessageDto): (string, string) =
let networksDto = self.networkService.getNetworks()
var token = self.tokenService.findTokenByAddress(networksDto[0].chainId, ZERO_ADDRESS)

View File

@ -51,8 +51,8 @@ proc createOneToOneChat*(chatId: string, ensName: string = ""): RpcResponse[Json
proc leaveGroupChat*(chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("leaveGroupChat".prefix, %* [nil, chatId, true])
proc deactivateChat*(chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
callPrivateRPC("deactivateChat".prefix, %* [{ "ID": chatId }])
proc deactivateChat*(chatId: string, preserveHistory: bool = false): RpcResponse[JsonNode] {.raises: [Exception].} =
callPrivateRPC("deactivateChat".prefix, %* [{ "ID": chatId, "preserveHistory": preserveHistory }])
proc clearChatHistory*(chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
callPrivateRPC("clearHistory".prefix, %* [{ "id": chatId }])

View File

@ -207,7 +207,7 @@ StatusMenu {
return qsTr("Leave group")
}
return root.chatType === Constants.chatType.oneToOne ?
qsTr("Delete Chat") :
qsTr("Close Chat") :
qsTr("Leave Chat")
}
icon.name: root.chatType === Constants.chatType.oneToOne || root.isCommunityChat ? "delete" : "arrow-left"
@ -290,12 +290,12 @@ StatusMenu {
confirmButtonObjectName: "deleteChatConfirmationDialogDeleteButton"
headerSettings.title: root.isCommunityChat ? qsTr("Delete #%1").arg(root.chatName) :
root.chatType === Constants.chatType.oneToOne ?
qsTr("Delete chat") :
qsTr("Close chat") :
qsTr("Leave chat")
confirmButtonLabel: root.isCommunityChat ? qsTr("Delete") : headerSettings.title
confirmationText: root.isCommunityChat ? qsTr("Are you sure you want to delete #%1 channel?").arg(root.chatName) :
root.chatType === Constants.chatType.oneToOne ?
qsTr("Are you sure you want to delete this chat?"):
qsTr("Are you sure you want to close this chat?"):
qsTr("Are you sure you want to leave this chat?")
showCancelButton: true
cancelBtnType: "normal"