History

add ui to kick api

danteruiz committed 7 years ago

Commit 5f3e31b1 parent 98eec6b8 files · +56 −6Browse files

Showing the changes to libraries/script-engine/src/UsersScriptingInterface.cpp (1 of 8 files). Show all

Unified · Split

libraries/script-engine/src/UsersScriptingInterface.cpp+39−2
@@ -12,6 +12,8 @@ · 11 unmodified lines
1212 #include "UsersScriptingInterface.h"
1313
1414 #include <NodeList.h>
15+#include <AvatarHashMap.h>
16+#include <OffscreenUi.h>
1517
1618 UsersScriptingInterface::UsersScriptingInterface() {
1719 // emit a signal when kick permissions have changed
@@ -52,8 +54,43 @@ float UsersScriptingInterface::getAvatarGain(const QUuid& nodeID) { · 34 unmodified lines
5254 }
5355
5456 void UsersScriptingInterface::kick(const QUuid& nodeID) {
55− // ask the NodeList to kick the user with the given session ID
56− DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID);
57+ bool waitingForKickResponse = _kickResponseLock.resultWithReadLock<bool>([&] { return _waitingForKickResponse; });
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+ }
5794 }
5895
5996 void UsersScriptingInterface::mute(const QUuid& nodeID) {