Comparison

mod_muc_rai/mod_muc_rai.lua @ 4510:6690586826e8

mod_muc_rai: Switch to low-priority pre-* events, which should suffice for per-session tracking
author Matthew Wild <mwild1@gmail.com>
date Mon, 15 Mar 2021 16:55:21 +0000
parent 4335:e03dadd4f2d1
child 4543:9377b5593cc7
comparison
equal deleted inserted replaced
4509:16995e7624f0 4510:6690586826e8
184 end 184 end
185 end 185 end
186 return rooms_with_activity; 186 return rooms_with_activity;
187 end 187 end
188 188
189 --- FIXME: 189 module:hook("muc-occupant-pre-join", function(event)
190 -- The subscribe/unsubscribe code below doesn't work in the case where
191 -- the user joins from multiple resources with the same nick.
192 --
193 -- For example, resource A joining, followed by resource B joining, followed
194 -- by A leaving and B leaving will ultimately trigger muc-occupant-joined for
195 -- resource A and muc-occupant-left for resource B.
196
197 module:hook("muc-occupant-joined", function(event)
198 local room_jid, user_jid = event.room.jid, event.stanza.attr.from; 190 local room_jid, user_jid = event.room.jid, event.stanza.attr.from;
199 local ok, _ = unsubscribe_room(user_jid, room_jid); 191 local ok, _ = unsubscribe_room(user_jid, room_jid);
200 if ok then 192 if ok then
201 module:log("debug", "Unsubscribed %s to %s Reason: muc-occupant-joined", user_jid, room_jid) 193 module:log("debug", "Unsubscribed %s to %s Reason: muc-occupant-joined", user_jid, room_jid)
202 end 194 end
203 end); 195 end, -500);
204 196
205 module:hook("muc-occupant-left", function(event) 197 module:hook("muc-occupant-pre-leave", function(event)
206 local room_jid, user_jid = event.room.jid, event.occupant.jid; 198 local room_jid, user_jid = event.room.jid, event.stanza.attr.from;
207 local ok, _ = subscribe_room(user_jid, room_jid); 199 local ok, _ = subscribe_room(user_jid, room_jid);
208 if ok then 200 if ok then
209 module:log("debug", "Subscribed %s to %s Reason: muc-occupant-left", user_jid, room_jid) 201 module:log("debug", "Subscribed %s to %s Reason: muc-occupant-left", user_jid, room_jid)
210 end 202 end
211 end); 203 end, -500);
212 204
213 module:hook("presence/host", function (event) 205 module:hook("presence/host", function (event)
214 local origin, stanza = event.origin, event.stanza; 206 local origin, stanza = event.origin, event.stanza;
215 local user_jid = stanza.attr.from; 207 local user_jid = stanza.attr.from;
216 208