Mercurial > prosody-hg
comparison plugins/mod_roster.lua @ 326:99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Mon, 17 Nov 2008 13:51:47 +0500 |
| parents | 300b5a201ad3 |
| children | 63be85693710 |
comparison
equal
deleted
inserted
replaced
| 325:5de1048b3fbf | 326:99a8317d1235 |
|---|---|
| 2 local st = require "util.stanza" | 2 local st = require "util.stanza" |
| 3 | 3 |
| 4 local jid_split = require "util.jid".split; | 4 local jid_split = require "util.jid".split; |
| 5 local t_concat = table.concat; | 5 local t_concat = table.concat; |
| 6 | 6 |
| 7 local handle_outbound_presence_subscriptions_and_probes = require "core.presencemanager".handle_outbound_presence_subscriptions_and_probes; | |
| 7 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster; | 8 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster; |
| 8 local rm_add_to_roster = require "core.rostermanager".add_to_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", |
| 36 if #query.tags == 1 and query.tags[1].name == "item" | 37 if #query.tags == 1 and query.tags[1].name == "item" |
| 37 and query.tags[1].attr.xmlns == "jabber:iq:roster" and query.tags[1].attr.jid | 38 and query.tags[1].attr.xmlns == "jabber:iq:roster" and query.tags[1].attr.jid |
| 38 and query.tags[1].attr.jid ~= "pending" then | 39 and query.tags[1].attr.jid ~= "pending" then |
| 39 local item = query.tags[1]; | 40 local item = query.tags[1]; |
| 40 local from_node, from_host = jid_split(stanza.attr.from); | 41 local from_node, from_host = jid_split(stanza.attr.from); |
| 42 local from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID | |
| 41 local node, host, resource = jid_split(item.attr.jid); | 43 local node, host, resource = jid_split(item.attr.jid); |
| 42 if not resource then | 44 local to_bare = node and (node.."@"..host) or host; -- bare JID |
| 45 if not resource and host then | |
| 43 if item.attr.jid ~= from_node.."@"..from_host then | 46 if item.attr.jid ~= from_node.."@"..from_host then |
| 44 if item.attr.subscription == "remove" then | 47 if item.attr.subscription == "remove" then |
| 45 if session.roster[item.attr.jid] then | 48 local r_item = session.roster[item.attr.jid]; |
| 49 if r_item then | |
| 46 local success, err_type, err_cond, err_msg = rm_remove_from_roster(session, item.attr.jid); | 50 local success, err_type, err_cond, err_msg = rm_remove_from_roster(session, item.attr.jid); |
| 47 if success then | 51 if success then |
| 48 session.send(st.reply(stanza)); | 52 session.send(st.reply(stanza)); |
| 49 rm_roster_push(from_node, from_host, item.attr.jid); | 53 rm_roster_push(from_node, from_host, item.attr.jid); |
| 54 if r_item.subscription == "both" or r_item.subscription == "from" then | |
| 55 handle_outbound_presence_subscriptions_and_probes(session, | |
| 56 st.presence({type="unsubscribed"}), from_bare, to_bare); | |
| 57 elseif r_item.subscription == "both" or r_item.subscription == "to" then | |
| 58 handle_outbound_presence_subscriptions_and_probes(session, | |
| 59 st.presence({type="unsubscribe"}), from_bare, to_bare); | |
| 60 end | |
| 50 else | 61 else |
| 51 session.send(st.error_reply(stanza, err_type, err_cond, err_msg)); | 62 session.send(st.error_reply(stanza, err_type, err_cond, err_msg)); |
| 52 end | 63 end |
| 53 else | 64 else |
| 54 session.send(st.error_reply(stanza, "modify", "item-not-found")); | 65 session.send(st.error_reply(stanza, "modify", "item-not-found")); |
