comparison mod_spam_reporting/mod_spam_reporting.lua @ 4612:fe24bda72838

mod_spam_reporting: Add support for XEP-0377 0.3 Support 'urn:xmpp:reporting:1', see https://xmpp.org/extensions/xep-0377.html#revision-history-v0.3
author Martin Dosch <martin@mdosch.de>
date Thu, 01 Jul 2021 21:07:38 +0200
parents a59671b3dd43
children 4eb684ab440c
comparison
equal deleted inserted replaced
4611:7a9e1c81c63e 4612:fe24bda72838
8 module:depends("blocklist"); 8 module:depends("blocklist");
9 9
10 module:add_feature("urn:xmpp:reporting:0"); 10 module:add_feature("urn:xmpp:reporting:0");
11 module:add_feature("urn:xmpp:reporting:reason:spam:0"); 11 module:add_feature("urn:xmpp:reporting:reason:spam:0");
12 module:add_feature("urn:xmpp:reporting:reason:abuse:0"); 12 module:add_feature("urn:xmpp:reporting:reason:abuse:0");
13 module:add_feature("urn:xmpp:reporting:1");
13 14
14 module:hook("iq-set/self/urn:xmpp:blocking:block", function (event) 15 module:hook("iq-set/self/urn:xmpp:blocking:block", function (event)
15 for item in event.stanza.tags[1]:childtags("item") do 16 for item in event.stanza.tags[1]:childtags("item") do
16 local report = item:get_child("report", "urn:xmpp:reporting:0"); 17 local report = item:get_child("report", "urn:xmpp:reporting:0");
17 local jid = jid_prep(item.attr.jid); 18 local jid = jid_prep(item.attr.jid);
22 local reason = report:get_child_text("text") or "no reason given"; 23 local reason = report:get_child_text("text") or "no reason given";
23 module:log("warn", "Received report of %s from JID '%s', %s", type, jid, reason); 24 module:log("warn", "Received report of %s from JID '%s', %s", type, jid, reason);
24 module:fire_event(module.name.."/"..type.."-report", { 25 module:fire_event(module.name.."/"..type.."-report", {
25 origin = event.origin, stanza = event.stanza, jid = jid, 26 origin = event.origin, stanza = event.stanza, jid = jid,
26 item = item, report = report, reason = reason, }); 27 item = item, report = report, reason = reason, });
28 else
29 report = item:get_child("report", "urn:xmpp:reporting:1");
30 if report and jid then
31 local type
32 if report.attr.reason == "urn:xmpp:reporting:abuse" then
33 type = "abuse";
34 end
35 if report.attr.reason == "urn:xmpp:reporting:spam" then
36 type = "spam";
37 end
38 local reason = report:get_child_text("text") or "no reason given";
39 module:log("warn", "Received report of %s from JID '%s', %s", type, jid, reason);
40 module:fire_event(module.name.."/"..type.."-report", {
41 origin = event.origin, stanza = event.stanza, jid = jid,
42 item = item, report = report, reason = reason, });
43 end
27 end 44 end
28 end 45 end
29 end, 1); 46 end, 1);