# HG changeset patch # User Kim Alvefur # Date 1629911080 -7200 # Node ID ce826ac8496ea64fc3ca48ef5a2b9c8a88e1f744 # Parent cc8b221f137cbecf7da203f3fd6cf8a10417c0c1 mod_spam_reporting: Refactor to deduplicate code Same event firing code regardless of protocol now. diff -r cc8b221f137c -r ce826ac8496e mod_spam_reporting/mod_spam_reporting.lua --- a/mod_spam_reporting/mod_spam_reporting.lua Wed Aug 25 18:56:45 2021 +0200 +++ b/mod_spam_reporting/mod_spam_reporting.lua Wed Aug 25 19:04:40 2021 +0200 @@ -14,28 +14,25 @@ module:hook("iq-set/self/urn:xmpp:blocking:block", function (event) for item in event.stanza.tags[1]:childtags("item") do - local report = item:get_child("report", "urn:xmpp:reporting:0"); + local report = item:get_child("report", "urn:xmpp:reporting:0") or item:get_child("report", "urn:xmpp:reporting:1"); local jid = jid_prep(item.attr.jid); if report and jid then - local report_type = report:get_child("spam") and "spam" or - report:get_child("abuse") and "abuse" or - "unknown"; - local reason = report:get_child_text("text"); - module:log("warn", "Received report of %s from JID '%s', %s", type, jid, reason); - module:fire_event(module.name.."/"..report_type.."-report", { - origin = event.origin, stanza = event.stanza, jid = jid, - item = item, report = report, reason = reason, }); - else - report = item:get_child("report", "urn:xmpp:reporting:1"); - if report and jid then - local report_type = "unknown"; + local report_type, reason; + if report.attr.xmlns == "urn:xmpp:reporting:0" then + report_type = report:get_child("spam") and "spam" or report:get_child("abuse") and "abuse" or "unknown"; + reason = report:get_child_text("text"); + elseif report.attr.xmlns == "urn:xmpp:reporting:1" then + report_type = "unknown"; if report.attr.reason == "urn:xmpp:reporting:abuse" then report_type = "abuse"; end if report.attr.reason == "urn:xmpp:reporting:spam" then report_type = "spam"; end - local reason = report:get_child_text("text"); + reason = report:get_child_text("text"); + end + + if report_type then module:log("warn", "Received report of %s from JID '%s', %s", type, jid, reason); module:fire_event(module.name.."/"..report_type.."-report", { origin = event.origin, stanza = event.stanza, jid = jid,