mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 20:50:06 +00:00
Handle empty message lists for text event keys
Partial fix for #44, application should no longer crash, but erroneous behavior may remain
This commit is contained in:
parent
7f624e1263
commit
fceb5c33f7
1 changed files with 66 additions and 26 deletions
|
|
@ -368,6 +368,9 @@ AlertModelImpl::AlertModelImpl() :
|
|||
std::string AlertModelImpl::GetCounties(const types::TextEventKey& key)
|
||||
{
|
||||
auto messageList = manager::TextEventManager::Instance()->message_list(key);
|
||||
|
||||
if (messageList.size() > 0)
|
||||
{
|
||||
auto& lastMessage = messageList.back();
|
||||
size_t segmentCount = lastMessage->segment_count();
|
||||
auto lastSegment = lastMessage->segment(segmentCount - 1);
|
||||
|
|
@ -383,24 +386,51 @@ std::string AlertModelImpl::GetCounties(const types::TextEventKey& key)
|
|||
|
||||
return scwx::util::ToString(counties);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger_->warn("GetCounties(): No message associated with key: {}",
|
||||
key.ToString());
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
std::string AlertModelImpl::GetState(const types::TextEventKey& key)
|
||||
{
|
||||
auto messageList = manager::TextEventManager::Instance()->message_list(key);
|
||||
|
||||
if (messageList.size() > 0)
|
||||
{
|
||||
auto& lastMessage = messageList.back();
|
||||
size_t segmentCount = lastMessage->segment_count();
|
||||
auto lastSegment = lastMessage->segment(segmentCount - 1);
|
||||
return scwx::util::ToString(lastSegment->header_->ugc_.states());
|
||||
}
|
||||
else
|
||||
{
|
||||
logger_->warn("GetState(): No message associated with key: {}",
|
||||
key.ToString());
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
std::chrono::system_clock::time_point
|
||||
AlertModelImpl::GetStartTime(const types::TextEventKey& key)
|
||||
{
|
||||
auto messageList = manager::TextEventManager::Instance()->message_list(key);
|
||||
|
||||
if (messageList.size() > 0)
|
||||
{
|
||||
auto& firstMessage = messageList.front();
|
||||
auto firstSegment = firstMessage->segment(0);
|
||||
return firstSegment->header_->vtecString_[0].pVtec_.event_begin();
|
||||
}
|
||||
else
|
||||
{
|
||||
logger_->warn("GetStartTime(): No message associated with key: {}",
|
||||
key.ToString());
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
std::string AlertModelImpl::GetStartTimeString(const types::TextEventKey& key)
|
||||
{
|
||||
|
|
@ -411,11 +441,21 @@ std::chrono::system_clock::time_point
|
|||
AlertModelImpl::GetEndTime(const types::TextEventKey& key)
|
||||
{
|
||||
auto messageList = manager::TextEventManager::Instance()->message_list(key);
|
||||
|
||||
if (messageList.size() > 0)
|
||||
{
|
||||
auto& lastMessage = messageList.back();
|
||||
size_t segmentCount = lastMessage->segment_count();
|
||||
auto lastSegment = lastMessage->segment(segmentCount - 1);
|
||||
return lastSegment->header_->vtecString_[0].pVtec_.event_end();
|
||||
}
|
||||
else
|
||||
{
|
||||
logger_->warn("GetEndTime(): No message associated with key: {}",
|
||||
key.ToString());
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
std::string AlertModelImpl::GetEndTimeString(const types::TextEventKey& key)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue