[UserContextMenu] Refactor: Consolidate actions (#7022)

This commit is contained in:
RickyRister 2026-07-05 18:24:52 -07:00 committed by GitHub
parent baddbfae14
commit 430fc117b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 89 deletions

View file

@ -436,103 +436,35 @@ void UserContextMenu::showContextMenu(const QPoint &pos,
QAction *actionClicked = menu->exec(pos); QAction *actionClicked = menu->exec(pos);
if (actionClicked == nullptr) { if (actionClicked == nullptr) {
} else if (actionClicked == aDetails) { } else if (actionClicked == aDetails) {
auto *infoWidget = execDetails(userName);
new UserInfoBox(client, false, static_cast<QWidget *>(parent()),
Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
infoWidget->setAttribute(Qt::WA_DeleteOnClose);
infoWidget->updateInfo(userName);
} else if (actionClicked == aChat) { } else if (actionClicked == aChat) {
emit openMessageDialog(userName, true); execChat(userName);
} else if (actionClicked == aShowGames) { } else if (actionClicked == aShowGames) {
Command_GetGamesOfUser cmd; execShowGames(userName);
cmd.set_user_name(userName.toStdString());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, &PendingCommand::finished, this, &UserContextMenu::gamesOfUserReceived);
client->sendCommand(pend);
} else if (actionClicked == aAddToBuddyList) { } else if (actionClicked == aAddToBuddyList) {
Command_AddToList cmd; execAddToBuddy(userName);
cmd.set_list("buddy");
cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd));
} else if (actionClicked == aRemoveFromBuddyList) { } else if (actionClicked == aRemoveFromBuddyList) {
Command_RemoveFromList cmd; execRemoveFromBuddy(userName);
cmd.set_list("buddy");
cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd));
} else if (actionClicked == aAddToIgnoreList) { } else if (actionClicked == aAddToIgnoreList) {
Command_AddToList cmd; execAddToIgnore(userName);
cmd.set_list("ignore");
cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd));
} else if (actionClicked == aRemoveFromIgnoreList) { } else if (actionClicked == aRemoveFromIgnoreList) {
Command_RemoveFromList cmd; execRemoveFromIgnore(userName);
cmd.set_list("ignore");
cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd));
} else if (actionClicked == aKick) { } else if (actionClicked == aKick) {
auto result = QMessageBox::question(static_cast<QWidget *>(parent()), tr("Kick Player"), execKick(playerId);
tr("Are you sure you want to kick this player from the game?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (result == QMessageBox::Yes) {
Command_KickFromGame cmd;
cmd.set_player_id(playerId);
game->getGameEventHandler()->sendGameCommand(cmd);
}
} else if (actionClicked == aBan) { } else if (actionClicked == aBan) {
Command_GetUserInfo cmd; execBan(userName);
cmd.set_user_name(userName.toStdString());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, &PendingCommand::finished, this, &UserContextMenu::banUser_processUserInfoResponse);
client->sendCommand(pend);
} else if (actionClicked == aPromoteToMod || actionClicked == aDemoteFromMod) { } else if (actionClicked == aPromoteToMod || actionClicked == aDemoteFromMod) {
Command_AdjustMod cmd; execAdjustMod(userName, actionClicked == aPromoteToMod);
cmd.set_user_name(userName.toStdString());
cmd.set_should_be_mod(actionClicked == aPromoteToMod);
PendingCommand *pend = client->prepareAdminCommand(cmd);
connect(pend, &PendingCommand::finished, this, &UserContextMenu::adjustMod_processUserResponse);
client->sendCommand(pend);
} else if (actionClicked == aPromoteToJudge || actionClicked == aDemoteFromJudge) { } else if (actionClicked == aPromoteToJudge || actionClicked == aDemoteFromJudge) {
Command_AdjustMod cmd; execAdjustJudge(userName, actionClicked == aPromoteToJudge);
cmd.set_user_name(userName.toStdString());
cmd.set_should_be_judge(actionClicked == aPromoteToJudge);
PendingCommand *pend = client->prepareAdminCommand(cmd);
connect(pend, &PendingCommand::finished, this, &UserContextMenu::adjustMod_processUserResponse);
client->sendCommand(pend);
} else if (actionClicked == aBanHistory) { } else if (actionClicked == aBanHistory) {
Command_GetBanHistory cmd; execBanHistory(userName);
cmd.set_user_name(userName.toStdString());
PendingCommand *pend = client->prepareModeratorCommand(cmd);
connect(pend, &PendingCommand::finished, this, &UserContextMenu::banUserHistory_processResponse);
client->sendCommand(pend);
} else if (actionClicked == aWarnUser) { } else if (actionClicked == aWarnUser) {
Command_GetUserInfo cmd; execWarn(userName);
cmd.set_user_name(userName.toStdString());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, &PendingCommand::finished, this, &UserContextMenu::warnUser_processUserInfoResponse);
client->sendCommand(pend);
} else if (actionClicked == aWarnHistory) { } else if (actionClicked == aWarnHistory) {
Command_GetWarnHistory cmd; execWarnHistory(userName);
cmd.set_user_name(userName.toStdString());
PendingCommand *pend = client->prepareModeratorCommand(cmd);
connect(pend, &PendingCommand::finished, this, &UserContextMenu::warnUserHistory_processResponse);
client->sendCommand(pend);
} else if (actionClicked == aGetAdminNotes) { } else if (actionClicked == aGetAdminNotes) {
Command_GetAdminNotes cmd; execAdminNotes(userName);
cmd.set_user_name(userName.toStdString());
auto *pend = client->prepareModeratorCommand(cmd);
connect(pend, &PendingCommand::finished, this, &UserContextMenu::getAdminNotes_processResponse);
client->sendCommand(pend);
} else if (actionClicked == aCopyToClipBoard) { } else if (actionClicked == aCopyToClipBoard) {
QClipboard *clipboard = QGuiApplication::clipboard(); QClipboard *clipboard = QGuiApplication::clipboard();
clipboard->setText(deckHash); clipboard->setText(deckHash);
@ -597,6 +529,19 @@ void UserContextMenu::execRemoveFromIgnore(const QString &userName)
client->sendCommand(client->prepareSessionCommand(cmd)); client->sendCommand(client->prepareSessionCommand(cmd));
} }
void UserContextMenu::execKick(int playerId)
{
auto result = QMessageBox::question(static_cast<QWidget *>(parent()), tr("Kick Player"),
tr("Are you sure you want to kick this player from the game?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (result == QMessageBox::Yes) {
Command_KickFromGame cmd;
cmd.set_player_id(playerId);
game->getGameEventHandler()->sendGameCommand(cmd);
}
}
void UserContextMenu::execBan(const QString &userName) void UserContextMenu::execBan(const QString &userName)
{ {
Command_GetUserInfo cmd; Command_GetUserInfo cmd;
@ -642,11 +587,20 @@ void UserContextMenu::execAdminNotes(const QString &userName)
client->sendCommand(pend); client->sendCommand(pend);
} }
void UserContextMenu::execAdjustMod(const QString &userName, bool shouldBeMod, bool shouldBeJudge) void UserContextMenu::execAdjustMod(const QString &userName, bool shouldBeMod)
{ {
Command_AdjustMod cmd; Command_AdjustMod cmd;
cmd.set_user_name(userName.toStdString()); cmd.set_user_name(userName.toStdString());
cmd.set_should_be_mod(shouldBeMod); cmd.set_should_be_mod(shouldBeMod);
PendingCommand *pend = client->prepareAdminCommand(cmd);
connect(pend, &PendingCommand::finished, this, &UserContextMenu::adjustMod_processUserResponse);
client->sendCommand(pend);
}
void UserContextMenu::execAdjustJudge(const QString &userName, bool shouldBeJudge)
{
Command_AdjustMod cmd;
cmd.set_user_name(userName.toStdString());
cmd.set_should_be_judge(shouldBeJudge); cmd.set_should_be_judge(shouldBeJudge);
PendingCommand *pend = client->prepareAdminCommand(cmd); PendingCommand *pend = client->prepareAdminCommand(cmd);
connect(pend, &PendingCommand::finished, this, &UserContextMenu::adjustMod_processUserResponse); connect(pend, &PendingCommand::finished, this, &UserContextMenu::adjustMod_processUserResponse);

View file

@ -89,12 +89,14 @@ public:
void execRemoveFromBuddy(const QString &userName); void execRemoveFromBuddy(const QString &userName);
void execAddToIgnore(const QString &userName); void execAddToIgnore(const QString &userName);
void execRemoveFromIgnore(const QString &userName); void execRemoveFromIgnore(const QString &userName);
void execKick(int playerId);
void execBan(const QString &userName); void execBan(const QString &userName);
void execWarn(const QString &userName); void execWarn(const QString &userName);
void execBanHistory(const QString &userName); void execBanHistory(const QString &userName);
void execWarnHistory(const QString &userName); void execWarnHistory(const QString &userName);
void execAdminNotes(const QString &userName); void execAdminNotes(const QString &userName);
void execAdjustMod(const QString &userName, bool shouldBeMod, bool shouldBeJudge); void execAdjustMod(const QString &userName, bool shouldBeMod);
void execAdjustJudge(const QString &userName, bool shouldBeJudge);
}; };
#endif #endif

View file

@ -707,13 +707,13 @@ void UserListWidget::connectPopupSignals()
connect(m_userInfoPopup, &UserInfoPopup::warnHistoryRequested, userContextMenu, &UserContextMenu::execWarnHistory); connect(m_userInfoPopup, &UserInfoPopup::warnHistoryRequested, userContextMenu, &UserContextMenu::execWarnHistory);
connect(m_userInfoPopup, &UserInfoPopup::adminNotesRequested, userContextMenu, &UserContextMenu::execAdminNotes); connect(m_userInfoPopup, &UserInfoPopup::adminNotesRequested, userContextMenu, &UserContextMenu::execAdminNotes);
connect(m_userInfoPopup, &UserInfoPopup::promoteToModRequested, this, connect(m_userInfoPopup, &UserInfoPopup::promoteToModRequested, this,
[this](const QString &n) { userContextMenu->execAdjustMod(n, true, false); }); [this](const QString &n) { userContextMenu->execAdjustMod(n, true); });
connect(m_userInfoPopup, &UserInfoPopup::demoteFromModRequested, this, connect(m_userInfoPopup, &UserInfoPopup::demoteFromModRequested, this,
[this](const QString &n) { userContextMenu->execAdjustMod(n, false, false); }); [this](const QString &n) { userContextMenu->execAdjustMod(n, false); });
connect(m_userInfoPopup, &UserInfoPopup::promoteToJudgeRequested, this, connect(m_userInfoPopup, &UserInfoPopup::promoteToJudgeRequested, this,
[this](const QString &n) { userContextMenu->execAdjustMod(n, false, true); }); [this](const QString &n) { userContextMenu->execAdjustJudge(n, true); });
connect(m_userInfoPopup, &UserInfoPopup::demoteFromJudgeRequested, this, connect(m_userInfoPopup, &UserInfoPopup::demoteFromJudgeRequested, this,
[this](const QString &n) { userContextMenu->execAdjustMod(n, false, false); }); [this](const QString &n) { userContextMenu->execAdjustJudge(n, false); });
} }
bool UserListWidget::eventFilter(QObject *obj, QEvent *event) bool UserListWidget::eventFilter(QObject *obj, QEvent *event)