Only invite if there is something/someone to invite

This commit is contained in:
Loren Burkholder 2021-07-19 12:31:20 -04:00
parent 74d493ff16
commit 4384554587
3 changed files with 9 additions and 77 deletions

View file

@ -18,13 +18,11 @@ ApplicationWindow {
if (inviteeEntry.text.match("@.+?:.{3,}")) {
invitees.addUser(inviteeEntry.text);
inviteeEntry.clear();
} else {
warningLabel.show();
}
}
function cleanUpAndClose() {
if (inviteeEntry.text !== "")
if (inviteeEntry.text.match("@.+?:.{3,}"))
addInvite();
invitees.accept();
close();
@ -79,80 +77,8 @@ ApplicationWindow {
Button {
text: qsTr("Add")
onClicked: {
if (inviteeEntry.text !== "") {
addInvite();
}
}
}
}
Label {
id: warningLabel
function show() {
state = "shown";
warningLabelTimer.start();
}
text: qsTr("Please enter a valid username (e.g. @joe:matrix.org).")
color: "red"
visible: false
opacity: 0
state: "hidden"
states: [
State {
name: "shown"
PropertyChanges {
target: warningLabel
opacity: 1
visible: true
}
},
State {
name: "hidden"
PropertyChanges {
target: warningLabel
opacity: 0
visible: false
}
}
]
transitions: [
Transition {
from: "shown"
to: "hidden"
reversible: true
SequentialAnimation {
NumberAnimation {
target: warningLabel
property: "opacity"
duration: 500
}
PropertyAction {
target: warningLabel
property: "visible"
}
}
}
]
Timer {
id: warningLabelTimer
interval: 2000
repeat: false
running: false
onTriggered: warningLabel.state = "hidden"
enabled: inviteeEntry.text.match("@.+?:.{3,}")
onClicked: addInvite()
}
}
@ -210,6 +136,7 @@ ApplicationWindow {
Button {
text: qsTr("Invite")
DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
enabled: invitees.count > 0
onClicked: cleanUpAndClose()
}

View file

@ -22,6 +22,8 @@ InviteesModel::addUser(QString mxid)
connect(invitee, &Invitee::userInfoLoaded, this, [this]() { endInsertRows(); });
invitees_.push_back(invitee);
emit countChanged();
}
QHash<int, QByteArray>

View file

@ -30,6 +30,8 @@ class InviteesModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
public:
enum Roles
{
@ -52,6 +54,7 @@ public:
signals:
void accept();
void countChanged();
private:
QVector<Invitee *> invitees_;