Software /
code /
prosody-modules
Diff
mod_support_contact/mod_support_contact.lua @ 100:999a4b3e699b
mod_support_contact: Added support for remote support contact.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 30 Nov 2009 17:43:23 +0500 |
parent | 1:21e089282b8f |
child | 777:e5413b66aeec |
line wrap: on
line diff
--- a/mod_support_contact/mod_support_contact.lua Thu Nov 26 20:23:20 2009 +0500 +++ b/mod_support_contact/mod_support_contact.lua Mon Nov 30 17:43:23 2009 +0500 @@ -16,6 +16,7 @@ local rostermanager = require "core.rostermanager"; local datamanager = require "util.datamanager"; local jid_split = require "util.jid".split; +local st = require "util.stanza"; module:hook("user-registered", function(event) module:log("debug", "Adding support contact"); @@ -26,14 +27,22 @@ local jid = node and (node..'@'..host) or host; local roster; - roster = rostermanager.load_roster(node, host) or {}; - roster[support_contact] = {subscription = "both", name = support_contact_nick, groups = {}}; - datamanager.store(node, host, "roster", roster); + roster = rostermanager.load_roster(node, host); + if hosts[host] then + roster[support_contact] = {subscription = "both", name = support_contact_nick, groups = {}}; + else + roster[support_contact] = {subscription = "from", ask = "subscribe", name = support_contact_nick, groups = {}}; + end + rostermanager.save_roster(node, host, roster); node, host = jid_split(support_contact); - roster = rostermanager.load_roster(node, host) or {}; - roster[jid] = {subscription = "both", groups = groups}; - datamanager.store(node, host, "roster", roster); - rostermanager.roster_push(node, host, jid); + if hosts[host] then + roster = rostermanager.load_roster(node, host); + roster[jid] = {subscription = "both", groups = groups}; + rostermanager.save_roster(node, host, roster); + rostermanager.roster_push(node, host, jid); + else + core_post_stanza(hosts[event.host], st.presence({from=jid, to=support_contact, type="subscribe"})); + end end);