Skip to content

Commit

Permalink
Add admin button for cancelling votes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmic-Sans committed Feb 18, 2020
1 parent a9442fc commit 2f43758
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
13 changes: 12 additions & 1 deletion AdminVirtualMachine.hpp
Expand Up @@ -90,6 +90,14 @@ struct AdminVirtualMachine
});
}

void CancelVote()
{
state_.dispatch([](auto& state)
{
state.StopVote();
});
}

void OnGuacamoleInstructions(
std::shared_ptr<std::vector<std::shared_ptr<SharedSocketMessage>>> instructions) {
state_.dispatch([instructions = std::move(instructions)](auto& state) mutable {
Expand Down Expand Up @@ -538,6 +546,9 @@ struct AdminVirtualMachine

void OnVoteEnd(bool vote_passed)
{
if (!active_ || !GetVotesEnabled()) {
return;
}
if (vote_passed) {
admin_vm_.Restart();
}
Expand All @@ -557,7 +568,7 @@ struct AdminVirtualMachine

void OnVoteIdle()
{
if (GetVotesEnabled()) {
if (active_ && GetVotesEnabled()) {
VmUserChannel::BroadcastMessage(GetVoteStatus());
}
}
Expand Down
17 changes: 17 additions & 0 deletions CollabVmServer.hpp
Expand Up @@ -1470,6 +1470,23 @@ namespace CollabVm::Server
}
break;
}
case CollabVmClientMessage::Message::CANCEL_VOTE:
{
if (is_admin_ && connected_vm_id_)
{
server_.virtual_machines_.dispatch(
[vm_id = connected_vm_id_](auto& virtual_machines)
{
if (const auto virtual_machine =
virtual_machines.GetAdminVirtualMachine(vm_id);
virtual_machine)
{
virtual_machine->CancelVote();
}
});
}
break;
}
case CollabVmClientMessage::Message::RECORDING_PREVIEW_REQUEST:
{
if (is_admin_)
Expand Down
2 changes: 2 additions & 0 deletions VoteController.hpp
Expand Up @@ -91,6 +91,8 @@ class VoteController {
{
if (ec || !static_cast<TBase&>(*this).GetVotesEnabled()) {
vote_state_ = VoteState::kIdle;
static_cast<TBase&>(*this).OnVoteIdle();
static_cast<TBase&>(*this).OnVoteEnd(false);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion submodules/collab-vm-common

0 comments on commit 2f43758

Please sign in to comment.