Ref T190, text messages can be appended

(same sender sends one message in multiple parts)
This commit is contained in:
Klaus Basan
2017-11-11 23:26:34 +01:00
parent 0a1f5c49ae
commit 48adb52082
4 changed files with 42 additions and 0 deletions

View File

@@ -65,6 +65,31 @@ namespace BlackMisc
} }
} }
bool CTextMessage::canBeAppended(const CTextMessage &textMessage) const
{
if (textMessage.isEmpty()) { return false; }
if (this->getSenderCallsign() != textMessage.getSenderCallsign()) { return false; }
if (this->isRadioMessage() && textMessage.isRadioMessage())
{
if (this->getFrequency() != textMessage.getFrequency()) { return false; }
return true;
}
else if (this->isPrivateMessage() && textMessage.isPrivateMessage())
{
if (this->getRecipientCallsign() != textMessage.getRecipientCallsign()) { return false; }
return true;
}
return false;
}
bool CTextMessage::appendIfPossible(const CTextMessage &textMessage)
{
if (textMessage.isEmpty()) { return false; }
if (!this->canBeAppended(textMessage)) { return false; }
m_message += " " + textMessage.getMessage();
return true;
}
QString CTextMessage::getRecipientCallsignOrFrequency() const QString CTextMessage::getRecipientCallsignOrFrequency() const
{ {
if (!m_recipientCallsign.isEmpty()) { return m_recipientCallsign.asString(); } if (!m_recipientCallsign.isEmpty()) { return m_recipientCallsign.asString(); }

View File

@@ -153,6 +153,12 @@ 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();
//! Can another message be appended
bool canBeAppended(const CTextMessage &textMessage) const;
//! Append if possible
bool appendIfPossible(const CTextMessage &textMessage);
//! Get SELCAL code (if applicable, e.g. ABCD), otherwise "" //! Get SELCAL code (if applicable, e.g. ABCD), otherwise ""
QString getSelcalCode() const; QString getSelcalCode() const;

View File

@@ -109,5 +109,14 @@ namespace BlackMisc
std::for_each(this->begin(), this->end(), [](CTextMessage & tm) { tm.markAsSent(); }); std::for_each(this->begin(), this->end(), [](CTextMessage & tm) { tm.markAsSent(); });
} }
void CTextMessageList::addConsolidatedTextMessage(const CTextMessage &message)
{
if (message.isEmpty()) { return; }
for (CTextMessage &tm : *this)
{
if (tm.appendIfPossible(message)) { return; }
}
this->push_back(message);
}
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -88,6 +88,8 @@ namespace BlackMisc
//! Mark all messages as sent //! Mark all messages as sent
void markAsSent(); void markAsSent();
//! Add a text message, but append it to an existing message if possible
void addConsolidatedTextMessage(const CTextMessage &message);
}; };
} //namespace } //namespace
} // namespace } // namespace