status-desktop/ui/app/AppLayouts/Chat/popups/GroupChatPopup.qml

208 lines
5.7 KiB
QML
Raw Normal View History

2020-06-17 15:56:48 +00:00
import QtQuick 2.12
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import QtQml.Models 2.3
import utils 1.0
import shared.controls 1.0
import StatusQ.Controls 0.1
import shared.views 1.0
import shared.panels 1.0
import shared.popups 1.0
import "../panels"
import "../controls"
2020-06-17 15:56:48 +00:00
// TODO: replace with StatusModal
2020-06-17 15:56:48 +00:00
ModalPopup {
id: popup
property var store
2020-06-17 15:56:48 +00:00
property var pubKeys: []
property bool selectChatMembers: true
property int memberCount: 1
readonly property int maxMembers: 10
property string channelNameValidationError: ""
2020-06-17 15:56:48 +00:00
onOpened: {
groupName.text = "";
searchBox.text = "";
selectChatMembers = true;
memberCount = 1;
pubKeys = [];
popup.store.addToGroupContacts.clear();
2020-12-11 20:38:10 +00:00
getContactListObject(popup.store.addToGroupContacts)
2020-12-11 20:38:10 +00:00
popup.store.addToGroupContacts.append({
//% "(You)"
name: userProfile.name + " " + qsTrId("(you)"),
pubKey: userProfile.pubKey,
address: "",
identicon: userProfile.icon,
thumbnailImage: userProfile.icon,
2020-06-17 15:56:48 +00:00
isUser: true
});
noContactsRect.visible = !popup.store.allContacts.hasAddedContacts();
2020-12-11 20:38:10 +00:00
contactList.visible = !noContactsRect.visible;
if (!contactList.visible) {
memberCount = 0;
}
2020-06-17 15:56:48 +00:00
}
function validate() {
if (groupName.text === "") {
2021-02-18 16:36:05 +00:00
//% "You need to enter a channel name"
channelNameValidationError = qsTrId("you-need-to-enter-a-channel-name")
} else if (!Utils.isValidChannelName(groupName.text)) {
2021-02-18 16:36:05 +00:00
//% "The channel name can only contain lowercase letters, numbers and dashes"
channelNameValidationError = qsTrId("the-channel-name-can-only-contain-lowercase-letters--numbers-and-dashes")
} else {
channelNameValidationError = ""
}
return channelNameValidationError === ""
}
function doJoin() {
if (!validate()) {
return
}
2020-12-11 20:38:10 +00:00
if (pubKeys.length === 0) {
return;
}
// Not Refactored Yet
// popup.store.chatsModelInst.groups.create(Utils.filterXSS(groupName.text), JSON.stringify(pubKeys));
2020-06-17 15:56:48 +00:00
popup.close();
}
function groupNameFilter(text) {
groupName.text = text.toLowerCase().replace(' ', '-');
}
2020-06-17 15:56:48 +00:00
header: Item {
height: 30
width: parent.width
StyledText {
2020-06-17 15:56:48 +00:00
id: lblNewGroup
//% "New group chat"
text: qsTrId("new-group-chat")
2020-06-17 15:56:48 +00:00
anchors.left: parent.left
font.bold: true
font.pixelSize: 17
anchors.top: parent.top
}
StyledText {
2020-06-17 15:56:48 +00:00
anchors.top: lblNewGroup.bottom
//% "%1 / 10 members"
text: qsTrId("%1-/-10-members").arg(memberCount)
color: Style.current.secondaryText
2020-06-17 15:56:48 +00:00
font.pixelSize: 15
}
}
2020-06-18 13:54:08 +00:00
SearchBox {
2020-06-17 15:56:48 +00:00
id: searchBox
visible: selectChatMembers
iconWidth: 17
iconHeight: 17
2020-06-18 13:54:08 +00:00
customHeight: 44
fontPixelSize: 15
2020-06-17 15:56:48 +00:00
}
Input {
id: groupName
//% "Group name"
placeholderText: qsTrId("group-name")
2020-06-17 15:56:48 +00:00
visible: !selectChatMembers
validationError: channelNameValidationError
onTextEdited: function (text) {
groupNameFilter(text)
}
validator: RegExpValidator { regExp: /^[a-zA-Z0-9\-\ ]+$/ }
2020-06-17 15:56:48 +00:00
}
2020-12-11 20:38:10 +00:00
NoFriendsRectangle {
id: noContactsRect
visible: false
anchors.top: groupName.bottom
anchors.topMargin: Style.current.xlPadding
anchors.horizontalCenter: parent.horizontalCenter
}
ContactListPanel {
2020-12-11 20:38:10 +00:00
id: contactList
anchors.fill: parent
model: popup.store.addToGroupContacts
2020-12-11 20:38:10 +00:00
searchString: searchBox.text.toLowerCase()
selectMode: selectChatMembers && memberCount < maxMembers
2020-06-17 15:56:48 +00:00
anchors.topMargin: 50
anchors.top: searchBox.bottom
2020-12-11 20:38:10 +00:00
onItemChecked: function(pubKey, itemChecked){
var idx = pubKeys.indexOf(pubKey)
if(itemChecked){
if(idx === -1){
pubKeys.push(pubKey)
2020-06-17 15:56:48 +00:00
}
2020-12-11 20:38:10 +00:00
} else {
if(idx > -1){
pubKeys.splice(idx, 1);
2020-06-17 15:56:48 +00:00
}
}
2020-12-11 20:38:10 +00:00
memberCount = pubKeys.length + 1;
btnSelectMembers.enabled = pubKeys.length > 0
2020-06-17 15:56:48 +00:00
}
}
2020-12-11 20:38:10 +00:00
2020-06-17 15:56:48 +00:00
footer: Item {
width: parent.width
height: btnSelectMembers.height
2020-06-17 15:56:48 +00:00
StatusRoundButton {
2020-06-17 15:56:48 +00:00
id: btnSelectMembers
visible: selectChatMembers
anchors.bottom: parent.bottom
anchors.right: parent.right
icon.name: "arrow-right"
icon.width: 20
icon.height: 16
enabled: !!pubKeys.length
onClicked : {
if(pubKeys.length > 0)
selectChatMembers = false
searchBox.text = ""
groupName.forceActiveFocus(Qt.MouseFocusReason)
2020-06-17 15:56:48 +00:00
}
}
StatusRoundButton {
2020-06-17 15:56:48 +00:00
id: btnBack
visible: !selectChatMembers
anchors.bottom: parent.bottom
anchors.left: parent.left
icon.name: "arrow-right"
icon.width: 20
icon.height: 16
icon.rotation: 180
onClicked : {
selectChatMembers = true
2020-06-17 15:56:48 +00:00
}
}
StatusButton {
2020-06-17 15:56:48 +00:00
visible: !selectChatMembers
anchors.bottom: parent.bottom
anchors.right: parent.right
//% "Create Group Chat"
text: qsTrId("create-group-chat")
enabled: groupName.text !== ""
2020-06-17 15:56:48 +00:00
onClicked : doJoin()
}
}
}