Mercurial > prosody-modules
diff mod_roster_allinall/mod_roster_allinall.lua @ 1545:a104a159697d
mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 05 Nov 2014 12:12:49 +0100 |
parents | |
children | 3ae8c81a348b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_roster_allinall/mod_roster_allinall.lua Wed Nov 05 12:12:49 2014 +0100 @@ -0,0 +1,44 @@ +local rostermanager = require"core.rostermanager"; +local jid_join = require"util.jid".join; +local jid_split = require"util.jid".split; +local host = module.host; +local sessions = hosts[host].sessions; + +-- Make a *one-way* subscription. User will see when contact is online, +-- contact will not see when user is online. +local function subscribe(user, contact) + local user_jid, contact_jid = jid_join(user, host), jid_join(contact, host); + + -- Update user's roster to say subscription request is pending... + rostermanager.set_contact_pending_out(user, host, contact_jid); + -- Update contact's roster to say subscription request is pending... + rostermanager.set_contact_pending_in(contact, host, user_jid); + -- Update contact's roster to say subscription request approved... + rostermanager.subscribed(contact, host, user_jid); + -- Update user's roster to say subscription request approved... + rostermanager.process_inbound_subscription_approval(user, host, contact_jid); + + rostermanager.roster_push(user, host, contact_jid); + rostermanager.roster_push(contact, host, user_jid); +end + + +module:hook("resource-bind", function(event) + local session = event.session; + local roster = session.roster; + local user = session.username; + local user_jid = jid_join(user, host); + local contact_jid; + for contact, contact_session in pairs(sessions) do + if contact ~= user then + contact_jid = jid_join(contact, host); + if not rostermanager.is_contact_subscribed(user, host, contact_jid) then + subscribe(contact, user); + end + if not rostermanager.is_contact_subscribed(contact, host, user_jid) then + subscribe(user, contact); + end + end + end +end); +