0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 16:04:15 +01:00

modules/m_presence: Ignore presence spam.

This commit is contained in:
Jason Volk 2018-04-27 15:27:30 -07:00
parent 25d6c4d521
commit 019628c8a3

View file

@ -102,11 +102,38 @@ try
return; return;
} }
const auto &presence bool useful{true};
m::presence::get(user_id, [&event, &object, &useful]
(const m::event &existing_event, const json::object &existing_object)
{ {
at<"presence"_>(object) assert(json::get<"user_id"_>(object) == unquote(existing_object.get("user_id")));
const auto &prev_active_ago
{
existing_object.get<time_t>("last_active_ago")
}; };
const time_t &now_active_ago
{
json::get<"last_active_ago"_>(object)
};
const time_t &prev_active_absolute
{
json::get<"origin_server_ts"_>(existing_event) - prev_active_ago
};
const time_t &now_active_absolute
{
json::get<"origin_server_ts"_>(event) - now_active_ago
};
useful = now_active_absolute > prev_active_absolute;
});
if(!useful)
return;
const auto evid const auto evid
{ {
m::presence::set(object) m::presence::set(object)
@ -118,7 +145,7 @@ try
at<"origin"_>(event), at<"origin"_>(event),
string_view{user_id}, string_view{user_id},
json::get<"currently_active"_>(object)? "active"_sv : "inactive"_sv, json::get<"currently_active"_>(object)? "active"_sv : "inactive"_sv,
presence, json::get<"presence"_>(object),
json::get<"last_active_ago"_>(object) / 1000L json::get<"last_active_ago"_>(object) / 1000L
}; };
} }