Software /
code /
prosody
Comparison
core/rostermanager.lua @ 110:bb5ac5976a97
Fixed: Roster support
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Wed, 22 Oct 2008 21:20:07 +0500 |
parent | 107:8d8debda3df2 |
child | 114:bed2a8508cf5 |
comparison
equal
deleted
inserted
replaced
109:7efedc96352a | 110:bb5ac5976a97 |
---|---|
5 end | 5 end |
6 | 6 |
7 local setmetatable = setmetatable; | 7 local setmetatable = setmetatable; |
8 local format = string.format; | 8 local format = string.format; |
9 local loadfile, setfenv, pcall = loadfile, setfenv, pcall; | 9 local loadfile, setfenv, pcall = loadfile, setfenv, pcall; |
10 local pairs, ipairs = pairs, ipairs; | |
10 | 11 |
11 local hosts = hosts; | 12 local hosts = hosts; |
12 | 13 |
13 require "util.datamanager" | 14 require "util.datamanager" |
14 | 15 |
15 local datamanager = datamanager; | 16 local datamanager = datamanager; |
16 local st = require "util.stanza"; | 17 local st = require "util.stanza"; |
17 local send = require "core.sessionmanager".send_to_session; | |
18 | 18 |
19 module "rostermanager" | 19 module "rostermanager" |
20 | 20 |
21 --[[function getroster(username, host) | 21 --[[function getroster(username, host) |
22 return { | 22 return { |
64 local item = hosts[host].sessions[username].roster[jid]; | 64 local item = hosts[host].sessions[username].roster[jid]; |
65 local stanza = st.iq({type="set"}); | 65 local stanza = st.iq({type="set"}); |
66 stanza:tag("query", {xmlns = "jabber:iq:roster"}); | 66 stanza:tag("query", {xmlns = "jabber:iq:roster"}); |
67 if item then | 67 if item then |
68 stanza:tag("item", {jid = jid, subscription = item.subscription, name = item.name}); | 68 stanza:tag("item", {jid = jid, subscription = item.subscription, name = item.name}); |
69 for group in pairs(item.groups) do | |
70 stanza:tag("group"):text(group):up(); | |
71 end | |
69 else | 72 else |
70 stanza:tag("item", {jid = jid, subscription = "remove"}); | 73 stanza:tag("item", {jid = jid, subscription = "remove"}); |
71 end | |
72 for group in item.groups do | |
73 stanza:tag("group"):text(group):up(); | |
74 end | 74 end |
75 stanza:up(); | 75 stanza:up(); |
76 stanza:up(); | 76 stanza:up(); |
77 -- stanza ready | 77 -- stanza ready |
78 for _, session in ipairs(hosts[host].sessions[username].sessions) do | 78 for _, session in pairs(hosts[host].sessions[username].sessions) do |
79 if session.full_jid then | 79 if session.full_jid then |
80 -- FIXME do we need to set stanza.attr.to? | 80 -- FIXME do we need to set stanza.attr.to? |
81 send(session, stanza); | 81 session.send(stanza); |
82 end | 82 end |
83 end | 83 end |
84 end | 84 end |
85 end | 85 end |
86 | 86 |
96 -- Attempt to load roster for non-loaded user | 96 -- Attempt to load roster for non-loaded user |
97 end | 97 end |
98 | 98 |
99 function save_roster(username, host) | 99 function save_roster(username, host) |
100 if hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then | 100 if hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then |
101 return datamanager.save(username, host, "roster", hosts[host].sessions[username].roster); | 101 return datamanager.store(username, host, "roster", hosts[host].sessions[username].roster); |
102 end | 102 end |
103 return nil; | 103 return nil; |
104 end | 104 end |
105 | 105 |
106 return _M; | 106 return _M; |