mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-15 01:05:35 +08:00
Ref T703, utility functions for "relayed messages" (i.e. copilot/pilot)
This commit is contained in:
@@ -49,6 +49,12 @@ namespace BlackMisc
|
|||||||
return m_message % u' ' % m_frequency.toQString(i18n);
|
return m_message % u' ' % m_frequency.toQString(i18n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString &CTextMessage::swiftRelayMessage()
|
||||||
|
{
|
||||||
|
static const QString s("swift relayed: ");
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
bool CTextMessage::isPrivateMessage() const
|
bool CTextMessage::isPrivateMessage() const
|
||||||
{
|
{
|
||||||
return !m_senderCallsign.isEmpty() && !m_recipientCallsign.isEmpty();
|
return !m_senderCallsign.isEmpty() && !m_recipientCallsign.isEmpty();
|
||||||
@@ -68,6 +74,34 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CTextMessage::isRelayedMessage() const
|
||||||
|
{
|
||||||
|
return m_relayedMessage || this->getMessage().startsWith(CTextMessage::swiftRelayMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTextMessage::makeRelayedMessage(const CCallsign &partnerCallsign)
|
||||||
|
{
|
||||||
|
if (this->getMessage().startsWith(CTextMessage::swiftRelayMessage())) { return; }
|
||||||
|
this->markAsRelayedMessage();
|
||||||
|
this->setRecipientCallsign(partnerCallsign);
|
||||||
|
m_recipientCallsign.setTypeHint(CCallsign::Aircraft);
|
||||||
|
const QString sender = this->getSenderCallsign().asString();
|
||||||
|
const QString newMessage = CTextMessage::swiftRelayMessage() % sender % u";" % this->getMessage();
|
||||||
|
m_message = newMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CTextMessage::relayedMessageToPrivateMessage()
|
||||||
|
{
|
||||||
|
if (!this->isRelayedMessage()) { return false; }
|
||||||
|
const int index = m_message.indexOf(';');
|
||||||
|
if (index < CTextMessage::swiftRelayMessage().length()) { return false; }
|
||||||
|
if (m_message.length() <= index + 1) { return false; } // no next line
|
||||||
|
const QString originalSender = m_message.left(index).remove(CTextMessage::swiftRelayMessage()).trimmed();
|
||||||
|
this->setSenderCallsign(CCallsign(originalSender, CCallsign::Aircraft));
|
||||||
|
m_message = m_message.mid(index + 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CTextMessage::canBeAppended(const CTextMessage &textMessage) const
|
bool CTextMessage::canBeAppended(const CTextMessage &textMessage) const
|
||||||
{
|
{
|
||||||
if (textMessage.isEmpty()) { return false; }
|
if (textMessage.isEmpty()) { return false; }
|
||||||
|
|||||||
@@ -147,6 +147,18 @@ namespace BlackMisc
|
|||||||
//! \remark also sets current timestamp if there is no valid timestamp
|
//! \remark also sets current timestamp if there is no valid timestamp
|
||||||
void markAsSent();
|
void markAsSent();
|
||||||
|
|
||||||
|
//! Is relayed message
|
||||||
|
bool isRelayedMessage() const;
|
||||||
|
|
||||||
|
//! Mark as relayed message
|
||||||
|
void markAsRelayedMessage() { m_relayedMessage = true; }
|
||||||
|
|
||||||
|
//! Mark as relayed and keep original sender
|
||||||
|
void makeRelayedMessage(const Aviation::CCallsign &partnerCallsign);
|
||||||
|
|
||||||
|
//! Turn relayed message into private message
|
||||||
|
bool relayedMessageToPrivateMessage();
|
||||||
|
|
||||||
//! Can another message be appended
|
//! Can another message be appended
|
||||||
bool canBeAppended(const CTextMessage &textMessage) const;
|
bool canBeAppended(const CTextMessage &textMessage) const;
|
||||||
|
|
||||||
@@ -171,12 +183,16 @@ namespace BlackMisc
|
|||||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||||
QString convertToQString(bool i18n = false) const;
|
QString convertToQString(bool i18n = false) const;
|
||||||
|
|
||||||
|
//! swift relay message marker
|
||||||
|
static const QString &swiftRelayMessage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_message;
|
QString m_message;
|
||||||
Aviation::CCallsign m_senderCallsign;
|
Aviation::CCallsign m_senderCallsign;
|
||||||
Aviation::CCallsign m_recipientCallsign;
|
Aviation::CCallsign m_recipientCallsign;
|
||||||
PhysicalQuantities::CFrequency m_frequency { 0, nullptr };
|
PhysicalQuantities::CFrequency m_frequency { 0, nullptr };
|
||||||
bool m_wasSent = false;
|
bool m_wasSent = false; //!< transient
|
||||||
|
bool m_relayedMessage = false; //!< transient
|
||||||
|
|
||||||
BLACK_METACLASS(
|
BLACK_METACLASS(
|
||||||
CTextMessage,
|
CTextMessage,
|
||||||
|
|||||||
@@ -103,6 +103,48 @@ namespace BlackMisc
|
|||||||
std::for_each(this->begin(), this->end(), [](CTextMessage & tm) { tm.toggleSenderRecipient(); });
|
std::for_each(this->begin(), this->end(), [](CTextMessage & tm) { tm.toggleSenderRecipient(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CTextMessageList::relayedToPrivateMessages()
|
||||||
|
{
|
||||||
|
if (this->isEmpty()) { return 0; }
|
||||||
|
int c = 0;
|
||||||
|
for (CTextMessage &m : *this)
|
||||||
|
{
|
||||||
|
if (m.relayedMessageToPrivateMessage()) { c++; }
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CTextMessageList::removePrivateMessagesFromCallsign(const CCallsign &callsign)
|
||||||
|
{
|
||||||
|
if (this->isEmpty()) { return 0; }
|
||||||
|
CTextMessageList r = this->withRemovedPrivateMessagesFromCallsign(callsign);
|
||||||
|
const int c = this->size() - r.size();
|
||||||
|
if (c < 1) { return 0; }
|
||||||
|
*this = r;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
CTextMessageList CTextMessageList::withRelayedToPrivateMessages() const
|
||||||
|
{
|
||||||
|
if (this->isEmpty()) { return {}; }
|
||||||
|
CTextMessageList copy = *this;
|
||||||
|
copy.relayedToPrivateMessages();
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
CTextMessageList CTextMessageList::withRemovedPrivateMessagesFromCallsign(const CCallsign &callsign) const
|
||||||
|
{
|
||||||
|
if (this->isEmpty()) { return {}; }
|
||||||
|
if (callsign.isEmpty()) { return *this; }
|
||||||
|
CTextMessageList r;
|
||||||
|
for (const CTextMessage &m : *this)
|
||||||
|
{
|
||||||
|
if (m.isPrivateMessage() && m.getSenderCallsign() == callsign) { continue; }
|
||||||
|
r.push_back(m);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
void CTextMessageList::markAsSent()
|
void CTextMessageList::markAsSent()
|
||||||
{
|
{
|
||||||
std::for_each(this->begin(), this->end(), [](CTextMessage & tm) { tm.markAsSent(); });
|
std::for_each(this->begin(), this->end(), [](CTextMessage & tm) { tm.markAsSent(); });
|
||||||
|
|||||||
@@ -82,9 +82,21 @@ namespace BlackMisc
|
|||||||
//! Find by frequency
|
//! Find by frequency
|
||||||
CTextMessageList findByFrequency(const PhysicalQuantities::CFrequency &frequency) const;
|
CTextMessageList findByFrequency(const PhysicalQuantities::CFrequency &frequency) const;
|
||||||
|
|
||||||
//! Toggle all sender receivers
|
//! Toggle all sender <-> recipients
|
||||||
void toggleSenderRecipients();
|
void toggleSenderRecipients();
|
||||||
|
|
||||||
|
//! Turn relayed into normal private messages
|
||||||
|
int relayedToPrivateMessages();
|
||||||
|
|
||||||
|
//! Remove private messages from callsign
|
||||||
|
int removePrivateMessagesFromCallsign(const Aviation::CCallsign &callsign);
|
||||||
|
|
||||||
|
//! List with relayed messages (if any) as private messages
|
||||||
|
CTextMessageList withRelayedToPrivateMessages() const;
|
||||||
|
|
||||||
|
//! With removed private messages from callsign
|
||||||
|
CTextMessageList withRemovedPrivateMessagesFromCallsign(const Aviation::CCallsign &callsign) const;
|
||||||
|
|
||||||
//! Mark all messages as sent
|
//! Mark all messages as sent
|
||||||
void markAsSent();
|
void markAsSent();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user