Software /
code /
prosody
Comparison
plugins/mod_roster.lua @ 5099:39eb688e106a
mod_roster: When an user is deleted, unsubscribe from their contacts
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 25 Aug 2012 01:31:05 +0200 |
parent | 5013:ab693eea0869 |
child | 5372:676e3cf0e565 |
comparison
equal
deleted
inserted
replaced
5098:fca8b5946f6f | 5099:39eb688e106a |
---|---|
13 local jid_prep = require "util.jid".prep; | 13 local jid_prep = require "util.jid".prep; |
14 local t_concat = table.concat; | 14 local t_concat = table.concat; |
15 local tonumber = tonumber; | 15 local tonumber = tonumber; |
16 local pairs, ipairs = pairs, ipairs; | 16 local pairs, ipairs = pairs, ipairs; |
17 | 17 |
18 local rm_load_roster = require "core.rostermanager".load_roster; | |
18 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster; | 19 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster; |
19 local rm_add_to_roster = require "core.rostermanager".add_to_roster; | 20 local rm_add_to_roster = require "core.rostermanager".add_to_roster; |
20 local rm_roster_push = require "core.rostermanager".roster_push; | 21 local rm_roster_push = require "core.rostermanager".roster_push; |
21 local core_post_stanza = prosody.core_post_stanza; | 22 local core_post_stanza = prosody.core_post_stanza; |
22 | 23 |
135 session.send(st.error_reply(stanza, "modify", "bad-request")); | 136 session.send(st.error_reply(stanza, "modify", "bad-request")); |
136 end | 137 end |
137 end | 138 end |
138 return true; | 139 return true; |
139 end); | 140 end); |
141 | |
142 module:hook_global("user-deleted", function(event) | |
143 local username, host = event.username, event.host; | |
144 if host ~= module.host then return end | |
145 local bare = username .. "@" .. host; | |
146 local roster = rm_load_roster(username, host); | |
147 for jid, item in pairs(roster) do | |
148 if jid and jid ~= "pending" then | |
149 if item.subscription == "both" or item.subscription == "from" or (roster.pending and roster.pending[jid]) then | |
150 module:send(st.presence({type="unsubscribed", from=bare, to=jid})); | |
151 end | |
152 if item.subscription == "both" or item.subscription == "to" or item.ask then | |
153 module:send(st.presence({type="unsubscribe", from=bare, to=jid})); | |
154 end | |
155 end | |
156 end | |
157 end, 300); |