add strict rate limit

This commit is contained in:
Jeffrey C. Ollie
2024-05-11 15:52:47 -05:00
parent b4404b691d
commit 085c964be7

View File

@ -3496,13 +3496,22 @@ fn showDesktopNotification(self: *Surface, title: [:0]const u8, body: [:0]const
var new_notification_digest: [hash_algorithm.digest_length]u8 = undefined;
if (last_notification_time) |last| {
if (now.since(last) < 1 * std.time.ns_per_s) {
log.warn("rate limiting desktop notifications", .{});
return;
}
}
{
var hash = hash_algorithm.init(.{});
hash.update(title);
hash.update(body);
hash.final(&new_notification_digest);
}
if (std.mem.eql(u8, &last_notification_digest, &new_notification_digest)) {
if (last_notification_time) |last| {
if (std.mem.eql(u8, &last_notification_digest, &new_notification_digest)) {
if (now.since(last) < 5 * std.time.ns_per_s) {
log.warn("suppressing identical notification", .{});
return;