Software /
code /
prosody-modules
Comparison
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 |
comparison
equal
deleted
inserted
replaced
99:2d03350613c4 | 100:999a4b3e699b |
---|---|
14 if not(support_contact and support_contact_nick) then return; end | 14 if not(support_contact and support_contact_nick) then return; end |
15 | 15 |
16 local rostermanager = require "core.rostermanager"; | 16 local rostermanager = require "core.rostermanager"; |
17 local datamanager = require "util.datamanager"; | 17 local datamanager = require "util.datamanager"; |
18 local jid_split = require "util.jid".split; | 18 local jid_split = require "util.jid".split; |
19 local st = require "util.stanza"; | |
19 | 20 |
20 module:hook("user-registered", function(event) | 21 module:hook("user-registered", function(event) |
21 module:log("debug", "Adding support contact"); | 22 module:log("debug", "Adding support contact"); |
22 | 23 |
23 local groups = support_contact_group and {[support_contact_group] = true;} or {}; | 24 local groups = support_contact_group and {[support_contact_group] = true;} or {}; |
24 | 25 |
25 local node, host = event.username, event.host; | 26 local node, host = event.username, event.host; |
26 local jid = node and (node..'@'..host) or host; | 27 local jid = node and (node..'@'..host) or host; |
27 local roster; | 28 local roster; |
28 | 29 |
29 roster = rostermanager.load_roster(node, host) or {}; | 30 roster = rostermanager.load_roster(node, host); |
30 roster[support_contact] = {subscription = "both", name = support_contact_nick, groups = {}}; | 31 if hosts[host] then |
31 datamanager.store(node, host, "roster", roster); | 32 roster[support_contact] = {subscription = "both", name = support_contact_nick, groups = {}}; |
33 else | |
34 roster[support_contact] = {subscription = "from", ask = "subscribe", name = support_contact_nick, groups = {}}; | |
35 end | |
36 rostermanager.save_roster(node, host, roster); | |
32 | 37 |
33 node, host = jid_split(support_contact); | 38 node, host = jid_split(support_contact); |
34 | 39 |
35 roster = rostermanager.load_roster(node, host) or {}; | 40 if hosts[host] then |
36 roster[jid] = {subscription = "both", groups = groups}; | 41 roster = rostermanager.load_roster(node, host); |
37 datamanager.store(node, host, "roster", roster); | 42 roster[jid] = {subscription = "both", groups = groups}; |
38 rostermanager.roster_push(node, host, jid); | 43 rostermanager.save_roster(node, host, roster); |
44 rostermanager.roster_push(node, host, jid); | |
45 else | |
46 core_post_stanza(hosts[event.host], st.presence({from=jid, to=support_contact, type="subscribe"})); | |
47 end | |
39 end); | 48 end); |