feat: leave private chat groups

This commit is contained in:
Richard Ramos 2020-06-10 15:41:03 -04:00 committed by Iuri Matias
parent 735ad1ffac
commit 9a2144fe75
9 changed files with 65 additions and 11 deletions

View File

@ -68,6 +68,7 @@ proc init*(self: ChatController) =
proc handleMessage(self: ChatController, data: MessageSignal) = proc handleMessage(self: ChatController, data: MessageSignal) =
for chat in data.chats: 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.updateChat(chat)
self.view.pushMessages(data.messages) self.view.pushMessages(data.messages)

View File

@ -127,6 +127,7 @@ QtObject:
self.status.chat.leave(self.activeChannel.id) self.status.chat.leave(self.activeChannel.id)
proc updateChat*(self: ChatsView, chat: Chat) = proc updateChat*(self: ChatsView, chat: Chat) =
self.upsertChannel(chat.id)
self.chats.updateChat(chat) self.chats.updateChat(chat)
if(self.activeChannel.id == chat.id): if(self.activeChannel.id == chat.id):
self.activeChannel.setChatItem(chat) self.activeChannel.setChatItem(chat)

View File

@ -74,6 +74,8 @@ 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)
else: else:
@ -86,6 +88,8 @@ QtObject:
proc updateChat*(self: ChannelsList, channel: Chat) = proc updateChat*(self: ChannelsList, channel: Chat) =
let idx = self.upsertChannel(channel) let idx = self.upsertChannel(channel)
if idx == -1: return
let topLeft = self.createIndex(0, 0, nil) let topLeft = self.createIndex(0, 0, nil)
let bottomRight = self.createIndex(self.chats.len, 0, nil) let bottomRight = self.createIndex(self.chats.len, 0, nil)
if idx != 0: # Move last updated chat to the top of the list if idx != 0: # Move last updated chat to the top of the list

View File

@ -67,13 +67,10 @@ proc toChat*(jsonChat: JsonNode): Chat =
if jsonChat["lastMessage"].kind != JNull: if jsonChat["lastMessage"].kind != JNull:
result.lastMessage = jsonChat{"lastMessage"}.toMessage result.lastMessage = jsonChat{"lastMessage"}.toMessage
if result.chatType == ChatType.OneToOne:
result.name = result.lastMessage.alias if result.chatType == ChatType.OneToOne:
result.identicon = result.lastMessage.identicon result.identicon = generateIdenticon(result.id)
else: 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: if jsonChat["members"].kind != JNull:
result.members = @[] result.members = @[]

View File

@ -46,6 +46,10 @@ proc newChatModel*(events: EventEmitter): ChatModel =
proc delete*(self: ChatModel) = proc delete*(self: ChatModel) =
discard discard
proc update*(self: ChatModel, chat: Chat) =
if chat.active:
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)
@ -103,7 +107,12 @@ proc init*(self: ChatModel) =
self.events.emit("mailserverTopics", TopicArgs(topics: topics)); self.events.emit("mailserverTopics", TopicArgs(topics: topics));
proc leave*(self: ChatModel, chatId: string) = 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) status_chat.deactivateChat(chatId)
# TODO: REMOVE MAILSERVER TOPIC # TODO: REMOVE MAILSERVER TOPIC
# TODO: REMOVE HISTORY # TODO: REMOVE HISTORY

View File

@ -111,3 +111,6 @@ proc markAllRead*(chatId: string): string =
proc confirmJoiningGroup*(chatId: string): string = proc confirmJoiningGroup*(chatId: string): string =
callPrivateRPC("confirmJoiningGroup".prefix, %* [chatId]) callPrivateRPC("confirmJoiningGroup".prefix, %* [chatId])
proc leaveGroupChat*(chatId: string): string =
callPrivateRPC("leaveGroupChat".prefix, %* [nil, chatId, true])

View File

@ -107,6 +107,7 @@ Item {
id: joinOrDecline id: joinOrDecline
Text { Text {
id: joinChat
text: qsTr("Join chat") text: qsTr("Join chat")
font.pixelSize: 20 font.pixelSize: 20
color: Theme.blue color: Theme.blue
@ -119,6 +120,22 @@ Item {
chatsModel.joinGroup() 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()
}
}
} }
} }

View File

@ -78,19 +78,38 @@ Rectangle {
anchors.leftMargin: -15 anchors.leftMargin: -15
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
contextMenu.arrowX = contextMenu.width - 40 var menu = chatContextMenu;
contextMenu.popup(moreActionsBtn.x, moreActionsBtn.height + 10) if(chatsModel.activeChannel.chatType == Constants.chatTypePrivateGroupChat){
menu = groupContextMenu
}
menu.arrowX = menu.width - 40
menu.popup(moreActionsBtn.x, moreActionsBtn.height + 10)
} }
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.RightButton
PopupMenu { PopupMenu {
id: contextMenu id: chatContextMenu
QQC2.Action { QQC2.Action {
icon.source: "../../../img/leave_chat.svg"
text: qsTr("Leave Chat") text: qsTr("Leave Chat")
onTriggered: chatsModel.leaveActiveChat() onTriggered: chatsModel.leaveActiveChat()
} }
} }
PopupMenu {
id: groupContextMenu
QQC2.Action {
icon.source: "../../../img/leave_chat.svg"
text: qsTr("Leave Group")
onTriggered: chatsModel.leaveActiveChat()
}
}
} }
} }
} }

View File

@ -0,0 +1,3 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M7.02006 4.35355C7.21532 4.15829 7.21532 3.84171 7.02006 3.64645C6.82479 3.45118 6.50821 3.45118 6.31295 3.64645L2.31295 7.64645C2.11769 7.84171 2.11769 8.15829 2.31295 8.35355L6.31295 12.3536C6.50821 12.5488 6.82479 12.5488 7.02006 12.3536C7.21532 12.1583 7.21532 11.8417 7.02006 11.6464L4.44265 9.06904C4.23266 8.85905 4.38138 8.5 4.67835 8.5H13.3332C13.6093 8.5 13.8332 8.27614 13.8332 8C13.8332 7.72386 13.6093 7.5 13.3332 7.5H4.67835C4.38138 7.5 4.23266 7.14095 4.44265 6.93096L7.02006 4.35355Z" fill="#4360DF"/>
</svg>

After

Width:  |  Height:  |  Size: 630 B