ソースを参照

Makes possible for poltergeist to set status just before leaving.

j8
damencho 8年前
コミット
8047fdf5a2
1個のファイルの変更74行の追加42行の削除
  1. 74
    42
      resources/prosody-plugins/mod_muc_poltergeist.lua

+ 74
- 42
resources/prosody-plugins/mod_muc_poltergeist.lua ファイルの表示

@@ -33,6 +33,10 @@ local token_util = module:require "token/util".new(parentCtx);
33 33
 local disableTokenVerification
34 34
     = module:get_option_boolean("disable_polergeist_token_verification", false);
35 35
 
36
+-- option to expire poltergeist with custom status text
37
+local poltergeistExpiredStatus
38
+    = module:get_option_string("poltergeist_expired_status");
39
+
36 40
 -- table to store all poltergeists we create
37 41
 local poltergeists = {};
38 42
 -- table to mark that outgoing unavailable presences
@@ -214,10 +218,30 @@ function create_poltergeist_occupant(room, nick, name, avatar, status)
214 218
     room:handle_first_presence(
215 219
         prosody.hosts[poltergeist_component], join_presence);
216 220
 
217
-    timer.add_task(poltergeist_timeout,
221
+    local timeout = poltergeist_timeout;
222
+    -- the timeout before removing so participants can see the status update
223
+    local removeTimeout = 5;
224
+    if (poltergeistExpiredStatus) then
225
+        timeout = timeout - removeTimeout;
226
+    end
227
+
228
+    timer.add_task(timeout,
218 229
         function ()
219
-            if (have_poltergeist_occupant(room, nick)) then
220
-                remove_poltergeist_occupant(room, nick, false);
230
+            if (poltergeistExpiredStatus) then
231
+                update_poltergeist_occupant_status(
232
+                    room, nick, poltergeistExpiredStatus);
233
+                -- and remove it after some time so participant can see
234
+                -- the update
235
+                timer.add_task(removeTimeout,
236
+                    function ()
237
+                        if (have_poltergeist_occupant(room, nick)) then
238
+                            remove_poltergeist_occupant(room, nick, false);
239
+                        end
240
+                    end);
241
+            else
242
+                if (have_poltergeist_occupant(room, nick)) then
243
+                    remove_poltergeist_occupant(room, nick, false);
244
+                end
221 245
             end
222 246
         end);
223 247
 end
@@ -240,6 +264,52 @@ function remove_poltergeist_occupant(room, nick, ignore)
240 264
     remove_username(room, nick);
241 265
 end
242 266
 
267
+-- Updates poltergeist occupant status
268
+-- @param room the room instance where to remove the occupant
269
+-- @param nick the nick of the occupant to remove
270
+-- @param status the status to update
271
+function update_poltergeist_occupant_status(room, nick, status)
272
+    local update_presence = get_presence(room, nick);
273
+
274
+    if (not update_presence) then
275
+        -- no presence found for occupant, create one
276
+        update_presence = st.presence({
277
+            to = room.jid.."/"..nick,
278
+            from = poltergeist_component.."/"..nick
279
+        });
280
+    else
281
+        -- update occupant presence with appropriate to and from
282
+        -- so we can send it again
283
+        update_presence = st.clone(update_presence);
284
+        update_presence.attr.to = room.jid.."/"..nick;
285
+        update_presence.attr.from = poltergeist_component.."/"..nick;
286
+    end
287
+
288
+    local once = false;
289
+    -- the status tag we will attach
290
+    local statusTag = st.stanza("status"):text(status);
291
+
292
+    -- if there is already a status tag replace it
293
+    update_presence:maptags(function (tag)
294
+        if tag.name == statusTag.name then
295
+            if not once then
296
+                once = true;
297
+                return statusTag;
298
+            else
299
+                return nil;
300
+            end
301
+        end
302
+        return tag;
303
+    end);
304
+    if (not once) then
305
+        -- no status tag was repleced, attach it
306
+        update_presence:add_child(statusTag);
307
+    end
308
+
309
+    room:handle_normal_presence(
310
+        prosody.hosts[poltergeist_component], update_presence);
311
+end
312
+
243 313
 -- Checks for existance of a poltergeist occupant
244 314
 -- @param room the room instance where to check for occupant
245 315
 -- @param nick the nick of the occupant
@@ -359,45 +429,7 @@ function handle_update_poltergeist (event)
359 429
 
360 430
     local nick = string.sub(username, 0, 8);
361 431
     if (have_poltergeist_occupant(room, nick)) then
362
-        local update_presence = get_presence(room, nick);
363
-
364
-        if (not update_presence) then
365
-            -- no presence found for occupant, create one
366
-            update_presence = st.presence({
367
-                to = room.jid.."/"..nick,
368
-                from = poltergeist_component.."/"..nick
369
-            });
370
-        else
371
-            -- update occupant presence with appropriate to and from
372
-            -- so we can send it again
373
-            update_presence = st.clone(update_presence);
374
-            update_presence.attr.to = room.jid.."/"..nick;
375
-            update_presence.attr.from = poltergeist_component.."/"..nick;
376
-        end
377
-
378
-        local once = false;
379
-        -- the status tag we will attach
380
-        local statusTag = st.stanza("status"):text(status);
381
-
382
-        -- if there is already a status tag replace it
383
-        update_presence:maptags(function (tag)
384
-            if tag.name == statusTag.name then
385
-                if not once then
386
-                    once = true;
387
-                    return statusTag;
388
-                else
389
-                    return nil;
390
-                end
391
-            end
392
-            return tag;
393
-        end);
394
-        if (not once) then
395
-            -- no status tag was repleced, attach it
396
-            update_presence:add_child(statusTag);
397
-        end
398
-
399
-        room:handle_normal_presence(
400
-            prosody.hosts[poltergeist_component], update_presence);
432
+        update_poltergeist_occupant_status(room, nick, status);
401 433
 
402 434
         return 200;
403 435
     else

読み込み中…
キャンセル
保存