From 9a2144fe758641fa62d720bb2a480cb6440ed378 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 10 Jun 2020 15:41:03 -0400 Subject: [PATCH] feat: leave private chat groups --- src/app/chat/core.nim | 1 + src/app/chat/view.nim | 1 + src/app/chat/views/channels_list.nim | 4 +++ src/signals/messages.nim | 11 +++----- src/status/chat.nim | 11 +++++++- src/status/libstatus/chat.nim | 3 +++ ui/app/AppLayouts/Chat/ChatColumn/Message.qml | 17 +++++++++++++ ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml | 25 ++++++++++++++++--- ui/app/img/leave_chat.svg | 3 +++ 9 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 ui/app/img/leave_chat.svg diff --git a/src/app/chat/core.nim b/src/app/chat/core.nim index d95dba7bb9..fc357036f3 100644 --- a/src/app/chat/core.nim +++ b/src/app/chat/core.nim @@ -68,6 +68,7 @@ proc init*(self: ChatController) = proc handleMessage(self: ChatController, data: MessageSignal) = for chat in data.chats: + self.status.chat.update(chat) # TODO: possible code smell. Try to unify this, by having the view react to the model self.view.updateChat(chat) self.view.pushMessages(data.messages) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 4db1d85d5c..9c9773105e 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -127,6 +127,7 @@ QtObject: self.status.chat.leave(self.activeChannel.id) proc updateChat*(self: ChatsView, chat: Chat) = + self.upsertChannel(chat.id) self.chats.updateChat(chat) if(self.activeChannel.id == chat.id): self.activeChannel.setChatItem(chat) diff --git a/src/app/chat/views/channels_list.nim b/src/app/chat/views/channels_list.nim index 8508fe95c1..ced0504c0e 100644 --- a/src/app/chat/views/channels_list.nim +++ b/src/app/chat/views/channels_list.nim @@ -74,6 +74,8 @@ 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) else: @@ -86,6 +88,8 @@ QtObject: proc updateChat*(self: ChannelsList, channel: Chat) = let idx = self.upsertChannel(channel) + if idx == -1: return + let topLeft = self.createIndex(0, 0, nil) let bottomRight = self.createIndex(self.chats.len, 0, nil) if idx != 0: # Move last updated chat to the top of the list diff --git a/src/signals/messages.nim b/src/signals/messages.nim index 30af3f85db..437a0aa666 100644 --- a/src/signals/messages.nim +++ b/src/signals/messages.nim @@ -67,13 +67,10 @@ proc toChat*(jsonChat: JsonNode): Chat = if jsonChat["lastMessage"].kind != JNull: result.lastMessage = jsonChat{"lastMessage"}.toMessage - if result.chatType == ChatType.OneToOne: - result.name = result.lastMessage.alias - result.identicon = result.lastMessage.identicon - else: - if result.chatType == ChatType.OneToOne: - result.identicon = generateIdenticon(result.id) - result.name = generateAlias(result.id) + + if result.chatType == ChatType.OneToOne: + result.identicon = generateIdenticon(result.id) + result.name = generateAlias(result.id) if jsonChat["members"].kind != JNull: result.members = @[] diff --git a/src/status/chat.nim b/src/status/chat.nim index 4a4cae0f2f..302e8c43ef 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -46,6 +46,10 @@ proc newChatModel*(events: EventEmitter): ChatModel = proc delete*(self: ChatModel) = discard +proc update*(self: ChatModel, chat: Chat) = + if chat.active: + self.channels[chat.id] = chat + proc hasChannel*(self: ChatModel, chatId: string): bool = self.channels.hasKey(chatId) @@ -103,7 +107,12 @@ proc init*(self: ChatModel) = self.events.emit("mailserverTopics", TopicArgs(topics: topics)); proc leave*(self: ChatModel, chatId: string) = - status_chat.removeFilters(chatId, self.filters[chatId]) + if self.channels[chatId].chatType == ChatType.PrivateGroupChat: + discard status_chat.leaveGroupChat(chatId) + + if self.filters.hasKey(chatId): + status_chat.removeFilters(chatId, self.filters[chatId]) + status_chat.deactivateChat(chatId) # TODO: REMOVE MAILSERVER TOPIC # TODO: REMOVE HISTORY diff --git a/src/status/libstatus/chat.nim b/src/status/libstatus/chat.nim index e8f1474cbc..967135713f 100644 --- a/src/status/libstatus/chat.nim +++ b/src/status/libstatus/chat.nim @@ -111,3 +111,6 @@ proc markAllRead*(chatId: string): string = proc confirmJoiningGroup*(chatId: string): string = callPrivateRPC("confirmJoiningGroup".prefix, %* [chatId]) + +proc leaveGroupChat*(chatId: string): string = + callPrivateRPC("leaveGroupChat".prefix, %* [nil, chatId, true]) diff --git a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml index cf35412b4f..822df7fb64 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/Message.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/Message.qml @@ -107,6 +107,7 @@ Item { id: joinOrDecline Text { + id: joinChat text: qsTr("Join chat") font.pixelSize: 20 color: Theme.blue @@ -119,6 +120,22 @@ Item { chatsModel.joinGroup() } } + } + + Text { + text: qsTr("Decline invitation") + font.pixelSize: 20 + color: Theme.blue + anchors.horizontalCenter: parent.horizontalCenter + anchors.top: joinChat.bottom + anchors.topMargin: Theme.padding + MouseArea { + cursorShape: Qt.PointingHandCursor + anchors.fill: parent + onClicked: { + chatsModel.leaveActiveChat() + } + } } } diff --git a/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml b/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml index 6fac5a652c..95dd19e80f 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml @@ -78,19 +78,38 @@ Rectangle { anchors.leftMargin: -15 anchors.fill: parent onClicked: { - contextMenu.arrowX = contextMenu.width - 40 - contextMenu.popup(moreActionsBtn.x, moreActionsBtn.height + 10) + var menu = chatContextMenu; + if(chatsModel.activeChannel.chatType == Constants.chatTypePrivateGroupChat){ + menu = groupContextMenu + } + + menu.arrowX = menu.width - 40 + menu.popup(moreActionsBtn.x, moreActionsBtn.height + 10) + } cursorShape: Qt.PointingHandCursor acceptedButtons: Qt.LeftButton | Qt.RightButton PopupMenu { - id: contextMenu + id: chatContextMenu QQC2.Action { + icon.source: "../../../img/leave_chat.svg" text: qsTr("Leave Chat") onTriggered: chatsModel.leaveActiveChat() } } + + PopupMenu { + id: groupContextMenu + QQC2.Action { + icon.source: "../../../img/leave_chat.svg" + text: qsTr("Leave Group") + onTriggered: chatsModel.leaveActiveChat() + } + } + + + } } } diff --git a/ui/app/img/leave_chat.svg b/ui/app/img/leave_chat.svg new file mode 100644 index 0000000000..c554daa675 --- /dev/null +++ b/ui/app/img/leave_chat.svg @@ -0,0 +1,3 @@ + + +