Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: send notifications to sending controller on prenote timeout
- Loading branch information
Showing
21 changed files
with
315 additions
and
23 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
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 |
---|---|---|
@@ -1,23 +1,29 @@ | ||
#include "PrenoteMessage.h" | ||
#include "PrenoteMessageCollection.h" | ||
#include "PrenoteMessageEventHandlerCollection.h" | ||
#include "PrenoteMessageTimeout.h" | ||
#include "time/SystemClock.h" | ||
|
||
using UKControllerPlugin::Time::TimeNow; | ||
|
||
namespace UKControllerPlugin::Prenote { | ||
|
||
PrenoteMessageTimeout::PrenoteMessageTimeout(std::shared_ptr<PrenoteMessageCollection> messages) | ||
: messages(std::move(messages)) | ||
PrenoteMessageTimeout::PrenoteMessageTimeout( | ||
std::shared_ptr<PrenoteMessageCollection> messages, const PrenoteMessageEventHandlerCollection& eventHandlers) | ||
: messages(std::move(messages)), eventHandlers(eventHandlers) | ||
{ | ||
} | ||
|
||
void PrenoteMessageTimeout::TimedEventTrigger() | ||
{ | ||
this->messages->RemoveWhere([](const std::shared_ptr<PrenoteMessage>& message) -> bool { | ||
return message->IsAcknowledged() | ||
? message->GetAcknowledgedAt() < TimeNow() - std::chrono::minutes(ACKNOWLEDGED_PRENOTE_TIMEOUT) | ||
: message->GetExpiresAt() < TimeNow(); | ||
}); | ||
this->messages->RemoveWhere( | ||
[](const std::shared_ptr<PrenoteMessage>& message) -> bool { | ||
return message->IsAcknowledged() ? message->GetAcknowledgedAt() < | ||
TimeNow() - std::chrono::minutes(ACKNOWLEDGED_PRENOTE_TIMEOUT) | ||
: message->GetExpiresAt() < TimeNow(); | ||
}, | ||
[this](const PrenoteMessage& message) { | ||
eventHandlers.MessageTimeout(message); | ||
}); | ||
} | ||
} // namespace UKControllerPlugin::Prenote |
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,42 @@ | ||
#include "PrenoteMessage.h" | ||
#include "PrenoteUserRelevanceChecker.h" | ||
#include "SendPrenoteTimeoutChatAreaMessage.h" | ||
#include "controller/ControllerPosition.h" | ||
#include "euroscope/EuroscopePluginLoopbackInterface.h" | ||
#include "euroscope/GeneralSettingsEntries.h" | ||
#include "euroscope/UserSetting.h" | ||
|
||
namespace UKControllerPlugin::Prenote { | ||
|
||
SendPrenoteTimeoutChatAreaMessage::SendPrenoteTimeoutChatAreaMessage( | ||
std::shared_ptr<PrenoteUserRelevanceChecker> prenoteRelevance, | ||
Euroscope::EuroscopePluginLoopbackInterface& plugin, | ||
Euroscope::UserSetting& userSettings) | ||
: prenoteRelevance(prenoteRelevance), plugin(plugin), userSettings(userSettings) | ||
{ | ||
assert(prenoteRelevance && "Prenote relevance is nullptr"); | ||
} | ||
|
||
void SendPrenoteTimeoutChatAreaMessage::MessageTimeout(const PrenoteMessage& message) | ||
{ | ||
if (message.IsAcknowledged() || !UserWantsChatAreaMessages() || !prenoteRelevance->IsRelevant(message)) { | ||
return; | ||
} | ||
|
||
plugin.ChatAreaMessage( | ||
"UKCP_COORDINATION", | ||
"UKCP", | ||
"Prenote message to " + message.GetTargetController()->GetCallsign() + " for " + message.GetCallsign() + | ||
" has timed out without acknowledgement.", | ||
true, | ||
true, | ||
true, | ||
true, | ||
true); | ||
} | ||
|
||
auto SendPrenoteTimeoutChatAreaMessage::UserWantsChatAreaMessages() const -> bool | ||
{ | ||
return userSettings.GetBooleanEntry(Euroscope::GeneralSettingsEntries::prenoteChatAreaMessagesSettingsKey); | ||
} | ||
} // namespace UKControllerPlugin::Prenote |
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,32 @@ | ||
#pragma once | ||
#include "PrenoteMessageEventHandlerInterface.h" | ||
|
||
namespace UKControllerPlugin::Euroscope { | ||
class EuroscopePluginLoopbackInterface; | ||
class UserSetting; | ||
} // namespace UKControllerPlugin::Euroscope | ||
|
||
namespace UKControllerPlugin::Prenote { | ||
class PrenoteUserRelevanceChecker; | ||
|
||
class SendPrenoteTimeoutChatAreaMessage : public PrenoteMessageEventHandlerInterface | ||
{ | ||
public: | ||
SendPrenoteTimeoutChatAreaMessage( | ||
std::shared_ptr<PrenoteUserRelevanceChecker> prenoteRelevance, | ||
Euroscope::EuroscopePluginLoopbackInterface& plugin, | ||
Euroscope::UserSetting& userSettings); | ||
void MessageTimeout(const PrenoteMessage& message) override; | ||
|
||
private: | ||
[[nodiscard]] auto UserWantsChatAreaMessages() const -> bool; | ||
// Checks relevance of prenotes | ||
const std::shared_ptr<PrenoteUserRelevanceChecker> prenoteRelevance; | ||
|
||
// For sending messages | ||
Euroscope::EuroscopePluginLoopbackInterface& plugin; | ||
|
||
// User settings | ||
Euroscope::UserSetting& userSettings; | ||
}; | ||
} // namespace UKControllerPlugin::Prenote |
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
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
Oops, something went wrong.