2020-06-17 19:18:31 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
2020-06-11 17:50:36 +00:00
|
|
|
import "../../../../imports"
|
|
|
|
import "../../../../shared"
|
2020-09-22 14:45:09 +00:00
|
|
|
import "../../../../shared/status"
|
2020-06-11 17:50:36 +00:00
|
|
|
import "./"
|
|
|
|
|
|
|
|
ModalPopup {
|
|
|
|
id: popup
|
2020-06-22 17:24:01 +00:00
|
|
|
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;
|
|
|
|
data.clear();
|
2020-09-17 19:39:02 +00:00
|
|
|
const nbContacts = profileModel.contactList.rowCount()
|
|
|
|
for(let i = 0; i < nbContacts; i++){
|
2020-06-22 17:24:01 +00:00
|
|
|
if(chatsModel.activeChannel.contains(profileModel.contactList.rowData(i, "pubKey"))) continue;
|
2020-09-16 19:52:48 +00:00
|
|
|
if(profileModel.contactList.rowData(i, "isContact") === "false") continue;
|
2020-06-22 17:24:01 +00:00
|
|
|
data.append({
|
|
|
|
name: profileModel.contactList.rowData(i, "name"),
|
2020-09-17 19:39:02 +00:00
|
|
|
localNickname: profileModel.contactList.rowData(i, "localNickname"),
|
2020-06-22 17:24:01 +00:00
|
|
|
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();
|
|
|
|
}
|
2020-06-11 17:50:36 +00:00
|
|
|
|
|
|
|
header: Item {
|
|
|
|
height: children[0].height
|
|
|
|
width: parent.width
|
|
|
|
|
2020-09-22 14:45:09 +00:00
|
|
|
|
|
|
|
StatusLetterIdenticon {
|
2020-06-11 17:50:36 +00:00
|
|
|
id: letterIdenticon
|
|
|
|
width: 36
|
|
|
|
height: 36
|
|
|
|
anchors.top: parent.top
|
|
|
|
color: chatsModel.activeChannel.color
|
2020-09-22 14:45:09 +00:00
|
|
|
chatName: chatsModel.activeChannel.name
|
2020-06-11 17:50:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 18:21:02 +00:00
|
|
|
StyledTextEdit {
|
2020-06-11 17:50:36 +00:00
|
|
|
id: groupName
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Add members"
|
|
|
|
text: addMembers ? qsTrId("add-members") : chatsModel.activeChannel.name
|
2020-06-11 17:50:36 +00:00
|
|
|
anchors.top: parent.top
|
2020-10-20 19:19:10 +00:00
|
|
|
anchors.topMargin: 2
|
2020-06-11 17:50:36 +00:00
|
|
|
anchors.left: letterIdenticon.right
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.leftMargin: Style.current.smallPadding
|
2020-06-11 17:50:36 +00:00
|
|
|
font.bold: true
|
|
|
|
font.pixelSize: 14
|
|
|
|
readOnly: true
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
}
|
|
|
|
|
2020-06-19 18:06:58 +00:00
|
|
|
StyledText {
|
2020-06-11 17:50:36 +00:00
|
|
|
text: {
|
2020-06-22 17:24:01 +00:00
|
|
|
let cnt = memberCount;
|
|
|
|
if(addMembers){
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "%1 / 10 members"
|
|
|
|
return qsTrId("%1-/-10-members").arg(cnt)
|
2020-06-22 17:24:01 +00:00
|
|
|
} else {
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "%1 members"
|
|
|
|
if(cnt > 1) return qsTrId("%1-members").arg(cnt);
|
|
|
|
//% "1 member"
|
|
|
|
return qsTrId("1-member");
|
2020-06-22 17:24:01 +00:00
|
|
|
}
|
2020-06-11 17:50:36 +00:00
|
|
|
}
|
|
|
|
width: 160
|
|
|
|
anchors.left: letterIdenticon.right
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.leftMargin: Style.current.smallPadding
|
2020-06-11 17:50:36 +00:00
|
|
|
anchors.top: groupName.bottom
|
|
|
|
anchors.topMargin: 2
|
|
|
|
font.pixelSize: 14
|
2020-07-02 15:14:31 +00:00
|
|
|
color: Style.current.darkGrey
|
2020-06-11 17:50:36 +00:00
|
|
|
}
|
2020-06-15 12:51:04 +00:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: editGroupNameBtn
|
2020-06-22 17:24:01 +00:00
|
|
|
visible: !addMembers && chatsModel.activeChannel.isAdmin(profileModel.profile.pubKey)
|
2020-06-15 12:51:04 +00:00
|
|
|
height: 24
|
|
|
|
width: 24
|
2020-10-20 19:19:10 +00:00
|
|
|
anchors.verticalCenter: groupName.verticalCenter
|
2020-06-15 12:51:04 +00:00
|
|
|
anchors.leftMargin: 4
|
|
|
|
anchors.left: groupName.right
|
|
|
|
radius: 8
|
|
|
|
|
2020-06-25 13:23:17 +00:00
|
|
|
SVGImage {
|
2020-06-15 12:51:04 +00:00
|
|
|
id: editGroupImg
|
|
|
|
source: "../../../img/edit-group.svg"
|
2020-08-07 19:26:51 +00:00
|
|
|
height: 16
|
|
|
|
width: 16
|
2020-06-15 12:51:04 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: closeModalMouseArea
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
onExited: {
|
2020-07-02 15:14:31 +00:00
|
|
|
editGroupNameBtn.color = Style.current.white
|
2020-06-15 12:51:04 +00:00
|
|
|
}
|
|
|
|
onEntered: {
|
2020-07-02 15:14:31 +00:00
|
|
|
editGroupNameBtn.color = Style.current.grey
|
2020-06-15 12:51:04 +00:00
|
|
|
}
|
|
|
|
onClicked: renameGroupPopup.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RenameGroupPopup {
|
|
|
|
id: renameGroupPopup
|
|
|
|
}
|
2020-06-11 17:50:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 17:24:01 +00:00
|
|
|
Item {
|
|
|
|
id: addMembersItem
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
SearchBox {
|
|
|
|
id: searchBox
|
|
|
|
visible: addMembers
|
|
|
|
iconWidth: 17
|
|
|
|
iconHeight: 17
|
|
|
|
customHeight: 44
|
|
|
|
fontPixelSize: 15
|
|
|
|
}
|
|
|
|
|
2020-08-10 02:14:21 +00:00
|
|
|
Rectangle {
|
|
|
|
id: noContactsRect
|
|
|
|
width: 320
|
|
|
|
visible: data.count == 0
|
|
|
|
anchors.top: searchBox.bottom
|
|
|
|
anchors.topMargin: Style.current.xlPadding
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
StyledText {
|
|
|
|
id: noContacts
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "All your contacts are already in the group"
|
|
|
|
text: qsTrId("group-chat-all-contacts-invited")
|
2020-08-10 02:14:21 +00:00
|
|
|
color: Style.current.textColor
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: Style.current.padding
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
}
|
|
|
|
StyledButton {
|
|
|
|
//% "Invite friends"
|
|
|
|
label: qsTrId("invite-friends")
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.top: noContacts.bottom
|
|
|
|
anchors.topMargin: Style.current.padding
|
|
|
|
onClicked: {
|
|
|
|
inviteFriendsPopup.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InviteFriendsPopup {
|
|
|
|
id: inviteFriendsPopup
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-22 17:24:01 +00:00
|
|
|
ScrollView {
|
2020-08-10 02:14:21 +00:00
|
|
|
visible: addMembers && data.count > 0
|
2020-06-22 17:24:01 +00:00
|
|
|
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 {
|
2020-10-20 19:19:10 +00:00
|
|
|
isVisible: searchBox.text === "" || model.name.includes(searchBox.text)
|
2020-06-22 17:24:01 +00:00
|
|
|
showCheckbox: memberCount < maxMembers
|
|
|
|
pubKey: model.pubKey
|
|
|
|
isUser: model.isUser
|
2020-10-20 19:19:10 +00:00
|
|
|
name: model.name.endsWith(".eth") || !model.localNickname ?
|
2020-09-17 19:39:02 +00:00
|
|
|
Utils.removeStatusEns(model.name) : model.localNickname
|
2020-06-22 17:24:01 +00:00
|
|
|
address: model.address
|
|
|
|
identicon: model.identicon
|
|
|
|
onItemChecked: function(pubKey, itemChecked){
|
|
|
|
var idx = pubKeys.indexOf(pubKey)
|
|
|
|
if(itemChecked){
|
2020-09-17 19:39:02 +00:00
|
|
|
if(idx === -1){
|
2020-06-22 17:24:01 +00:00
|
|
|
pubKeys.push(pubKey)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(idx > -1){
|
|
|
|
pubKeys.splice(idx, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memberCount = chatsModel.activeChannel.members.rowCount() + pubKeys.length;
|
|
|
|
btnSelectMembers.enabled = pubKeys.length > 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-06-11 17:50:36 +00:00
|
|
|
|
|
|
|
Item {
|
2020-06-22 17:24:01 +00:00
|
|
|
id: groupInfoItem
|
2020-06-11 17:50:36 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
|
2020-06-19 18:06:58 +00:00
|
|
|
StyledText {
|
2020-06-11 17:50:36 +00:00
|
|
|
id: memberLabel
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Members"
|
|
|
|
text: qsTrId("members-title")
|
2020-06-11 17:50:36 +00:00
|
|
|
anchors.left: parent.left
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.leftMargin: Style.current.padding
|
2020-06-11 17:50:36 +00:00
|
|
|
font.pixelSize: 15
|
2020-07-02 15:14:31 +00:00
|
|
|
color: Style.current.darkGrey
|
2020-06-11 17:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
id: memberList
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.top: memberLabel.bottom
|
|
|
|
anchors.bottom: popup.bottom
|
|
|
|
anchors.topMargin: 30
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.bottomMargin: Style.current.padding
|
2020-06-11 17:50:36 +00:00
|
|
|
spacing: 4
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
model: chatsModel.activeChannel.members
|
2020-10-20 19:19:10 +00:00
|
|
|
delegate: Item {
|
2020-09-17 19:39:02 +00:00
|
|
|
id: contactRow
|
2020-10-20 19:19:10 +00:00
|
|
|
width: parent.width
|
|
|
|
height: identicon.height
|
|
|
|
|
2020-09-17 19:39:02 +00:00
|
|
|
property string nickname: {
|
|
|
|
// Get contact nickname
|
|
|
|
const contactList = profileModel.contactList
|
|
|
|
const contactCount = contactList.rowCount()
|
|
|
|
let nickname = ""
|
|
|
|
for (let i = 0; i < contactCount; i++) {
|
|
|
|
if (contactList.rowData(i, 'pubKey') === model.pubKey) {
|
|
|
|
return contactList.rowData(i, 'localNickname')
|
|
|
|
}
|
|
|
|
}
|
2020-09-17 20:18:50 +00:00
|
|
|
return ""
|
2020-09-17 19:39:02 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 19:19:10 +00:00
|
|
|
StatusImageIdenticon {
|
|
|
|
id: identicon
|
|
|
|
anchors.left: parent.left
|
|
|
|
source: model.identicon
|
2020-06-11 17:50:36 +00:00
|
|
|
}
|
2020-10-20 19:19:10 +00:00
|
|
|
|
|
|
|
StyledText {
|
|
|
|
text: !model.userName.endsWith(".eth") && !!contactRow.nickname ?
|
|
|
|
contactRow.nickname : Utils.removeStatusEns(model.userName)
|
|
|
|
anchors.left: identicon.right
|
|
|
|
anchors.leftMargin: Style.current.smallPadding
|
|
|
|
anchors.right: adminLabel.left
|
|
|
|
anchors.rightMargin: Style.current.smallPadding
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
font.pixelSize: 13
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
onClicked: openProfilePopup(model.userName, model.pubKey, model.identicon, '', contactRow.nickname, popup)
|
2020-06-11 17:50:36 +00:00
|
|
|
}
|
2020-10-20 19:19:10 +00:00
|
|
|
}
|
2020-08-06 13:37:09 +00:00
|
|
|
|
2020-10-20 19:19:10 +00:00
|
|
|
StyledText {
|
|
|
|
id: adminLabel
|
|
|
|
visible: model.isAdmin
|
|
|
|
//% "Admin"
|
|
|
|
text: qsTrId("group-chat-admin")
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
font.pixelSize: 13
|
2020-06-11 17:50:36 +00:00
|
|
|
}
|
2020-10-20 19:19:10 +00:00
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: moreActionsBtn
|
|
|
|
visible: !model.isAdmin && chatsModel.activeChannel.isAdmin(profileModel.profile.pubKey)
|
|
|
|
text: "..."
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.smallPadding
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
contextMenu.popup(-contextMenu.width / 2 + moreActionsBtn.width / 2, moreActionsBtn.height + 10)
|
|
|
|
}
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
PopupMenu {
|
|
|
|
id: contextMenu
|
|
|
|
Action {
|
|
|
|
icon.source: "../../../img/make-admin.svg"
|
|
|
|
//% "Make Admin"
|
|
|
|
text: qsTrId("make-admin")
|
|
|
|
onTriggered: chatsModel.makeAdmin(chatsModel.activeChannel.id, model.pubKey)
|
2020-06-12 14:01:46 +00:00
|
|
|
}
|
2020-10-20 19:19:10 +00:00
|
|
|
Action {
|
|
|
|
icon.source: "../../../img/remove-from-group.svg"
|
|
|
|
icon.color: Style.current.red
|
|
|
|
//% "Remove From Group"
|
|
|
|
text: qsTrId("remove-from-group")
|
|
|
|
onTriggered: chatsModel.kickGroupMember(chatsModel.activeChannel.id, model.pubKey)
|
2020-06-12 14:01:46 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-11 17:50:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-22 17:24:01 +00:00
|
|
|
|
|
|
|
footer: Item {
|
|
|
|
visible: chatsModel.activeChannel.isAdmin(profileModel.profile.pubKey)
|
|
|
|
width: parent.width
|
|
|
|
height: children[0].height
|
|
|
|
StyledButton {
|
|
|
|
visible: !addMembers
|
|
|
|
anchors.right: parent.right
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Add members"
|
|
|
|
label: qsTrId("add-members")
|
2020-06-22 17:24:01 +00:00
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
onClicked: {
|
|
|
|
addMembers = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: btnBack
|
|
|
|
visible: addMembers
|
|
|
|
width: 44
|
|
|
|
height: 44
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.left: parent.left
|
2020-06-25 13:23:17 +00:00
|
|
|
SVGImage {
|
2020-06-22 17:24:01 +00:00
|
|
|
source: "../../../img/arrow-left-btn-active.svg"
|
2020-06-25 13:23:17 +00:00
|
|
|
width: 50
|
|
|
|
height: 50
|
2020-06-22 17:24:01 +00:00
|
|
|
}
|
|
|
|
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
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Add selected"
|
|
|
|
label: qsTrId("add-selected")
|
2020-06-22 17:24:01 +00:00
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
onClicked: doAddMembers()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
content: addMembers ? addMembersItem : groupInfoItem
|
2020-06-11 17:50:36 +00:00
|
|
|
}
|