Software /
code /
prosody
Comparison
plugins/mod_roster.lua @ 916:f0743928ef7e
core.rostermanager/mod_roster: Support for roster versioning
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 23 Mar 2009 00:31:29 +0000 |
parent | 896:2c0b9e3c11c3 |
child | 928:92288c13d7bc |
comparison
equal
deleted
inserted
replaced
915:0fe5bf7ab81d | 916:f0743928ef7e |
---|---|
10 | 10 |
11 local st = require "util.stanza" | 11 local st = require "util.stanza" |
12 | 12 |
13 local jid_split = require "util.jid".split; | 13 local jid_split = require "util.jid".split; |
14 local t_concat = table.concat; | 14 local t_concat = table.concat; |
15 local tostring = tostring; | |
15 | 16 |
16 local handle_presence = require "core.presencemanager".handle_presence; | 17 local handle_presence = require "core.presencemanager".handle_presence; |
17 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster; | 18 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster; |
18 local rm_add_to_roster = require "core.rostermanager".add_to_roster; | 19 local rm_add_to_roster = require "core.rostermanager".add_to_roster; |
19 local rm_roster_push = require "core.rostermanager".roster_push; | 20 local rm_roster_push = require "core.rostermanager".roster_push; |
25 function (session, stanza) | 26 function (session, stanza) |
26 if stanza.tags[1].name == "query" then | 27 if stanza.tags[1].name == "query" then |
27 if stanza.attr.type == "get" then | 28 if stanza.attr.type == "get" then |
28 local roster = st.reply(stanza) | 29 local roster = st.reply(stanza) |
29 :query("jabber:iq:roster"); | 30 :query("jabber:iq:roster"); |
30 for jid in pairs(session.roster) do | 31 |
31 if jid ~= "pending" then | 32 local ver = stanza.tags[1].attr.ver |
32 roster:tag("item", { | 33 |
33 jid = jid, | 34 if (not ver) or tonumber(ver) ~= (session.roster[false].version or 1) then |
34 subscription = session.roster[jid].subscription, | 35 -- Client does not support versioning, or has stale roster |
35 ask = session.roster[jid].ask, | 36 for jid in pairs(session.roster) do |
36 name = session.roster[jid].name, | 37 if jid ~= "pending" and jid then |
37 }); | 38 roster:tag("item", { |
38 for group in pairs(session.roster[jid].groups) do | 39 jid = jid, |
39 roster:tag("group"):text(group):up(); | 40 subscription = session.roster[jid].subscription, |
41 ask = session.roster[jid].ask, | |
42 name = session.roster[jid].name, | |
43 }); | |
44 for group in pairs(session.roster[jid].groups) do | |
45 roster:tag("group"):text(group):up(); | |
46 end | |
47 roster:up(); -- move out from item | |
40 end | 48 end |
41 roster:up(); -- move out from item | |
42 end | 49 end |
50 roster.tags[1].attr.ver = tostring(session.roster[false].version or "1"); | |
43 end | 51 end |
44 session.send(roster); | 52 session.send(roster); |
45 session.interested = true; -- resource is interested in roster updates | 53 session.interested = true; -- resource is interested in roster updates |
46 return true; | 54 return true; |
47 elseif stanza.attr.type == "set" then | 55 elseif stanza.attr.type == "set" then |
48 local query = stanza.tags[1]; | 56 local query = stanza.tags[1]; |
49 if #query.tags == 1 and query.tags[1].name == "item" | 57 if #query.tags == 1 and query.tags[1].name == "item" |
50 and query.tags[1].attr.xmlns == "jabber:iq:roster" and query.tags[1].attr.jid | 58 and query.tags[1].attr.xmlns == "jabber:iq:roster" and query.tags[1].attr.jid |
59 -- Protection against overwriting roster.pending, until we move it | |
51 and query.tags[1].attr.jid ~= "pending" then | 60 and query.tags[1].attr.jid ~= "pending" then |
52 local item = query.tags[1]; | 61 local item = query.tags[1]; |
53 local from_node, from_host = jid_split(stanza.attr.from); | 62 local from_node, from_host = jid_split(stanza.attr.from); |
54 local from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID | 63 local from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID |
55 local node, host, resource = jid_split(item.attr.jid); | 64 local node, host, resource = jid_split(item.attr.jid); |