feat: whitelist the characters possible for the channel names
This commit is contained in:
parent
0174bb4e21
commit
6869a3ddfb
|
@ -13,6 +13,7 @@ ModalPopup {
|
||||||
property bool selectChatMembers: true
|
property bool selectChatMembers: true
|
||||||
property int memberCount: 1
|
property int memberCount: 1
|
||||||
readonly property int maxMembers: 10
|
readonly property int maxMembers: 10
|
||||||
|
property string channelNameValidationError: ""
|
||||||
|
|
||||||
onOpened: {
|
onOpened: {
|
||||||
groupName.text = "";
|
groupName.text = "";
|
||||||
|
@ -55,8 +56,25 @@ ModalPopup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doJoin(){
|
function validate() {
|
||||||
if(pubKeys.length === 0) return;
|
if (groupName.text === "") {
|
||||||
|
channelNameValidationError = qsTr("You need to enter a channel name")
|
||||||
|
} else if (!Utils.isValidChannelName(groupName.text)) {
|
||||||
|
channelNameValidationError = qsTr("The channel name can only contain lowercase letters, numbers and dashes")
|
||||||
|
} else {
|
||||||
|
channelNameValidationError = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return channelNameValidationError === ""
|
||||||
|
}
|
||||||
|
|
||||||
|
function doJoin() {
|
||||||
|
if (!validate()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if(pubKeys.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
chatsModel.createGroup(Utils.filterXSS(groupName.text), JSON.stringify(pubKeys));
|
chatsModel.createGroup(Utils.filterXSS(groupName.text), JSON.stringify(pubKeys));
|
||||||
popup.close();
|
popup.close();
|
||||||
}
|
}
|
||||||
|
@ -98,6 +116,7 @@ ModalPopup {
|
||||||
//% "Group name"
|
//% "Group name"
|
||||||
placeholderText: qsTrId("group-name")
|
placeholderText: qsTrId("group-name")
|
||||||
visible: !selectChatMembers
|
visible: !selectChatMembers
|
||||||
|
validationError: channelNameValidationError
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|
|
@ -8,8 +8,24 @@ import "../data/channelList.js" as ChannelJSON
|
||||||
import "./"
|
import "./"
|
||||||
|
|
||||||
ModalPopup {
|
ModalPopup {
|
||||||
|
property string channelNameValidationError: ""
|
||||||
|
|
||||||
|
function validate() {
|
||||||
|
if (channelName.text === "") {
|
||||||
|
channelNameValidationError = qsTr("You need to enter a channel name")
|
||||||
|
} else if (!Utils.isValidChannelName(channelName.text)) {
|
||||||
|
channelNameValidationError = qsTr("The channel name can only contain lowercase letters, numbers and dashes")
|
||||||
|
} else {
|
||||||
|
channelNameValidationError = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return channelNameValidationError === ""
|
||||||
|
}
|
||||||
|
|
||||||
function doJoin() {
|
function doJoin() {
|
||||||
if(channelName.text === "") return;
|
if (!validate()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
chatsModel.joinChat(channelName.text, Constants.chatTypePublic);
|
chatsModel.joinChat(channelName.text, Constants.chatTypePublic);
|
||||||
popup.close();
|
popup.close();
|
||||||
}
|
}
|
||||||
|
@ -48,6 +64,7 @@ ModalPopup {
|
||||||
Keys.onEnterPressed: doJoin()
|
Keys.onEnterPressed: doJoin()
|
||||||
Keys.onReturnPressed: doJoin()
|
Keys.onReturnPressed: doJoin()
|
||||||
icon: "../../../img/hash.svg"
|
icon: "../../../img/hash.svg"
|
||||||
|
validationError: channelNameValidationError
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollView {
|
ScrollView {
|
||||||
|
|
|
@ -146,6 +146,10 @@ QtObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isValidChannelName(channelName) {
|
||||||
|
return (/^[a-z0-9\-]+$/.test(channelName))
|
||||||
|
}
|
||||||
|
|
||||||
function isSpace(c) {
|
function isSpace(c) {
|
||||||
return (/( |\t|\n|\r)/.test(c))
|
return (/( |\t|\n|\r)/.test(c))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue