Mercurial > prosody-modules
changeset 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 |
parents | 7eb23a4e7fde |
children | 232da6b1d2c1 |
files | mod_adhoc_groups/README.markdown mod_adhoc_groups/mod_adhoc_groups.lua |
diffstat | 2 files changed, 63 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_adhoc_groups/README.markdown Tue Nov 21 15:01:18 2017 +0100 @@ -0,0 +1,21 @@ +--- +labels: +... + +Introduction +============ + +This module is similar in purpouse to mod\_groups, for when you want all +users on the server to be in each others roster. + +Details +======= + +Upon login, this module will add all currently logged in users to the +logging in users roster. + +Configuration +============= + +Just add it to the modules\_enabled, after that there is no further +configuration.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_adhoc_groups/mod_adhoc_groups.lua Tue Nov 21 15:01:18 2017 +0100 @@ -0,0 +1,42 @@ +local rostermanager = require"core.rostermanager"; +local jid_join = require"util.jid".join; +local host = module.host; +local sessions = prosody.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); + + -- Push updates to both rosters + 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 user = session.username; + local user_jid = jid_join(user, host); + for contact in pairs(sessions) do + if contact ~= user then + local 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); +