Showing the changes to libraries/script-engine/src/UsersScriptingInterface.cpp (1 of 8 files). Show all
Unified · Split
| @@ -12,6 +12,8 @@ · 11 unmodified lines | |||
| 12 | #include "UsersScriptingInterface.h" | 12 | #include "UsersScriptingInterface.h" |
| 13 | 13 | ||
| 14 | #include <NodeList.h> | 14 | #include <NodeList.h> |
| 15 | #include <AvatarHashMap.h> | ||
| 16 | #include <OffscreenUi.h> | ||
| 15 | 17 | ||
| 16 | UsersScriptingInterface::UsersScriptingInterface() { | 18 | UsersScriptingInterface::UsersScriptingInterface() { |
| 17 | // emit a signal when kick permissions have changed | 19 | // emit a signal when kick permissions have changed |
| @@ -52,8 +54,43 @@ float UsersScriptingInterface::getAvatarGain(const QUuid& nodeID) { · 34 unmodified lines | |||
| 52 | } | 54 | } |
| 53 | 55 | ||
| 54 | void UsersScriptingInterface::kick(const QUuid& nodeID) { | 56 | void UsersScriptingInterface::kick(const QUuid& nodeID) { |
| 55 | // ask the NodeList to kick the user with the given session ID | 57 | bool waitingForKickResponse = _kickResponseLock.resultWithReadLock<bool>([&] { return _waitingForKickResponse; }); |
| 56 | DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID); | 58 | if (getCanKick() && !waitingForKickResponse) { |
| 59 | |||
| 60 | |||
| 61 | auto avatarHashMap = DependencyManager::get<AvatarHashMap>(); | ||
| 62 | auto avatar = avatarHashMap->getAvatarBySessionID(nodeID); | ||
| 63 | |||
| 64 | QString userName; | ||
| 65 | |||
| 66 | if (avatar) { | ||
| 67 | userName = avatar->getSessionDisplayName(); | ||
| 68 | } else { | ||
| 69 | userName = nodeID.toString(); | ||
| 70 | } | ||
| 71 | |||
| 72 | QString kickMessage = "Do you wish to kick " + userName + " from your domain"; | ||
| 73 | ModalDialogListener* dlg = OffscreenUi::asyncQuestion("Kick User", kickMessage, | ||
| 74 | QMessageBox::Yes | QMessageBox::No); | ||
| 75 | |||
| 76 | if (dlg->getDialogItem()) { | ||
| 77 | |||
| 78 | QObject::connect(dlg, &ModalDialogListener::response, this, [=] (QVariant answer) { | ||
| 79 | QObject::disconnect(dlg, &ModalDialogListener::response, this, nullptr); | ||
| 80 | |||
| 81 | bool yes = (static_cast<QMessageBox::StandardButton>(answer.toInt()) == QMessageBox::Yes); | ||
| 82 | // ask the NodeList to kick the user with the given session ID | ||
| 83 | |||
| 84 | if (yes) { | ||
| 85 | DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID); | ||
| 86 | } | ||
| 87 | |||
| 88 | _kickResponseLock.withWriteLock([&] { _waitingForKickResponse = false; }); | ||
| 89 | }); | ||
| 90 | |||
| 91 | _kickResponseLock.withWriteLock([&] { _waitingForKickResponse = true; }); | ||
| 92 | } | ||
| 93 | } | ||
| 57 | } | 94 | } |
| 58 | 95 | ||
| 59 | void UsersScriptingInterface::mute(const QUuid& nodeID) { | 96 | void UsersScriptingInterface::mute(const QUuid& nodeID) { |