feat(chat): implement clearing chat history

Closes #148
This commit is contained in:
Pascal Precht 2020-06-18 11:47:30 +02:00 committed by Iuri Matias
parent 719d66b332
commit 7d5ea12095
7 changed files with 44 additions and 3 deletions

View File

@ -43,6 +43,10 @@ proc handleChatEvents(self: ChatController) =
self.view.updateChats(evArgs.chats) self.view.updateChats(evArgs.chats)
self.view.pushMessages(evArgs.messages) self.view.pushMessages(evArgs.messages)
self.status.events.on("chatHistoryCleared") do(e: Args):
var args = ChannelArgs(e)
self.view.clearMessages(args.chat.id)
self.status.events.on("channelJoined") do(e: Args): self.status.events.on("channelJoined") do(e: Args):
var channel = ChannelArgs(e) var channel = ChannelArgs(e)
discard self.view.chats.addChatItemToList(channel.chat) discard self.view.chats.addChatItemToList(channel.chat)

View File

@ -86,6 +86,12 @@ QtObject:
proc messagePushed*(self: ChatsView) {.signal.} proc messagePushed*(self: ChatsView) {.signal.}
proc messagesCleared*(self: ChatsView) {.signal.}
proc clearMessages*(self: ChatsView, id: string) =
self.messageList[id].clear()
self.messagesCleared()
proc pushMessages*(self:ChatsView, messages: var seq[Message]) = proc pushMessages*(self:ChatsView, messages: var seq[Message]) =
for msg in messages.mitems: for msg in messages.mitems:
self.upsertChannel(msg.chatId) self.upsertChannel(msg.chatId)
@ -130,6 +136,9 @@ QtObject:
proc leaveActiveChat*(self: ChatsView) {.slot.} = proc leaveActiveChat*(self: ChatsView) {.slot.} =
self.status.chat.leave(self.activeChannel.id) self.status.chat.leave(self.activeChannel.id)
proc clearChatHistory*(self: ChatsView, id: string) {.slot.} =
self.status.chat.clearHistory(id)
proc updateChats*(self: ChatsView, chats: seq[Chat]) = proc updateChats*(self: ChatsView, chats: seq[Chat]) =
for chat in chats: for chat in chats:
self.upsertChannel(chat.id) self.upsertChannel(chat.id)

View File

@ -100,6 +100,11 @@ QtObject:
self.messages.add(message) self.messages.add(message)
self.endInsertRows() self.endInsertRows()
proc clear*(self: ChatMessageList) =
self.beginResetModel()
self.messages = @[]
self.endResetModel()
proc updateUsernames*(self: ChatMessageList, contacts: seq[Profile]) = proc updateUsernames*(self: ChatMessageList, contacts: seq[Profile]) =
let topLeft = self.createIndex(0, 0, nil) let topLeft = self.createIndex(0, 0, nil)
let bottomRight = self.createIndex(self.messages.len, 0, nil) let bottomRight = self.createIndex(self.messages.len, 0, nil)

View File

@ -136,12 +136,18 @@ proc leave*(self: ChatModel, chatId: string) =
status_chat.deactivateChat(self.channels[chatId]) status_chat.deactivateChat(self.channels[chatId])
# TODO: REMOVE MAILSERVER TOPIC # TODO: REMOVE MAILSERVER TOPIC
# TODO: REMOVE HISTORY
self.filters.del(chatId) self.filters.del(chatId)
self.channels.del(chatId) self.channels.del(chatId)
discard status_chat.clearChatHistory(chatId)
self.events.emit("channelLeft", ChatIdArg(chatId: chatId)) self.events.emit("channelLeft", ChatIdArg(chatId: chatId))
self.events.emit("activeChannelChanged", ChatIdArg(chatId: "")) self.events.emit("activeChannelChanged", ChatIdArg(chatId: ""))
proc clearHistory*(self: ChatModel, chatId: string) =
discard status_chat.clearChatHistory(chatId)
let chat = self.channels[chatId]
self.events.emit("chatHistoryCleared", ChannelArgs(chat: chat))
proc setActiveChannel*(self: ChatModel, chatId: string) = proc setActiveChannel*(self: ChatModel, chatId: string) =
self.events.emit("activeChannelChanged", ChatIdArg(chatId: chatId)) self.events.emit("activeChannelChanged", ChatIdArg(chatId: chatId))
@ -202,4 +208,4 @@ proc updateContacts*(self: ChatModel, contacts: seq[Profile]) =
proc createGroup*(self: ChatModel, groupName: string, pubKeys: seq[string]) = proc createGroup*(self: ChatModel, groupName: string, pubKeys: seq[string]) =
var response = parseJson(status_chat.createGroup(groupName, pubKeys)) var response = parseJson(status_chat.createGroup(groupName, pubKeys))
var (chats, messages) = formatChatUpdate(response) var (chats, messages) = formatChatUpdate(response)
self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats, contacts: @[])) self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats, contacts: @[]))

