Mercurial > prosody-modules
comparison mod_muc_moderation_delay/delay.lib.lua @ 5962:a86720654fb9
mod_muc_moderation_delay: Fix lua 5.3/5.4 compatibility.
| author | John Livingston <git@john-livingston.fr> |
|---|---|
| date | Tue, 10 Sep 2024 18:03:03 +0200 |
| parents | 959382fac20c |
| children |
comparison
equal
deleted
inserted
replaced
| 5961:7308ec4aaad1 | 5962:a86720654fb9 |
|---|---|
| 86 else | 86 else |
| 87 stanza_id = stanza_id_child.attr.id; | 87 stanza_id = stanza_id_child.attr.id; |
| 88 end | 88 end |
| 89 local id = stanza.attr.id; | 89 local id = stanza.attr.id; |
| 90 if not id then | 90 if not id then |
| 91 -- message should alway have an id, but just in case... | 91 -- message should always have an id, but just in case... |
| 92 module:log("warn", "Message has no id, wont delay it."); | 92 module:log("warn", "Message has no id, wont delay it."); |
| 93 return; | 93 return; |
| 94 end | 94 end |
| 95 | 95 |
| 96 -- Message must be delayed, except for: | 96 -- Message must be delayed, except for: |
| 104 -- first of all, if the initiator occupant is not moderator, me must send to them. | 104 -- first of all, if the initiator occupant is not moderator, me must send to them. |
| 105 -- (delaying the echo message could have some quircks in some xmpp clients) | 105 -- (delaying the echo message could have some quircks in some xmpp clients) |
| 106 if stanza.attr.from then | 106 if stanza.attr.from then |
| 107 local from_occupant = room:get_occupant_by_nick(stanza.attr.from); | 107 local from_occupant = room:get_occupant_by_nick(stanza.attr.from); |
| 108 if from_occupant and valid_roles[from_occupant.role or "none"] < moderator_role_value then | 108 if from_occupant and valid_roles[from_occupant.role or "none"] < moderator_role_value then |
| 109 module:log("debug", "Message %s / %s must be sent separatly to it initialior %s.", id, stanza_id, delay, stanza.attr.from); | 109 module:log("debug", "Message %s / %s must be sent separatly to it initiator %s.", id, stanza_id, delay, stanza.attr.from); |
| 110 room:route_to_occupant(from_occupant, stanza); | 110 room:route_to_occupant(from_occupant, stanza); |
| 111 end | 111 end |
| 112 end | 112 end |
| 113 | 113 |
| 114 -- adding a tag, so that moderators can know that this message is delayed. | 114 -- adding a tag, so that moderators can know that this message is delayed. |
| 115 stanza:tag(moderation_delay_tag, { | 115 stanza:tag(moderation_delay_tag, { |
| 116 delay = "" .. delay; | 116 delay = "" .. delay; |
| 117 waiting = string.format("%i", get_time() + delay); | 117 waiting = string.format("%i", math.floor(get_time() + delay)); |
| 118 }):up(); | 118 }):up(); |
| 119 | 119 |
| 120 -- then, sending to moderators (and only moderators): | 120 -- then, sending to moderators (and only moderators): |
| 121 room:broadcast(stanza, function (nick, occupant) | 121 room:broadcast(stanza, function (nick, occupant) |
| 122 if valid_roles[occupant.role or "none"] >= moderator_role_value then | 122 if valid_roles[occupant.role or "none"] >= moderator_role_value then |
