Comparison

plugins/mod_roster.lua @ 110:bb5ac5976a97

Fixed: Roster support
author Waqas Hussain <waqas20@gmail.com>
date Wed, 22 Oct 2008 21:20:07 +0500
parent 108:1d79da482c5d
child 114:bed2a8508cf5
comparison
equal deleted inserted replaced
109:7efedc96352a 110:bb5ac5976a97
4 4
5 local jid_split = require "util.jid".split; 5 local jid_split = require "util.jid".split;
6 local t_concat = table.concat; 6 local t_concat = table.concat;
7 7
8 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster; 8 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster;
9 local rm_add_to_roster = require "core.rostermanager".add_to_roster;
9 local rm_roster_push = require "core.rostermanager".roster_push; 10 local rm_roster_push = require "core.rostermanager".roster_push;
10 11
11 add_iq_handler("c2s", "jabber:iq:roster", 12 add_iq_handler("c2s", "jabber:iq:roster",
12 function (session, stanza) 13 function (session, stanza)
13 if stanza.tags[1].name == "query" then 14 if stanza.tags[1].name == "query" then
14 if stanza.attr.type == "get" then 15 if stanza.attr.type == "get" then
15 local roster = st.reply(stanza) 16 local roster = st.reply(stanza)
16 :query("jabber:iq:roster"); 17 :query("jabber:iq:roster");
17 for jid in pairs(session.roster) do 18 for jid in pairs(session.roster) do
18 local item = st.stanza("item", { 19 roster:tag("item", {
19 jid = jid, 20 jid = jid,
20 subscription = session.roster[jid].subscription, 21 subscription = session.roster[jid].subscription,
21 name = session.roster[jid].name, 22 name = session.roster[jid].name,
22 }); 23 });
23 for group in pairs(session.roster[jid].groups) do 24 for group in pairs(session.roster[jid].groups) do
24 item:tag("group"):text(group):up(); 25 roster:tag("group"):text(group):up();
25 end 26 end
26 roster:add_child(item);
27 end 27 end
28 send(session, roster); 28 send(session, roster);
29 return true; 29 return true;
30 elseif stanza.attr.type == "set" then 30 elseif stanza.attr.type == "set" then
31 local query = stanza.tags[1]; 31 local query = stanza.tags[1];
50 end 50 end
51 else 51 else
52 local r_item = {name = item.attr.name, groups = {}}; 52 local r_item = {name = item.attr.name, groups = {}};
53 if r_item.name == "" then r_item.name = nil; end 53 if r_item.name == "" then r_item.name = nil; end
54 if session.roster[item.attr.jid] then 54 if session.roster[item.attr.jid] then
55 r_item.subscription = session.roster[item.attr.jid]; 55 r_item.subscription = session.roster[item.attr.jid].subscription;
56 else 56 else
57 r_item.subscription = "none"; 57 r_item.subscription = "none";
58 end 58 end
59 for _, child in ipairs(item) do 59 for _, child in ipairs(item) do
60 if child.name == "group" then 60 if child.name == "group" then