Comparison

mod_adhoc_groups/mod_adhoc_groups.lua @ 2847:907a15c9d621

mod_adhoc_groups: Copy from mod_roster_allinall
author Kim Alvefur <zash@zash.se>
date Tue, 21 Nov 2017 15:01:18 +0100
parent 1798:mod_roster_allinall/mod_roster_allinall.lua@3ae8c81a348b
child 2848:232da6b1d2c1
comparison
equal deleted inserted replaced
2846:7eb23a4e7fde 2847:907a15c9d621
1 local rostermanager = require"core.rostermanager";
2 local jid_join = require"util.jid".join;
3 local host = module.host;
4 local sessions = prosody.hosts[host].sessions;
5
6 -- Make a *one-way* subscription. User will see when contact is online,
7 -- contact will not see when user is online.
8 local function subscribe(user, contact)
9 local user_jid, contact_jid = jid_join(user, host), jid_join(contact, host);
10
11 -- Update user's roster to say subscription request is pending...
12 rostermanager.set_contact_pending_out(user, host, contact_jid);
13 -- Update contact's roster to say subscription request is pending...
14 rostermanager.set_contact_pending_in(contact, host, user_jid);
15 -- Update contact's roster to say subscription request approved...
16 rostermanager.subscribed(contact, host, user_jid);
17 -- Update user's roster to say subscription request approved...
18 rostermanager.process_inbound_subscription_approval(user, host, contact_jid);
19
20 -- Push updates to both rosters
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 user = session.username;
29 local user_jid = jid_join(user, host);
30 for contact in pairs(sessions) do
31 if contact ~= user then
32 local contact_jid = jid_join(contact, host);
33 if not rostermanager.is_contact_subscribed(user, host, contact_jid) then
34 subscribe(contact, user);
35 end
36 if not rostermanager.is_contact_subscribed(contact, host, user_jid) then
37 subscribe(user, contact);
38 end
39 end
40 end
41 end);
42