feat: add members to existing group chat and fix group position on chat list
This commit is contained in:
parent
e1d72ef057
commit
80b8d8f478
|
@ -51,6 +51,7 @@ proc handleChatEvents(self: ChatController) =
|
|||
var channel = ChannelArgs(e)
|
||||
discard self.view.chats.addChatItemToList(channel.chat)
|
||||
self.status.chat.chatMessages(channel.chat.id)
|
||||
self.view.setActiveChannel(channel.chat.id)
|
||||
|
||||
self.status.events.on("channelLeft") do(e: Args):
|
||||
discard self.view.chats.removeChatItemFromList(self.view.activeChannel.chatItem.id)
|
||||
|
|
|
@ -168,3 +168,7 @@ QtObject:
|
|||
proc createGroup*(self: ChatsView, groupName: string, pubKeys: string) {.slot.} =
|
||||
let pubKeysSeq = map(parseJson(pubKeys).getElems(), proc(x:JsonNode):string = x.getStr)
|
||||
self.status.chat.createGroup(groupName, pubKeysSeq)
|
||||
|
||||
proc addGroupMembers*(self: ChatsView, chatId: string, pubKeys: string) {.slot.} =
|
||||
let pubKeysSeq = map(parseJson(pubKeys).getElems(), proc(x:JsonNode):string = x.getStr)
|
||||
self.status.chat.addGroupMembers(chatId, pubKeysSeq)
|
||||
|
|
|
@ -66,6 +66,10 @@ QtObject:
|
|||
if self.chatItem.isNil: return false
|
||||
return self.chatItem.isMember(pubKey)
|
||||
|
||||
proc contains*(self: ChatItemView, pubKey: string): bool {.slot.} =
|
||||
if self.chatItem.isNil: return false
|
||||
return self.chatItem.contains(pubKey)
|
||||
|
||||
proc isAdmin*(self: ChatItemView, pubKey: string): bool {.slot.} =
|
||||
if self.chatItem.isNil: return false
|
||||
return self.chatItem.isAdmin(pubKey)
|
||||
|
|
|
@ -78,7 +78,6 @@ proc join*(self: ChatModel, chatId: string, chatType: ChatType) =
|
|||
self.events.emit("mailserverTopics", TopicArgs(topics: topics));
|
||||
|
||||
self.events.emit("channelJoined", ChannelArgs(chat: chat))
|
||||
self.events.emit("activeChannelChanged", ChatIdArg(chatId: self.getActiveChannel()))
|
||||
|
||||
proc init*(self: ChatModel) =
|
||||
let chatList = status_chat.loadChats()
|
||||
|
@ -177,3 +176,7 @@ proc createGroup*(self: ChatModel, groupName: string, pubKeys: seq[string]) =
|
|||
self.channels[chat.id] = chat
|
||||
self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats, contacts: @[]))
|
||||
self.events.emit("activeChannelChanged", ChatIdArg(chatId: chat.id))
|
||||
|
||||
proc addGroupMembers*(self: ChatModel, chatId: string, pubKeys: seq[string]) =
|
||||
var response = status_chat.addGroupMembers(chatId, pubKeys)
|
||||
self.emitUpdate(response)
|
||||
|
|
|
@ -101,6 +101,11 @@ proc isMember*(self: Chat, pubKey: string): bool =
|
|||
if member.id == pubKey and member.joined: return true
|
||||
return false
|
||||
|
||||
proc contains*(self: Chat, pubKey: string): bool =
|
||||
for member in self.members:
|
||||
if member.id == pubKey: return true
|
||||
return false
|
||||
|
||||
proc isAdmin*(self: Chat, pubKey: string): bool =
|
||||
for member in self.members:
|
||||
if member.id == pubKey and member.joined and member.admin: return true
|
||||
|
|
|
@ -110,3 +110,6 @@ proc renameGroup*(chatId: string, newName: string): string =
|
|||
|
||||
proc createGroup*(groupName: string, pubKeys: seq[string]): string =
|
||||
callPrivateRPC("createGroupChatWithMembers".prefix, %* [nil, groupName, pubKeys])
|
||||
|
||||
proc addGroupMembers*(chatId: string, pubKeys: seq[string]): string =
|
||||
callPrivateRPC("addMembersToGroupChat".prefix, %* [nil, chatId, pubKeys])
|
||||
|
|
|
@ -50,6 +50,13 @@ Item {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: chatsModel
|
||||
onActiveChannelChanged: {
|
||||
chatGroupsListView.currentIndex = chatsModel.activeChannelIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
/*##^##
|
||||
Designer {
|
||||
|
|
|
@ -7,6 +7,46 @@ import "./"
|
|||
|
||||
ModalPopup {
|
||||
id: popup
|
||||
property bool addMembers: false
|
||||
property int currMemberCount: 1
|
||||
property int memberCount: 1
|
||||
readonly property int maxMembers: 10
|
||||
property var pubKeys: []
|
||||
|
||||
function resetSelectedMembers(){
|
||||
pubKeys = [];
|
||||
memberCount = chatsModel.activeChannel.members.rowCount();
|
||||
currMemberCount = memberCount;
|
||||
for(var i in groupMembers.contentItem.children){
|
||||
if (groupMembers.contentItem.children[i].isChecked !== null) {
|
||||
groupMembers.contentItem.children[i].isChecked = false
|
||||
}
|
||||
}
|
||||
data.clear();
|
||||
for(let i = 0; i < profileModel.contactList.rowCount(); i++){
|
||||
if(chatsModel.activeChannel.contains(profileModel.contactList.rowData(i, "pubKey"))) continue;
|
||||
if(profileModel.contactList.rowData(i, "isContact") == "false") continue;
|
||||
data.append({
|
||||
name: profileModel.contactList.rowData(i, "name"),
|
||||
pubKey: profileModel.contactList.rowData(i, "pubKey"),
|
||||
address: profileModel.contactList.rowData(i, "address"),
|
||||
identicon: profileModel.contactList.rowData(i, "identicon"),
|
||||
isUser: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onOpened: {
|
||||
addMembers = false;
|
||||
btnSelectMembers.enabled = false;
|
||||
resetSelectedMembers();
|
||||
}
|
||||
|
||||
function doAddMembers(){
|
||||
if(pubKeys.length === 0) return;
|
||||
chatsModel.addGroupMembers(chatsModel.activeChannel.id, JSON.stringify(pubKeys));
|
||||
popup.close();
|
||||
}
|
||||
|
||||
header: Item {
|
||||
height: children[0].height
|
||||
|
@ -34,7 +74,7 @@ ModalPopup {
|
|||
|
||||
StyledTextEdit {
|
||||
id: groupName
|
||||
text: chatsModel.activeChannel.name
|
||||
text: addMembers ? qsTr("Add members") : chatsModel.activeChannel.name
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 18
|
||||
anchors.left: letterIdenticon.right
|
||||
|
@ -47,10 +87,14 @@ ModalPopup {
|
|||
|
||||
StyledText {
|
||||
text: {
|
||||
let cnt = chatsModel.activeChannel.members.rowCount();
|
||||
let cnt = memberCount;
|
||||
if(addMembers){
|
||||
return qsTr("%1 / 10 members").arg(cnt)
|
||||
} else {
|
||||
if(cnt > 1) return qsTr("%1 members").arg(cnt);
|
||||
return qsTr("1 member");
|
||||
}
|
||||
}
|
||||
width: 160
|
||||
anchors.left: letterIdenticon.right
|
||||
anchors.leftMargin: Theme.smallPadding
|
||||
|
@ -62,7 +106,7 @@ ModalPopup {
|
|||
|
||||
Rectangle {
|
||||
id: editGroupNameBtn
|
||||
visible: chatsModel.activeChannel.isAdmin(profileModel.profile.pubKey)
|
||||
visible: !addMembers && chatsModel.activeChannel.isAdmin(profileModel.profile.pubKey)
|
||||
height: 24
|
||||
width: 24
|
||||
anchors.top: parent.top
|
||||
|
@ -98,9 +142,68 @@ ModalPopup {
|
|||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: addMembersItem
|
||||
anchors.fill: parent
|
||||
|
||||
SearchBox {
|
||||
id: searchBox
|
||||
visible: addMembers
|
||||
iconWidth: 17
|
||||
iconHeight: 17
|
||||
customHeight: 44
|
||||
fontPixelSize: 15
|
||||
}
|
||||
|
||||
ScrollView {
|
||||
visible: addMembers
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: 50
|
||||
anchors.top: searchBox.bottom
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
||||
ScrollBar.vertical.policy: groupMembers.contentHeight > groupMembers.height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff
|
||||
|
||||
ListView {
|
||||
anchors.fill: parent
|
||||
model: ListModel {
|
||||
id: data
|
||||
}
|
||||
spacing: 0
|
||||
clip: true
|
||||
id: groupMembers
|
||||
delegate: Contact {
|
||||
isVisible: searchBox.text == "" || model.name.includes(searchBox.text)
|
||||
showCheckbox: memberCount < maxMembers
|
||||
pubKey: model.pubKey
|
||||
isUser: model.isUser
|
||||
name: model.name
|
||||
address: model.address
|
||||
identicon: model.identicon
|
||||
onItemChecked: function(pubKey, itemChecked){
|
||||
var idx = pubKeys.indexOf(pubKey)
|
||||
if(itemChecked){
|
||||
if(idx == -1){
|
||||
pubKeys.push(pubKey)
|
||||
}
|
||||
} else {
|
||||
if(idx > -1){
|
||||
pubKeys.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
memberCount = chatsModel.activeChannel.members.rowCount() + pubKeys.length;
|
||||
btnSelectMembers.enabled = pubKeys.length > 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Item {
|
||||
id: container
|
||||
id: groupInfoItem
|
||||
anchors.fill: parent
|
||||
|
||||
StyledText {
|
||||
|
@ -205,4 +308,54 @@ ModalPopup {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
footer: Item {
|
||||
visible: chatsModel.activeChannel.isAdmin(profileModel.profile.pubKey)
|
||||
width: parent.width
|
||||
height: children[0].height
|
||||
StyledButton {
|
||||
visible: !addMembers
|
||||
anchors.right: parent.right
|
||||
label: qsTr("Add members")
|
||||
anchors.bottom: parent.bottom
|
||||
onClicked: {
|
||||
addMembers = true;
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: btnBack
|
||||
visible: addMembers
|
||||
width: 44
|
||||
height: 44
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
Image {
|
||||
source: "../../../img/arrow-left-btn-active.svg"
|
||||
}
|
||||
background: Rectangle {
|
||||
color: "transparent"
|
||||
}
|
||||
MouseArea {
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
anchors.fill: parent
|
||||
onClicked : {
|
||||
addMembers = false;
|
||||
resetSelectedMembers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StyledButton {
|
||||
id: btnSelectMembers
|
||||
visible: addMembers
|
||||
disabled: memberCount <= currMemberCount
|
||||
anchors.right: parent.right
|
||||
label: qsTr("Add selected")
|
||||
anchors.bottom: parent.bottom
|
||||
onClicked: doAddMembers()
|
||||
}
|
||||
}
|
||||
|
||||
content: addMembers ? addMembersItem : groupInfoItem
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue