diff --git a/src/message_command_dispatcher.cpp b/src/message_command_dispatcher.cpp index 1d17c5d..ec64a7a 100644 --- a/src/message_command_dispatcher.cpp +++ b/src/message_command_dispatcher.cpp @@ -3,7 +3,6 @@ #include #include #include -#include // TODO: move SyncedBy to global #include #include @@ -18,7 +17,7 @@ MessageCommandDispatcher::MessageCommandDispatcher( RegistryMessageModel& rmm, ConfigModelI& conf ) : - _cr(cr), _rmm(rmm), _conf(conf) + _cr(cr), _rmm(rmm), _conf(conf), _program_started_at(Message::getTimeMS()) { // overwrite default admin and moderator to false _conf.set("MessageCommandDispatcher", "admin", false); @@ -233,6 +232,14 @@ bool MessageCommandDispatcher::onEvent(const Message::Events::MessageConstruct& return false; } + if (e.e.any_of()) { + // test if message was written before program was started (-1s) + if (e.e.get().ts + 1'000 < _program_started_at) { + // message too old + return false; + } + } + std::string_view message_text = e.e.get().text; if (message_text.empty()) { diff --git a/src/message_command_dispatcher.hpp b/src/message_command_dispatcher.hpp index 1437c33..b8daf26 100644 --- a/src/message_command_dispatcher.hpp +++ b/src/message_command_dispatcher.hpp @@ -51,6 +51,8 @@ class MessageCommandDispatcher : public RegistryMessageModelEventI { }; std::deque _message_queue; + uint64_t _program_started_at {0}; + public: MessageCommandDispatcher(Contact3Registry& cr, RegistryMessageModel& rmm, ConfigModelI& conf); ~MessageCommandDispatcher(void);