|
1 local rostermanager = require"core.rostermanager"; |
|
2 local jid_join = require"util.jid".join; |
|
3 local jid_split = require"util.jid".split; |
|
4 local host = module.host; |
|
5 local sessions = hosts[host].sessions; |
|
6 |
|
7 -- Make a *one-way* subscription. User will see when contact is online, |
|
8 -- contact will not see when user is online. |
|
9 local function subscribe(user, contact) |
|
10 local user_jid, contact_jid = jid_join(user, host), jid_join(contact, host); |
|
11 |
|
12 -- Update user's roster to say subscription request is pending... |
|
13 rostermanager.set_contact_pending_out(user, host, contact_jid); |
|
14 -- Update contact's roster to say subscription request is pending... |
|
15 rostermanager.set_contact_pending_in(contact, host, user_jid); |
|
16 -- Update contact's roster to say subscription request approved... |
|
17 rostermanager.subscribed(contact, host, user_jid); |
|
18 -- Update user's roster to say subscription request approved... |
|
19 rostermanager.process_inbound_subscription_approval(user, host, contact_jid); |
|
20 |
|
21 rostermanager.roster_push(user, host, contact_jid); |
|
22 rostermanager.roster_push(contact, host, user_jid); |
|
23 end |
|
24 |
|
25 |
|
26 module:hook("resource-bind", function(event) |
|
27 local session = event.session; |
|
28 local roster = session.roster; |
|
29 local user = session.username; |
|
30 local user_jid = jid_join(user, host); |
|
31 local contact_jid; |
|
32 for contact, contact_session in pairs(sessions) do |
|
33 if contact ~= user then |
|
34 contact_jid = jid_join(contact, host); |
|
35 if not rostermanager.is_contact_subscribed(user, host, contact_jid) then |
|
36 subscribe(contact, user); |
|
37 end |
|
38 if not rostermanager.is_contact_subscribed(contact, host, user_jid) then |
|
39 subscribe(user, contact); |
|
40 end |
|
41 end |
|
42 end |
|
43 end); |
|
44 |