moment/src/gui/Popups/InviteToRoomPopup.qml

134 lines
3.9 KiB
QML
Raw Normal View History

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"
BoxPopup {
id: popup
// fillAvailableHeight: true
2019-12-14 08:08:59 +11:00
summary.text: qsTr("Invite members to <i>%1</i>").arg(roomName)
summary.textFormat: Text.StyledText
2019-12-12 03:42:59 +11:00
okText: qsTr("Invite")
okEnabled: invitingAllowed && Boolean(inviteArea.text.trim())
2020-05-30 06:35:27 +10:00
onOpened: inviteArea.forceActiveFocus()
2019-12-12 03:42:59 +11:00
onInvitingAllowedChanged:
if (! invitingAllowed && inviteFuture) inviteFuture.cancel()
box.buttonCallbacks: ({
ok: button => {
button.loading = true
const inviteesLeft = inviteArea.text.trim().split(/\s+/).filter(
user => ! successfulInvites.includes(user)
)
inviteFuture = py.callClientCoro(
userId,
"room_mass_invite",
[roomId, ...inviteesLeft],
([successes, errors]) => {
if (errors.length < 1) {
popup.close()
return
}
successfulInvites = successes
failedInvites = errors
button.loading = false
}
)
},
cancel: button => {
if (inviteFuture) inviteFuture.cancel()
popup.close()
},
})
property string userId
property string roomId
2019-12-14 08:08:59 +11:00
property string roomName
2019-12-12 03:42:59 +11:00
property bool invitingAllowed: true
property var inviteFuture: null
property var successfulInvites: []
property var failedInvites: []
2020-05-30 06:35:27 +10:00
ScrollView {
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
focusItemOnTab: box.firstButton
placeholderText:
qsTr("User IDs (e.g. @bob:matrix.org @alice:localhost)")
}
2019-12-12 03:42:59 +11:00
}
HLabel {
id: errorMessage
visible: Layout.maximumHeight > 0
wrapMode: Text.Wrap
color: theme.colors.errorText
text:
invitingAllowed ?
allErrors :
2019-12-23 02:21:47 +11:00
qsTr("You do not have permission to invite members to this room")
2019-12-12 03:42:59 +11:00
Layout.maximumHeight: text ? implicitHeight : 0
Layout.fillWidth: true
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) :
type === "UserFromOtherServerDisallowed" ?
qsTr("This room rejects users from other matrix " +
"servers, can't invite %1").arg(user) :
type === "MatrixNotFound" ?
2019-12-12 03:42:59 +11:00
qsTr("%1 not found, please verify the entered user ID")
.arg(user) :
type === "MatrixBadGateway" ?
qsTr("Server error while trying to find %1, please " +
"verify the entered user ID").arg(user) :
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")
}
Behavior on Layout.maximumHeight { HNumberAnimation {} }
}
}