Skip to content

Commit

Permalink
Merge PR #5917: FIX(client): Fix target and permission selection in u…
Browse files Browse the repository at this point in the history
…pdateMenuPermissions

This commit addresses two issues within the 'updateMenuPermissions' method:
First, the target selection introduced in be7ad39 was suffering from the same problem as described in #3090 where selected tree items were not preferred for determining targets. This issue caused the chat bar to be erroneously disabled in certain situations, for example when connecting to a channel with "Text Message" permission disabled and switching to a different by left-clicking.
The second issue is an oversight in 441d06f where the 'Use selected item as the chat bar target' option was introduced. The permission check in 'updateMenuPermissions' was not updated to take the new option into account and therefore always used the selected target for the permission query independent of the state of the option.

The fix consists of using the unified 'getContextMenuTargets' for target selection and adding a special case for handling the enabled state of the chat bar by taking the new option into account.

Fixes #1799
  • Loading branch information
Krzmbrzl authored Oct 18, 2022
2 parents e0c2b37 + 8eb12e9 commit 1b26a55
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions src/mumble/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2502,32 +2502,22 @@ void MainWindow::on_qaChannelCopyURL_triggered() {
* @see MainWindow::msgPermissionQuery(const MumbleProto::PermissionQuery &msg)
*/
void MainWindow::updateMenuPermissions() {
ClientUser *cu = nullptr;
Channel *c = nullptr;
ContextMenuTarget target = getContextMenuTargets();

if (Global::get().uiSession) {
cu = getContextMenuUser();
if (!cu)
cu = pmModel->getUser(qtvUsers->currentIndex());

c = cu ? cu->cChannel : getContextMenuChannel();
if (!c)
c = pmModel->getChannel(qtvUsers->currentIndex());
}

ChanACL::Permissions p = c ? static_cast< ChanACL::Permissions >(c->uiPermissions) : ChanACL::None;
ChanACL::Permissions p =
target.channel ? static_cast< ChanACL::Permissions >(target.channel->uiPermissions) : ChanACL::None;

if (c && !p) {
Global::get().sh->requestChannelPermissions(c->iId);
if (c->iId == 0)
if (target.channel && !p) {
Global::get().sh->requestChannelPermissions(target.channel->iId);
if (target.channel->iId == 0)
p = Global::get().pPermissions;
else
p = ChanACL::All;

c->uiPermissions = p;
target.channel->uiPermissions = p;
}

Channel *cparent = c ? c->cParent : nullptr;
Channel *cparent = target.channel ? target.channel->cParent : nullptr;
ChanACL::Permissions pparent =
cparent ? static_cast< ChanACL::Permissions >(cparent->uiPermissions) : ChanACL::None;

Expand Down Expand Up @@ -2555,14 +2545,15 @@ void MainWindow::updateMenuPermissions() {
homec->uiPermissions = homep;
}

if (cu) {
if (target.user) {
qaUserMute->setEnabled(p & (ChanACL::Write | ChanACL::MuteDeafen)
&& ((cu != user) || cu->bMute || cu->bSuppress));
qaUserDeaf->setEnabled(p & (ChanACL::Write | ChanACL::MuteDeafen) && ((cu != user) || cu->bDeaf));
&& ((target.user != user) || target.user->bMute || target.user->bSuppress));
qaUserDeaf->setEnabled(p & (ChanACL::Write | ChanACL::MuteDeafen)
&& ((target.user != user) || target.user->bDeaf));
qaUserPrioritySpeaker->setEnabled(p & (ChanACL::Write | ChanACL::MuteDeafen));
qaUserTextMessage->setEnabled(p & (ChanACL::Write | ChanACL::TextMessage));
qaUserInformation->setEnabled((Global::get().pPermissions & (ChanACL::Write | ChanACL::Register))
|| (p & (ChanACL::Write | ChanACL::Enter)) || (cu == user));
|| (p & (ChanACL::Write | ChanACL::Enter)) || (target.user == user));
} else {
qaUserMute->setEnabled(false);
qaUserDeaf->setEnabled(false);
Expand All @@ -2582,11 +2573,19 @@ void MainWindow::updateMenuPermissions() {
qaChannelUnlink->setEnabled((p & (ChanACL::Write | ChanACL::LinkChannel))
|| (homep & (ChanACL::Write | ChanACL::LinkChannel)));
qaChannelUnlinkAll->setEnabled(p & (ChanACL::Write | ChanACL::LinkChannel));

qaChannelCopyURL->setEnabled(c);
qaChannelCopyURL->setEnabled(target.channel);
qaChannelSendMessage->setEnabled(p & (ChanACL::Write | ChanACL::TextMessage));
qaChannelFilter->setEnabled(true);
qteChat->setEnabled(p & (ChanACL::Write | ChanACL::TextMessage));

bool chatBarEnabled = false;
if (Global::get().uiSession) {
if (Global::get().s.bChatBarUseSelection && (target.channel || target.user)) {
chatBarEnabled = p & (ChanACL::Write | ChanACL::TextMessage);
} else if (homec) {
chatBarEnabled = homep & (ChanACL::Write | ChanACL::TextMessage);
}
}
qteChat->setEnabled(chatBarEnabled);
}

void MainWindow::userStateChanged() {
Expand Down

0 comments on commit 1b26a55

Please sign in to comment.