plugins/disco.lua

changeset 167
a2ae7a9d360f
parent 146
2678048e93e6
child 172
1a32e9ae79d0
equal deleted inserted replaced
166:3499b4ea3277 167:a2ae7a9d360f
28 stream.disco.nodes = {} 28 stream.disco.nodes = {}
29 29
30 stream.caps = {} 30 stream.caps = {}
31 stream.caps.node = 'http://code.matthewwild.co.uk/verse/' 31 stream.caps.node = 'http://code.matthewwild.co.uk/verse/'
32 32
33 local _resend_presence; -- Forward declaration of a function
34
33 local function cmp_identity(item1, item2) 35 local function cmp_identity(item1, item2)
34 if item1.category < item2.category then 36 if item1.category < item2.category then
35 return true; 37 return true;
36 elseif item2.category < item1.category then 38 elseif item2.category < item1.category then
37 return false; 39 return false;
85 }) 87 })
86 end 88 end
87 }) 89 })
88 90
89 function stream:add_disco_feature(feature) 91 function stream:add_disco_feature(feature)
90 table.insert(self.disco.info.features, {var=feature}); 92 table.insert(self.disco.info.features, {var=feature});
93 _resend_presence();
91 end 94 end
92 95
93 function stream:remove_disco_feature(feature) 96 function stream:remove_disco_feature(feature)
94 for idx, disco_feature in ipairs(self.disco.info.features) do 97 for idx, disco_feature in ipairs(self.disco.info.features) do
95 if disco_feature.var == feature then 98 if disco_feature.var == feature then
96 table.remove(self.disco.info.features, idx); 99 table.remove(self.disco.info.features, idx);
100 _resend_presence();
97 return true; 101 return true;
98 end 102 end
99 end 103 end
100 end 104 end
101 105
368 end 372 end
369 stream:event("ready"); 373 stream:event("ready");
370 end); 374 end);
371 return true; 375 return true;
372 end, 5); 376 end, 5);
377
378 local last_presence; -- Cache to re-send with updated caps
379
380 stream:hook("presence-out", function (presence)
381 if not presence:get_child("c", xmlns_caps) then
382 presence:reset():add_child(stream:caps()):reset();
383 end
384 if not presence.attr.to then
385 last_presence = presence; -- Cache non-directed presence
386 end
387 end);
388
389 local function update_caps(tag)
390 if tag.name == "c" and tag.attr.xmlns == xmlns_caps then
391 return stream:caps();
392 end
393 end
394
395 function _resend_presence() -- Local via forward declaration
396 if last_presence then
397 last_presence = last_presence:maptags(update_caps);
398 stream:send(last_presence);
399 end
400 end
373 end 401 end
374 402
375 -- end of disco.lua 403 -- end of disco.lua

mercurial