diff --git a/services/tunnelbroker/src/Database/DatabaseManager.h b/services/tunnelbroker/src/Database/DatabaseManager.h --- a/services/tunnelbroker/src/Database/DatabaseManager.h +++ b/services/tunnelbroker/src/Database/DatabaseManager.h @@ -47,6 +47,9 @@ std::vector> findMessageItemsByReceiver(const std::string &toDeviceID); void removeMessageItem(const std::string &messageID); + void removeMessageItemsOlderThenDeviceCheckpoint( + const std::string &toDeviceID, + const size_t &checkpointTime); }; } // namespace database diff --git a/services/tunnelbroker/src/Database/DatabaseManager.cpp b/services/tunnelbroker/src/Database/DatabaseManager.cpp --- a/services/tunnelbroker/src/Database/DatabaseManager.cpp +++ b/services/tunnelbroker/src/Database/DatabaseManager.cpp @@ -209,6 +209,18 @@ this->innerRemoveItem(*item); } +void DatabaseManager::removeMessageItemsOlderThenDeviceCheckpoint( + const std::string &toDeviceID, + const size_t &checkpointTime) { + std::vector> messageItems = + this->findMessageItemsByReceiver(toDeviceID); + for (std::shared_ptr &messageItem : messageItems) { + if (messageItem->getCreatedAt() < checkpointTime) { + this->removeMessageItem(messageItem->getMessageID()); + } + } +} + } // namespace database } // namespace network } // namespace comm