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
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared.controls 1.0
|
2021-10-21 15:07:13 +00:00
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared.views 1.0
|
|
|
|
import shared.panels 1.0
|
|
|
|
import shared.popups 1.0
|
2021-10-01 15:58:36 +00:00
|
|
|
import "../panels"
|
|
|
|
import "../controls"
|
2020-06-17 15:56:48 +00:00
|
|
|
|
2021-10-14 11:33:34 +00:00
|
|
|
// TODO: replace with StatusModal
|
2020-06-17 15:56:48 +00:00
|
|
|
ModalPopup {
|
|
|
|
id: popup
|
|
|
|
|
2021-12-08 12:31:28 +00:00
|
|
|
property var chatSectionModule
|
2021-10-22 20:49:47 +00:00
|
|
|
property var store
|
2020-06-17 15:56:48 +00:00
|
|
|
property bool selectChatMembers: true
|
|
|
|
property int memberCount: 1
|
|
|
|
readonly property int maxMembers: 10
|
2020-11-06 19:46:21 +00:00
|
|
|
property string channelNameValidationError: ""
|
2020-06-17 15:56:48 +00:00
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
groupName.text = "";
|
|
|
|
searchBox.text = "";
|
|
|
|
selectChatMembers = true;
|
|
|
|
memberCount = 1;
|
2022-02-14 12:18:25 +00:00
|
|
|
contactList.selectedPubKeys = [];
|
2020-06-17 15:56:48 +00:00
|
|
|
|
2022-02-14 12:18:25 +00:00
|
|
|
chatSectionModule.populateMyContacts("")
|
2020-12-11 20:38:10 +00:00
|
|
|
|
2021-12-08 12:31:28 +00:00
|
|
|
noContactsRect.visible = !chatSectionModule.listOfMyContacts.rowCount() > 0
|
2020-12-11 20:38:10 +00:00
|
|
|
contactList.visible = !noContactsRect.visible;
|
|
|
|
if (!contactList.visible) {
|
2020-08-10 02:14:21 +00:00
|
|
|
memberCount = 0;
|
|
|
|
}
|
2020-06-17 15:56:48 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 12:31:28 +00:00
|
|
|
onClosed: chatSectionModule.clearMyContacts()
|
|
|
|
|
2020-11-06 19:46:21 +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")
|
2020-11-06 19:46:21 +00:00
|
|
|
} 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")
|
2020-11-06 19:46:21 +00:00
|
|
|
} else {
|
|
|
|
channelNameValidationError = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return channelNameValidationError === ""
|
|
|
|
}
|
|
|
|
|
|
|
|
function doJoin() {
|
|
|
|
if (!validate()) {
|
|
|
|
return
|
|
|
|
}
|
2022-02-14 12:18:25 +00:00
|
|
|
if (contactList.selectedPubKeys.length === 0) {
|
2020-11-06 19:46:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-12-08 12:31:28 +00:00
|
|
|
|
2022-02-14 12:18:25 +00:00
|
|
|
popup.chatSectionModule.createGroupChat(Utils.filterXSS(groupName.text), JSON.stringify(contactList.selectedPubKeys));
|
2020-06-17 15:56:48 +00:00
|
|
|
popup.close();
|
|
|
|
}
|
|
|
|
|
2021-01-20 20:56:38 +00:00
|
|
|
function groupNameFilter(text) {
|
|
|
|
groupName.text = text.toLowerCase().replace(' ', '-');
|
|
|
|
}
|
|
|
|
|
2020-06-17 15:56:48 +00:00
|
|
|
header: Item {
|
|
|
|
height: 30
|
|
|
|
width: parent.width
|
2022-02-09 09:43:23 +00:00
|
|
|
|
2020-06-19 18:06:58 +00:00
|
|
|
StyledText {
|
2020-06-17 15:56:48 +00:00
|
|
|
id: lblNewGroup
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "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
|
|
|
|
}
|
|
|
|
|
2020-06-19 18:06:58 +00:00
|
|
|
StyledText {
|
2020-06-17 15:56:48 +00:00
|
|
|
anchors.top: lblNewGroup.bottom
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "%1 / 10 members"
|
|
|
|
text: qsTrId("%1-/-10-members").arg(memberCount)
|
2021-02-18 19:07:23 +00:00
|
|
|
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
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Group name"
|
|
|
|
placeholderText: qsTrId("group-name")
|
2020-06-17 15:56:48 +00:00
|
|
|
visible: !selectChatMembers
|
2020-11-06 19:46:21 +00:00
|
|
|
validationError: channelNameValidationError
|
2021-01-20 20:56:38 +00:00
|
|
|
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 {
|
2020-08-10 02:14:21 +00:00
|
|
|
id: noContactsRect
|
2021-10-27 14:17:15 +00:00
|
|
|
visible: false
|
2020-08-10 02:14:21 +00:00
|
|
|
anchors.top: groupName.bottom
|
|
|
|
anchors.topMargin: Style.current.xlPadding
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
|
2021-10-01 15:58:36 +00:00
|
|
|
ContactListPanel {
|
2020-12-11 20:38:10 +00:00
|
|
|
id: contactList
|
2021-11-30 10:50:53 +00:00
|
|
|
anchors.fill: parent
|
2021-12-08 12:31:28 +00:00
|
|
|
model: chatSectionModule.listOfMyContacts
|
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
|
2022-02-14 12:18:25 +00:00
|
|
|
onSelectedPubKeysChanged:{
|
|
|
|
memberCount = selectedPubKeys.length + 1;
|
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 {
|
2021-01-13 19:15:52 +00:00
|
|
|
width: parent.width
|
|
|
|
height: btnSelectMembers.height
|
2020-06-17 15:56:48 +00:00
|
|
|
|
2021-10-27 14:17:15 +00:00
|
|
|
StatusRoundButton {
|
2020-06-17 15:56:48 +00:00
|
|
|
id: btnSelectMembers
|
|
|
|
visible: selectChatMembers
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.right: parent.right
|
2021-01-28 11:17:46 +00:00
|
|
|
icon.name: "arrow-right"
|
|
|
|
icon.width: 20
|
|
|
|
icon.height: 16
|
2022-02-14 12:18:25 +00:00
|
|
|
enabled: contactList.selectedPubKeys.length > 0
|
2021-01-28 11:17:46 +00:00
|
|
|
onClicked : {
|
2022-02-14 12:18:25 +00:00
|
|
|
if (contactList.selectedPubKeys.length > 0)
|
2021-01-28 11:17:46 +00:00
|
|
|
selectChatMembers = false
|
|
|
|
searchBox.text = ""
|
|
|
|
groupName.forceActiveFocus(Qt.MouseFocusReason)
|
2020-06-17 15:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-28 11:17:46 +00:00
|
|
|
StatusRoundButton {
|
2020-06-17 15:56:48 +00:00
|
|
|
id: btnBack
|
|
|
|
visible: !selectChatMembers
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.left: parent.left
|
2021-01-28 11:17:46 +00:00
|
|
|
icon.name: "arrow-right"
|
|
|
|
icon.width: 20
|
|
|
|
icon.height: 16
|
2021-10-21 15:07:13 +00:00
|
|
|
icon.rotation: 180
|
2021-01-28 11:17:46 +00:00
|
|
|
onClicked : {
|
|
|
|
selectChatMembers = true
|
2020-06-17 15:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-28 11:04:10 +00:00
|
|
|
StatusButton {
|
2020-06-17 15:56:48 +00:00
|
|
|
visible: !selectChatMembers
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.right: parent.right
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Create Group Chat"
|
2021-01-28 11:04:10 +00:00
|
|
|
text: qsTrId("create-group-chat")
|
|
|
|
enabled: groupName.text !== ""
|
2020-06-17 15:56:48 +00:00
|
|
|
onClicked : doJoin()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|