feat: leave private chat groups
This commit is contained in:
parent
735ad1ffac
commit
9a2144fe75
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = @[]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 |
Loading…
Reference in New Issue