2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-12-12 03:42:59 +11:00
|
|
|
import QtQuick 2.12
|
2020-05-30 06:35:27 +10:00
|
|
|
import QtQuick.Controls 2.12
|
2019-12-12 03:42:59 +11:00
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import "../Base"
|
2020-07-12 12:52:14 +10:00
|
|
|
import "../Base/Buttons"
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
HColumnPopup {
|
2019-12-12 03:42:59 +11:00
|
|
|
id: popup
|
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
property string userId
|
|
|
|
property string roomId
|
|
|
|
property string roomName
|
|
|
|
property bool invitingAllowed: true
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
property var inviteFuture: null
|
|
|
|
property var successfulInvites: []
|
|
|
|
property var failedInvites: []
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
function invite() {
|
|
|
|
inviteButton.loading = true
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
const inviteesLeft = inviteArea.text.trim().split(/\s+/).filter(
|
|
|
|
user => ! successfulInvites.includes(user)
|
|
|
|
)
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
inviteFuture = py.callClientCoro(
|
|
|
|
userId,
|
|
|
|
"room_mass_invite",
|
|
|
|
[roomId, ...inviteesLeft],
|
|
|
|
|
|
|
|
([successes, errors]) => {
|
|
|
|
if (errors.length < 1) {
|
|
|
|
popup.close()
|
|
|
|
return
|
2019-12-12 03:42:59 +11:00
|
|
|
}
|
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
successfulInvites = successes
|
|
|
|
failedInvites = errors
|
|
|
|
inviteButton.loading = false
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2019-12-12 03:42:59 +11:00
|
|
|
|
|
|
|
|
2020-07-12 12:52:14 +10:00
|
|
|
page.footer: AutoDirectionLayout {
|
2020-06-25 22:32:08 +10:00
|
|
|
ApplyButton {
|
|
|
|
id: inviteButton
|
|
|
|
text: qsTr("Invite")
|
|
|
|
icon.name: "room-send-invite"
|
|
|
|
enabled: invitingAllowed && Boolean(inviteArea.text.trim())
|
|
|
|
onClicked: invite()
|
|
|
|
}
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
CancelButton {
|
|
|
|
id: cancelButton
|
|
|
|
onClicked: popup.close()
|
|
|
|
}
|
|
|
|
}
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2020-06-25 22:32:08 +10:00
|
|
|
onOpened: inviteArea.forceActiveFocus()
|
|
|
|
onClosed: if (inviteFuture) inviteFuture.cancel()
|
|
|
|
|
|
|
|
onInvitingAllowedChanged:
|
|
|
|
if (! invitingAllowed && inviteFuture) inviteFuture.cancel()
|
|
|
|
|
|
|
|
SummaryLabel {
|
|
|
|
text: qsTr("Invite members to <i>%1</i>").arg(roomName)
|
|
|
|
textFormat: Text.StyledText
|
|
|
|
}
|
2019-12-12 03:42:59 +11:00
|
|
|
|
2020-06-23 03:57:49 +10:00
|
|
|
HScrollView {
|
2020-06-25 22:32:08 +10:00
|
|
|
clip: true
|
|
|
|
|
2019-12-12 03:42:59 +11:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
2020-05-30 06:35:27 +10:00
|
|
|
|
|
|
|
HTextArea {
|
|
|
|
id: inviteArea
|
2020-06-25 22:32:08 +10:00
|
|
|
focusItemOnTab: inviteButton.enabled ? inviteButton : cancelButton
|
2020-05-30 06:35:27 +10:00
|
|
|
placeholderText:
|
|
|
|
qsTr("User IDs (e.g. @bob:matrix.org @alice:localhost)")
|
|
|
|
}
|
2019-12-12 03:42:59 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
HLabel {
|
|
|
|
id: errorMessage
|
|
|
|
|
|
|
|
readonly property string allErrors: {
|
|
|
|
// TODO: handle these: real user not found
|
|
|
|
const lines = []
|
|
|
|
|
2020-03-08 19:46:20 +11:00
|
|
|
for (const [user, error] of failedInvites) {
|
2019-12-12 03:42:59 +11:00
|
|
|
const type = py.getattr(
|
|
|
|
py.getattr(error, "__class__"), "__name__",
|
|
|
|
)
|
|
|
|
|
|
|
|
lines.push(
|
|
|
|
type === "InvalidUserId" ?
|
|
|
|
qsTr("%1 is not a valid user ID, expected format is " +
|
|
|
|
"@username:homeserver").arg(user) :
|
|
|
|
|
2020-03-09 22:59:23 +11:00
|
|
|
type === "UserFromOtherServerDisallowed" ?
|
|
|
|
qsTr("This room rejects users from other matrix " +
|
|
|
|
"servers, can't invite %1").arg(user) :
|
|
|
|
|
2020-06-03 10:19:09 +10:00
|
|
|
type === "MatrixNotFound" ?
|
2020-06-03 10:30:04 +10:00
|
|
|
qsTr("%1 not found, please verify the entered ID")
|
2019-12-12 03:42:59 +11:00
|
|
|
.arg(user) :
|
|
|
|
|
2020-05-30 06:45:08 +10:00
|
|
|
type === "MatrixBadGateway" ?
|
2020-06-03 10:30:04 +10:00
|
|
|
qsTr("Could not contact %1's server, " +
|
|
|
|
"please verify the entered ID").arg(user) :
|
2020-05-30 06:45:08 +10:00
|
|
|
|
2019-12-12 03:42:59 +11:00
|
|
|
type === "MatrixUnsupportedRoomVersion" ?
|
|
|
|
qsTr("%1's server does not support this room's version")
|
|
|
|
.arg(user) :
|
|
|
|
|
|
|
|
type === "MatrixForbidden" ?
|
|
|
|
qsTr("%1 is banned from this room")
|
|
|
|
.arg(user) :
|
|
|
|
|
|
|
|
qsTr("Unknown error while inviting %1: %2 - %3")
|
|
|
|
.arg(user).arg(type).arg(py.getattr(error, "args"))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return lines.join("\n\n")
|
|
|
|
}
|
|
|
|
|
2020-07-12 14:25:57 +10:00
|
|
|
visible: Layout.maximumHeight > 0
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
color: theme.colors.errorText
|
|
|
|
text:
|
|
|
|
invitingAllowed ?
|
|
|
|
allErrors :
|
|
|
|
qsTr("You do not have permission to invite members to this room")
|
|
|
|
|
|
|
|
Layout.maximumHeight: text ? implicitHeight : 0
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
2019-12-12 03:42:59 +11:00
|
|
|
Behavior on Layout.maximumHeight { HNumberAnimation {} }
|
|
|
|
}
|
|
|
|
}
|