View File

@ -100,6 +100,9 @@ proc confirmJoiningGroup*(chatId: string): string =
proc leaveGroupChat*(chatId: string): string = proc leaveGroupChat*(chatId: string): string =
callPrivateRPC("leaveGroupChat".prefix, %* [nil, chatId, true]) callPrivateRPC("leaveGroupChat".prefix, %* [nil, chatId, true])
proc clearChatHistory*(chatId: string): string =
callPrivateRPC("deleteMessagesByChatID".prefix, %* [chatId])
proc renameGroup*(chatId: string, newName: string): string = proc renameGroup*(chatId: string, newName: string): string =
callPrivateRPC("changeGroupChatName".prefix, %* [nil, chatId, newName]) callPrivateRPC("changeGroupChatName".prefix, %* [nil, chatId, newName])

View File

@ -93,6 +93,11 @@ Rectangle {
PopupMenu { PopupMenu {
id: chatContextMenu id: chatContextMenu
Action {
icon.source: "../../../img/close.svg"
text: qsTr("Clear history")
onTriggered: chatsModel.clearChatHistory(chatsModel.activeChannel.id)
}
Action { Action {
icon.source: "../../../img/leave_chat.svg" icon.source: "../../../img/leave_chat.svg"
text: qsTr("Leave Chat") text: qsTr("Leave Chat")
@ -107,6 +112,11 @@ Rectangle {
text: qsTr("Group Information") text: qsTr("Group Information")
onTriggered: groupInfoPopup.open() onTriggered: groupInfoPopup.open()
} }
Action {
icon.source: "../../../img/close.svg"
text: qsTr("Clear history")
onTriggered: chatsModel.clearChatHistory(chatsModel.activeChannel.id)
}
Action { Action {
icon.source: "../../../img/leave_chat.svg" icon.source: "../../../img/leave_chat.svg"
text: qsTr("Leave Group") text: qsTr("Leave Group")

4
ui/app/img/close.svg Normal file
View File

@ -0,0 +1,4 @@
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9.68656 4.31295C9.88182 4.50821 9.88182 4.8248 9.68656 5.02006L7.94244 6.76418C7.81227 6.89435 7.81227 7.10541 7.94244 7.23558L9.68656 8.9797C9.88182 9.17496 9.88182 9.49154 9.68656 9.68681C9.4913 9.88207 9.17472 9.88207 8.97945 9.68681L7.23534 7.94269C7.10516 7.81251 6.89411 7.81251 6.76393 7.94269L5.01989 9.68672C4.82463 9.88199 4.50805 9.88199 4.31279 9.68672C4.11753 9.49146 4.11753 9.17488 4.31279 8.97962L6.05682 7.23558C6.187 7.10541 6.187 6.89435 6.05682 6.76418L4.31279 5.02014C4.11753 4.82488 4.11753 4.50829 4.31279 4.31303C4.50805 4.11777 4.82463 4.11777 5.01989 4.31303L6.76393 6.05707C6.89411 6.18724 7.10516 6.18724 7.23534 6.05707L8.97945 4.31295C9.17472 4.11769 9.4913 4.11769 9.68656 4.31295Z" fill="#4360DF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.99967 13.6666C10.6816 13.6666 13.6663 10.6818 13.6663 6.99992C13.6663 3.31802 10.6816 0.333252 6.99967 0.333252C3.31778 0.333252 0.333008 3.31802 0.333008 6.99992C0.333008 10.6818 3.31778 13.6666 6.99967 13.6666ZM6.99967 12.6666C10.1293 12.6666 12.6663 10.1295 12.6663 6.99992C12.6663 3.87031 10.1293 1.33325 6.99967 1.33325C3.87006 1.33325 1.33301 3.87031 1.33301 6.99992C1.33301 10.1295 3.87006 12.6666 6.99967 12.6666Z" fill="#4360DF"/>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB