Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: send chat area message for release requested
- Loading branch information
Showing
16 changed files
with
346 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
namespace UKControllerPlugin::Releases { | ||
|
||
class DepartureReleaseRequest; | ||
|
||
/** | ||
* Checks if a release request is relevant to the current user. | ||
*/ | ||
class DepartureReleaseRelevanceChecker | ||
{ | ||
public: | ||
virtual ~DepartureReleaseRelevanceChecker() = default; | ||
[[nodiscard]] virtual bool IsRelevant(const DepartureReleaseRequest& releaseRequest) const = 0; | ||
}; | ||
} // namespace UKControllerPlugin::Releases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
namespace UKControllerPlugin::Releases { | ||
|
||
class DepartureReleaseRequest; | ||
|
||
using DepartureReleaseRequestedEvent = struct DepartureReleaseRequestedEvent | ||
{ | ||
std::shared_ptr<DepartureReleaseRequest> releaseRequest; | ||
}; | ||
} // namespace UKControllerPlugin::Releases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "ReleaseIsTargetedAtUser.h" | ||
#include "controller/ActiveCallsignCollection.h" | ||
#include "controller/ActiveCallsign.h" | ||
#include "controller/ControllerPosition.h" | ||
#include "releases/DepartureReleaseRequest.h" | ||
|
||
namespace UKControllerPlugin::Releases { | ||
|
||
ReleaseIsTargetedAtUser::ReleaseIsTargetedAtUser( | ||
std::shared_ptr<const Controller::ActiveCallsignCollection> activeCallsigns) | ||
: activeCallsigns(std::move(activeCallsigns)) | ||
{ | ||
assert(this->activeCallsigns && "activeCallsigns must not be null"); | ||
} | ||
|
||
/** | ||
* Check that the user has a callsign, and that the callsign has the same normalised controller position | ||
* as the target of the release request. | ||
*/ | ||
bool ReleaseIsTargetedAtUser::IsRelevant(const DepartureReleaseRequest& releaseRequest) const | ||
{ | ||
return activeCallsigns->UserHasCallsign() && | ||
activeCallsigns->GetUserCallsign().GetNormalisedPosition().GetId() == releaseRequest.TargetController(); | ||
} | ||
} // namespace UKControllerPlugin::Releases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
#include "releases/DepartureReleaseRelevanceChecker.h" | ||
|
||
namespace UKControllerPlugin::Controller { | ||
class ActiveCallsignCollection; | ||
} // namespace UKControllerPlugin::Controller | ||
|
||
namespace UKControllerPlugin::Releases { | ||
|
||
class ReleaseIsTargetedAtUser : public DepartureReleaseRelevanceChecker | ||
{ | ||
public: | ||
explicit ReleaseIsTargetedAtUser(std::shared_ptr<const Controller::ActiveCallsignCollection> activeCallsigns); | ||
[[nodiscard]] bool IsRelevant(const DepartureReleaseRequest& releaseRequest) const override; | ||
|
||
private: | ||
// The active callsigns | ||
const std::shared_ptr<const Controller::ActiveCallsignCollection> activeCallsigns; | ||
}; | ||
|
||
} // namespace UKControllerPlugin::Releases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/plugin/releases/SendReleaseRequestedChatAreaMessage.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "DepartureReleaseRelevanceChecker.h" | ||
#include "DepartureReleaseRequest.h" | ||
#include "DepartureReleaseRequestedEvent.h" | ||
#include "SendReleaseRequestedChatAreaMessage.h" | ||
#include "euroscope/EuroscopePluginLoopbackInterface.h" | ||
#include "euroscope/GeneralSettingsEntries.h" | ||
#include "euroscope/UserSetting.h" | ||
|
||
namespace UKControllerPlugin::Releases { | ||
|
||
SendReleaseRequestedChatAreaMessage::SendReleaseRequestedChatAreaMessage( | ||
std::shared_ptr<const DepartureReleaseRelevanceChecker> relevanceChecker, | ||
Euroscope::EuroscopePluginLoopbackInterface& plugin, | ||
Euroscope::UserSetting& userSettings) | ||
: relevanceChecker(std::move(relevanceChecker)), plugin(plugin), userSettings(userSettings) | ||
{ | ||
assert(this->relevanceChecker && "relevanceChecker must not be null"); | ||
} | ||
|
||
void SendReleaseRequestedChatAreaMessage::OnEvent(const DepartureReleaseRequestedEvent& event) | ||
{ | ||
if (!this->relevanceChecker->IsRelevant(*event.releaseRequest)) { | ||
LogDebug("Not sending release requested chat area message because it is not relevant"); | ||
return; | ||
} | ||
|
||
if (!userSettings.GetBooleanEntry(Euroscope::GeneralSettingsEntries::releaseChatAreaMessagesSettingsKey)) { | ||
LogDebug("Not sending release requested chat area message because user does not want chat area messages"); | ||
return; | ||
} | ||
|
||
plugin.ChatAreaMessage( | ||
"UKCP_COORDINATION", | ||
"UKCP", | ||
"Departure release requested for " + event.releaseRequest->Callsign() + ".", | ||
true, | ||
true, | ||
true, | ||
true, | ||
true); | ||
} | ||
} // namespace UKControllerPlugin::Releases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
#include "eventhandler/EventHandler.h" | ||
|
||
namespace UKControllerPlugin::Euroscope { | ||
class EuroscopePluginLoopbackInterface; | ||
class UserSetting; | ||
} // namespace UKControllerPlugin::Euroscope | ||
|
||
namespace UKControllerPlugin::Releases { | ||
|
||
class DepartureReleaseRelevanceChecker; | ||
struct DepartureReleaseRequestedEvent; | ||
|
||
class SendReleaseRequestedChatAreaMessage | ||
: public UKControllerPluginUtils::EventHandler::EventHandler<DepartureReleaseRequestedEvent> | ||
{ | ||
public: | ||
SendReleaseRequestedChatAreaMessage( | ||
std::shared_ptr<const DepartureReleaseRelevanceChecker> relevanceChecker, | ||
Euroscope::EuroscopePluginLoopbackInterface& plugin, | ||
Euroscope::UserSetting& userSettings); | ||
void OnEvent(const DepartureReleaseRequestedEvent& event) override; | ||
|
||
private: | ||
// Checks prenote relevance | ||
const std::shared_ptr<const DepartureReleaseRelevanceChecker> relevanceChecker; | ||
|
||
// For sending messages | ||
Euroscope::EuroscopePluginLoopbackInterface& plugin; | ||
|
||
// For checking user settings | ||
Euroscope::UserSetting& userSettings; | ||
}; | ||
|
||
} // namespace UKControllerPlugin::Releases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "controller/ActiveCallsign.h" | ||
#include "controller/ActiveCallsignCollection.h" | ||
#include "controller/ControllerPosition.h" | ||
#include "releases/DepartureReleaseRequest.h" | ||
#include "releases/ReleaseIsTargetedAtUser.h" | ||
|
||
namespace UKControllerPluginTest::Releases { | ||
class ReleaseIsTargetedAtUserTest : public ::testing::Test | ||
{ | ||
protected: | ||
ReleaseIsTargetedAtUserTest() | ||
: position1(std::make_shared<UKControllerPlugin::Controller::ControllerPosition>( | ||
1, "EGGD_APP", 125.650, std::vector<std::string>{}, true, true)), | ||
position2(std::make_shared<UKControllerPlugin::Controller::ControllerPosition>( | ||
2, "EGGD_TWR", 133.850, std::vector<std::string>{}, true, true)), | ||
userCallsign("EGGD_APP", "EGGD_APP", *position1, true), | ||
nonUserCallsign("EGGD_TWR", "EGGD_TWR", *position2, false), | ||
callsignCollection(std::make_shared<UKControllerPlugin::Controller::ActiveCallsignCollection>()), | ||
releaseIsTargetedAtUser(callsignCollection) | ||
{ | ||
callsignCollection->AddCallsign(nonUserCallsign); | ||
} | ||
|
||
std::shared_ptr<UKControllerPlugin::Controller::ControllerPosition> position1; | ||
std::shared_ptr<UKControllerPlugin::Controller::ControllerPosition> position2; | ||
UKControllerPlugin::Controller::ActiveCallsign userCallsign; | ||
UKControllerPlugin::Controller::ActiveCallsign nonUserCallsign; | ||
std::shared_ptr<UKControllerPlugin::Controller::ActiveCallsignCollection> callsignCollection; | ||
UKControllerPlugin::Releases::ReleaseIsTargetedAtUser releaseIsTargetedAtUser; | ||
}; | ||
|
||
TEST_F(ReleaseIsTargetedAtUserTest, IsRelevantReturnsTrueWhenCallsignIsUser) | ||
{ | ||
callsignCollection->AddUserCallsign(userCallsign); | ||
UKControllerPlugin::Releases::DepartureReleaseRequest releaseRequest( | ||
1, "BAW555", 99, 1, std::chrono::system_clock::now()); | ||
EXPECT_TRUE(releaseIsTargetedAtUser.IsRelevant(releaseRequest)); | ||
} | ||
|
||
TEST_F(ReleaseIsTargetedAtUserTest, IsRelevantReturnsFalseWhenCallsignIsNotUser) | ||
{ | ||
callsignCollection->AddUserCallsign(userCallsign); | ||
UKControllerPlugin::Releases::DepartureReleaseRequest releaseRequest( | ||
1, "BAW555", 99, 2, std::chrono::system_clock::now()); | ||
EXPECT_FALSE(releaseIsTargetedAtUser.IsRelevant(releaseRequest)); | ||
} | ||
|
||
TEST_F(ReleaseIsTargetedAtUserTest, IsRelevantReturnsFalseWhenUserCallsignIsNotInCollection) | ||
{ | ||
UKControllerPlugin::Releases::DepartureReleaseRequest releaseRequest( | ||
1, "BAW555", 99, 1, std::chrono::system_clock::now()); | ||
EXPECT_FALSE(releaseIsTargetedAtUser.IsRelevant(releaseRequest)); | ||
} | ||
} // namespace UKControllerPluginTest::Releases |
Oops, something went wrong.