Software /
code /
prosody
Comparison
core/rostermanager.lua @ 132:9a4aa57af367
Roster updates
- Added support for item.ask attribute in rostermanager and mod_roster
- Updated roster docs
- Removed old code from rostermanager
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 23 Oct 2008 20:02:30 +0500 |
parent | 114:bed2a8508cf5 |
child | 171:28f420d057a0 |
comparison
equal
deleted
inserted
replaced
131:4bbbc7883ee6 | 132:9a4aa57af367 |
---|---|
15 | 15 |
16 local datamanager = datamanager; | 16 local datamanager = datamanager; |
17 local st = require "util.stanza"; | 17 local st = require "util.stanza"; |
18 | 18 |
19 module "rostermanager" | 19 module "rostermanager" |
20 | |
21 --[[function getroster(username, host) | |
22 return { | |
23 ["mattj@localhost"] = true, | |
24 ["tobias@getjabber.ath.cx"] = true, | |
25 ["waqas@getjabber.ath.cx"] = true, | |
26 ["thorns@getjabber.ath.cx"] = true, | |
27 ["idw@getjabber.ath.cx"] = true, | |
28 } | |
29 --return datamanager.load(username, host, "roster") or {}; | |
30 end]] | |
31 | 20 |
32 function add_to_roster(session, jid, item) | 21 function add_to_roster(session, jid, item) |
33 if session.roster then | 22 if session.roster then |
34 local old_item = session.roster[jid]; | 23 local old_item = session.roster[jid]; |
35 session.roster[jid] = item; | 24 session.roster[jid] = item; |
63 if hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then | 52 if hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then |
64 local item = hosts[host].sessions[username].roster[jid]; | 53 local item = hosts[host].sessions[username].roster[jid]; |
65 local stanza = st.iq({type="set"}); | 54 local stanza = st.iq({type="set"}); |
66 stanza:tag("query", {xmlns = "jabber:iq:roster"}); | 55 stanza:tag("query", {xmlns = "jabber:iq:roster"}); |
67 if item then | 56 if item then |
68 stanza:tag("item", {jid = jid, subscription = item.subscription, name = item.name}); | 57 stanza:tag("item", {jid = jid, subscription = item.subscription, name = item.name, ask = item.ask}); |
69 for group in pairs(item.groups) do | 58 for group in pairs(item.groups) do |
70 stanza:tag("group"):text(group):up(); | 59 stanza:tag("group"):text(group):up(); |
71 end | 60 end |
72 else | 61 else |
73 stanza:tag("item", {jid = jid, subscription = "remove"}); | 62 stanza:tag("item", {jid = jid, subscription = "remove"}); |
92 hosts[host].sessions[username].roster = roster; | 81 hosts[host].sessions[username].roster = roster; |
93 end | 82 end |
94 return roster; | 83 return roster; |
95 end | 84 end |
96 -- Attempt to load roster for non-loaded user | 85 -- Attempt to load roster for non-loaded user |
86 -- TODO also support loading for offline user | |
97 end | 87 end |
98 | 88 |
99 function save_roster(username, host) | 89 function save_roster(username, host) |
100 if hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then | 90 if hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then |
101 return datamanager.store(username, host, "roster", hosts[host].sessions[username].roster); | 91 return datamanager.store(username, host, "roster", hosts[host].sessions[username].roster); |