Mercurial > prosody-modules
comparison mod_spam_reporting/mod_spam_reporting.lua @ 4658:ff68cc37b400
mod_spam_reporting: Make 'reason' text an optional value
Enables downstream modules that watch these events to distinguish between
no reason given and reason being a literal "no reason given".
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 25 Aug 2021 16:32:11 +0200 |
| parents | 4eb684ab440c |
| children | cc8b221f137c |
comparison
equal
deleted
inserted
replaced
| 4657:78ef5d9e2361 | 4658:ff68cc37b400 |
|---|---|
| 18 local jid = jid_prep(item.attr.jid); | 18 local jid = jid_prep(item.attr.jid); |
| 19 if report and jid then | 19 if report and jid then |
| 20 local type = report:get_child("spam") and "spam" or | 20 local type = report:get_child("spam") and "spam" or |
| 21 report:get_child("abuse") and "abuse" or | 21 report:get_child("abuse") and "abuse" or |
| 22 "unknown"; | 22 "unknown"; |
| 23 local reason = report:get_child_text("text") or "no reason given"; | 23 local reason = report:get_child_text("text"); |
| 24 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); |
| 25 module:fire_event(module.name.."/"..type.."-report", { | 25 module:fire_event(module.name.."/"..type.."-report", { |
| 26 origin = event.origin, stanza = event.stanza, jid = jid, | 26 origin = event.origin, stanza = event.stanza, jid = jid, |
| 27 item = item, report = report, reason = reason, }); | 27 item = item, report = report, reason = reason, }); |
| 28 else | 28 else |
| 33 type = "abuse"; | 33 type = "abuse"; |
| 34 end | 34 end |
| 35 if report.attr.reason == "urn:xmpp:reporting:spam" then | 35 if report.attr.reason == "urn:xmpp:reporting:spam" then |
| 36 type = "spam"; | 36 type = "spam"; |
| 37 end | 37 end |
| 38 local reason = report:get_child_text("text") or "no reason given"; | 38 local reason = report:get_child_text("text"); |
| 39 module:log("warn", "Received report of %s from JID '%s', %s", type, jid, reason); | 39 module:log("warn", "Received report of %s from JID '%s', %s", type, jid, reason); |
| 40 module:fire_event(module.name.."/"..type.."-report", { | 40 module:fire_event(module.name.."/"..type.."-report", { |
| 41 origin = event.origin, stanza = event.stanza, jid = jid, | 41 origin = event.origin, stanza = event.stanza, jid = jid, |
| 42 item = item, report = report, reason = reason, }); | 42 item = item, report = report, reason = reason, }); |
| 43 end | 43 end |
