# HG changeset patch # User Kim Alvefur # Date 1616674703 -3600 # Node ID d61ec5e6ee1696d198eb3f01500925308a072c1a # Parent 960674938665e087db37eb18fcfc47769e07a4d8 MUC: Allow overriding occupant object from groupchat message event Use case: Enable module that provides a virtual occupant object for bots Before, if there is no occupant then either some other part of MUC would reject the message or `occupant.nick` would have caused an error. diff -r 960674938665 -r d61ec5e6ee16 plugins/muc/muc.lib.lua --- a/plugins/muc/muc.lib.lua Thu Apr 01 12:30:55 2021 +0200 +++ b/plugins/muc/muc.lib.lua Thu Mar 25 13:18:23 2021 +0100 @@ -1186,10 +1186,15 @@ if not stanza.attr.id then stanza.attr.id = new_id() end - if module:fire_event("muc-occupant-groupchat", { - room = self; origin = origin; stanza = stanza; from = from; occupant = occupant; - }) then return true; end - stanza.attr.from = occupant.nick; + local event_data = {room = self; origin = origin; stanza = stanza; from = from; occupant = occupant}; + if module:fire_event("muc-occupant-groupchat", event_data) then + return true; + end + if event_data.occupant then + stanza.attr.from = event_data.occupant.nick; + else + stanza.attr.from = self.jid; + end self:broadcast_message(stanza); stanza.attr.from = from; return true;