Comparison

plugins/muc/muc.lib.lua @ 11498:d61ec5e6ee16

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.
author Kim Alvefur <zash@zash.se>
date Thu, 25 Mar 2021 13:18:23 +0100
parent 11246:ab189e707705
child 11713:7623767df468
comparison
equal deleted inserted replaced
11497:960674938665 11498:d61ec5e6ee16
1184 local from = stanza.attr.from; 1184 local from = stanza.attr.from;
1185 local occupant = self:get_occupant_by_real_jid(from); 1185 local occupant = self:get_occupant_by_real_jid(from);
1186 if not stanza.attr.id then 1186 if not stanza.attr.id then
1187 stanza.attr.id = new_id() 1187 stanza.attr.id = new_id()
1188 end 1188 end
1189 if module:fire_event("muc-occupant-groupchat", { 1189 local event_data = {room = self; origin = origin; stanza = stanza; from = from; occupant = occupant};
1190 room = self; origin = origin; stanza = stanza; from = from; occupant = occupant; 1190 if module:fire_event("muc-occupant-groupchat", event_data) then
1191 }) then return true; end 1191 return true;
1192 stanza.attr.from = occupant.nick; 1192 end
1193 if event_data.occupant then
1194 stanza.attr.from = event_data.occupant.nick;
1195 else
1196 stanza.attr.from = self.jid;
1197 end
1193 self:broadcast_message(stanza); 1198 self:broadcast_message(stanza);
1194 stanza.attr.from = from; 1199 stanza.attr.from = from;
1195 return true; 1200 return true;
1196 end 1201 end
1197 1202