dont execute commands that where written before it was started
This commit is contained in:
parent
0ea096c695
commit
e8f69c0948
@ -3,7 +3,6 @@
|
|||||||
#include <solanaceae/util/config_model.hpp>
|
#include <solanaceae/util/config_model.hpp>
|
||||||
#include <solanaceae/message3/components.hpp>
|
#include <solanaceae/message3/components.hpp>
|
||||||
#include <solanaceae/contact/components.hpp>
|
#include <solanaceae/contact/components.hpp>
|
||||||
#include <solanaceae/tox_messages/components.hpp> // TODO: move SyncedBy to global
|
|
||||||
#include <solanaceae/toxcore/utils.hpp>
|
#include <solanaceae/toxcore/utils.hpp>
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
@ -18,7 +17,7 @@ MessageCommandDispatcher::MessageCommandDispatcher(
|
|||||||
RegistryMessageModel& rmm,
|
RegistryMessageModel& rmm,
|
||||||
ConfigModelI& conf
|
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
|
// overwrite default admin and moderator to false
|
||||||
_conf.set("MessageCommandDispatcher", "admin", false);
|
_conf.set("MessageCommandDispatcher", "admin", false);
|
||||||
@ -233,6 +232,14 @@ bool MessageCommandDispatcher::onEvent(const Message::Events::MessageConstruct&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.e.any_of<Message::Components::Timestamp>()) {
|
||||||
|
// test if message was written before program was started (-1s)
|
||||||
|
if (e.e.get<Message::Components::Timestamp>().ts + 1'000 < _program_started_at) {
|
||||||
|
// message too old
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string_view message_text = e.e.get<Message::Components::MessageText>().text;
|
std::string_view message_text = e.e.get<Message::Components::MessageText>().text;
|
||||||
|
|
||||||
if (message_text.empty()) {
|
if (message_text.empty()) {
|
||||||
|
@ -51,6 +51,8 @@ class MessageCommandDispatcher : public RegistryMessageModelEventI {
|
|||||||
};
|
};
|
||||||
std::deque<QueuedMessage> _message_queue;
|
std::deque<QueuedMessage> _message_queue;
|
||||||
|
|
||||||
|
uint64_t _program_started_at {0};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MessageCommandDispatcher(Contact3Registry& cr, RegistryMessageModel& rmm, ConfigModelI& conf);
|
MessageCommandDispatcher(Contact3Registry& cr, RegistryMessageModel& rmm, ConfigModelI& conf);
|
||||||
~MessageCommandDispatcher(void);
|
~MessageCommandDispatcher(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user