aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/muc
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-03-25 13:18:23 +0100
committerKim Alvefur <zash@zash.se>2021-03-25 13:18:23 +0100
commit1f00a4fd8e369b2b9680f2a3f09c748c8db60e23 (patch)
tree0b5b4186ab96e1d64344e4fcc8ac9bff429c0e72 /plugins/muc
parent40c620c7e801258baad41809a3a793128220e46e (diff)
downloadprosody-1f00a4fd8e369b2b9680f2a3f09c748c8db60e23.tar.gz
prosody-1f00a4fd8e369b2b9680f2a3f09c748c8db60e23.zip
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.
Diffstat (limited to 'plugins/muc')
-rw-r--r--plugins/muc/muc.lib.lua13
1 files changed, 9 insertions, 4 deletions
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index d1449af1..f34b579c 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -1186,10 +1186,15 @@ function room_mt:handle_groupchat_to_room(origin, stanza)
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;