|
@@ -182,6 +182,20 @@ function have_poltergeist_occupant(room, nick)
|
182
|
182
|
return not not room:get_occupant_jid(poltergeist_component.."/"..nick);
|
183
|
183
|
end
|
184
|
184
|
|
|
185
|
+-- Returns the last presence of occupant
|
|
186
|
+-- @param room the room instance where to check for occupant
|
|
187
|
+-- @param nick the nick of the occupant
|
|
188
|
+-- @return presence of the occupant
|
|
189
|
+function get_presence(room, nick)
|
|
190
|
+ local occupant_jid
|
|
191
|
+ = room:get_occupant_jid(poltergeist_component.."/"..nick);
|
|
192
|
+ if (occupant_jid) then
|
|
193
|
+ return room:get_occupant_by_nick(occupant_jid):get_presence();
|
|
194
|
+ end
|
|
195
|
+
|
|
196
|
+ return nil;
|
|
197
|
+end
|
|
198
|
+
|
185
|
199
|
-- Event handlers
|
186
|
200
|
|
187
|
201
|
--- Note: mod_muc and some of its sub-modules add event handlers between 0 and -100,
|
|
@@ -268,10 +282,42 @@ function handle_update_poltergeist (event)
|
268
|
282
|
|
269
|
283
|
local nick = string.sub(username, 0, 8);
|
270
|
284
|
if (have_poltergeist_occupant(room, nick)) then
|
271
|
|
- local update_presence = st.presence({
|
272
|
|
- to = room.jid.."/"..nick,
|
273
|
|
- from = poltergeist_component.."/"..nick
|
274
|
|
- }):tag("status"):text(status):up();
|
|
285
|
+ local update_presence = get_presence(room, nick);
|
|
286
|
+
|
|
287
|
+ if (not update_presence) then
|
|
288
|
+ -- no presence found for occupant, create one
|
|
289
|
+ update_presence = st.presence({
|
|
290
|
+ to = room.jid.."/"..nick,
|
|
291
|
+ from = poltergeist_component.."/"..nick
|
|
292
|
+ });
|
|
293
|
+ else
|
|
294
|
+ -- update occupant presence with appropriate to and from
|
|
295
|
+ -- so we can send it again
|
|
296
|
+ update_presence = st.clone(update_presence);
|
|
297
|
+ update_presence.attr.to = room.jid.."/"..nick;
|
|
298
|
+ update_presence.attr.from = poltergeist_component.."/"..nick;
|
|
299
|
+ end
|
|
300
|
+
|
|
301
|
+ local once = false;
|
|
302
|
+ -- the status tag we will attach
|
|
303
|
+ local statusTag = st.stanza("status"):text(status);
|
|
304
|
+
|
|
305
|
+ -- if there is already a status tag replace it
|
|
306
|
+ update_presence:maptags(function (tag)
|
|
307
|
+ if tag.name == statusTag.name then
|
|
308
|
+ if not once then
|
|
309
|
+ once = true;
|
|
310
|
+ return statusTag;
|
|
311
|
+ else
|
|
312
|
+ return nil;
|
|
313
|
+ end
|
|
314
|
+ end
|
|
315
|
+ return tag;
|
|
316
|
+ end);
|
|
317
|
+ if (not once) then
|
|
318
|
+ -- no status tag was repleced, attach it
|
|
319
|
+ update_presence:add_child(statusTag);
|
|
320
|
+ end
|
275
|
321
|
|
276
|
322
|
room:handle_normal_presence(
|
277
|
323
|
prosody.hosts[poltergeist_component], update_presence);
|