Mercurial > prosody-hg
comparison plugins/mod_roster.lua @ 6613:2aae36312eb9
rostermanager, mod_roster, mod_presence: Move pending roster items to roster metadata field
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 03 Apr 2015 06:38:22 +0200 |
| parents | bd0ff8ae98a8 |
| children | c8ad387aab1c |
comparison
equal
deleted
inserted
replaced
| 6612:6cc48b51d699 | 6613:2aae36312eb9 |
|---|---|
| 42 | 42 |
| 43 if not (client_ver and server_ver) or client_ver ~= server_ver then | 43 if not (client_ver and server_ver) or client_ver ~= server_ver then |
| 44 roster:query("jabber:iq:roster"); | 44 roster:query("jabber:iq:roster"); |
| 45 -- Client does not support versioning, or has stale roster | 45 -- Client does not support versioning, or has stale roster |
| 46 for jid, item in pairs(session.roster) do | 46 for jid, item in pairs(session.roster) do |
| 47 if jid ~= "pending" and jid then | 47 if jid then |
| 48 roster:tag("item", { | 48 roster:tag("item", { |
| 49 jid = jid, | 49 jid = jid, |
| 50 subscription = item.subscription, | 50 subscription = item.subscription, |
| 51 ask = item.ask, | 51 ask = item.ask, |
| 52 name = item.name, | 52 name = item.name, |
| 62 session.send(roster); | 62 session.send(roster); |
| 63 session.interested = true; -- resource is interested in roster updates | 63 session.interested = true; -- resource is interested in roster updates |
| 64 else -- stanza.attr.type == "set" | 64 else -- stanza.attr.type == "set" |
| 65 local query = stanza.tags[1]; | 65 local query = stanza.tags[1]; |
| 66 if #query.tags == 1 and query.tags[1].name == "item" | 66 if #query.tags == 1 and query.tags[1].name == "item" |
| 67 and query.tags[1].attr.xmlns == "jabber:iq:roster" and query.tags[1].attr.jid | 67 and query.tags[1].attr.xmlns == "jabber:iq:roster" and query.tags[1].attr.jid then |
| 68 -- Protection against overwriting roster.pending, until we move it | |
| 69 and query.tags[1].attr.jid ~= "pending" then | |
| 70 local item = query.tags[1]; | 68 local item = query.tags[1]; |
| 71 local from_node, from_host = jid_split(stanza.attr.from); | 69 local from_node, from_host = jid_split(stanza.attr.from); |
| 72 local jid = jid_prep(item.attr.jid); | 70 local jid = jid_prep(item.attr.jid); |
| 73 local node, host, resource = jid_split(jid); | 71 local node, host, resource = jid_split(jid); |
| 74 if not resource and host then | 72 if not resource and host then |
| 76 if item.attr.subscription == "remove" then | 74 if item.attr.subscription == "remove" then |
| 77 local roster = session.roster; | 75 local roster = session.roster; |
| 78 local r_item = roster[jid]; | 76 local r_item = roster[jid]; |
| 79 if r_item then | 77 if r_item then |
| 80 local to_bare = node and (node.."@"..host) or host; -- bare JID | 78 local to_bare = node and (node.."@"..host) or host; -- bare JID |
| 81 if r_item.subscription == "both" or r_item.subscription == "from" or (roster.pending and roster.pending[jid]) then | 79 if r_item.subscription == "both" or r_item.subscription == "from" or roster[false].pending[jid] then |
| 82 core_post_stanza(session, st.presence({type="unsubscribed", from=session.full_jid, to=to_bare})); | 80 core_post_stanza(session, st.presence({type="unsubscribed", from=session.full_jid, to=to_bare})); |
| 83 end | 81 end |
| 84 if r_item.subscription == "both" or r_item.subscription == "to" or r_item.ask then | 82 if r_item.subscription == "both" or r_item.subscription == "to" or r_item.ask then |
| 85 core_post_stanza(session, st.presence({type="unsubscribe", from=session.full_jid, to=to_bare})); | 83 core_post_stanza(session, st.presence({type="unsubscribe", from=session.full_jid, to=to_bare})); |
| 86 end | 84 end |
| 142 local username, host = event.username, event.host; | 140 local username, host = event.username, event.host; |
| 143 if host ~= module.host then return end | 141 if host ~= module.host then return end |
| 144 local bare = username .. "@" .. host; | 142 local bare = username .. "@" .. host; |
| 145 local roster = rm_load_roster(username, host); | 143 local roster = rm_load_roster(username, host); |
| 146 for jid, item in pairs(roster) do | 144 for jid, item in pairs(roster) do |
| 147 if jid and jid ~= "pending" then | 145 if jid then |
| 148 if item.subscription == "both" or item.subscription == "from" or (roster.pending and roster.pending[jid]) then | 146 if item.subscription == "both" or item.subscription == "from" or roster[false].pending[jid] then |
| 149 module:send(st.presence({type="unsubscribed", from=bare, to=jid})); | 147 module:send(st.presence({type="unsubscribed", from=bare, to=jid})); |
| 150 end | 148 end |
| 151 if item.subscription == "both" or item.subscription == "to" or item.ask then | 149 if item.subscription == "both" or item.subscription == "to" or item.ask then |
| 152 module:send(st.presence({type="unsubscribe", from=bare, to=jid})); | 150 module:send(st.presence({type="unsubscribe", from=bare, to=jid})); |
| 153 end | 151 end |
