Software / code / prosody-modules
Comparison
mod_groups_internal/mod_groups_internal.lua @ 5823:8566a423da88
mod_groups_internal: Set group names as roster groups
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 23 Dec 2023 17:27:35 +0100 |
| parent | 5818:5533c577dd02 |
| child | 5843:742142f9771e |
comparison
equal
deleted
inserted
replaced
| 5822:c75328aeaba3 | 5823:8566a423da88 |
|---|---|
| 16 | 16 |
| 17 local is_contact_subscribed = rostermanager.is_contact_subscribed; | 17 local is_contact_subscribed = rostermanager.is_contact_subscribed; |
| 18 | 18 |
| 19 -- Make a *one-way* subscription. User will see when contact is online, | 19 -- Make a *one-way* subscription. User will see when contact is online, |
| 20 -- contact will not see when user is online. | 20 -- contact will not see when user is online. |
| 21 local function subscribe(user, user_jid, contact, contact_jid) | 21 local function subscribe(user, user_jid, contact, contact_jid, group_name) |
| 22 -- Update user's roster to say subscription request is pending... | 22 -- Update user's roster to say subscription request is pending... |
| 23 rostermanager.set_contact_pending_out(user, host, contact_jid); | 23 rostermanager.set_contact_pending_out(user, host, contact_jid); |
| 24 -- Update contact's roster to say subscription request is pending... | 24 -- Update contact's roster to say subscription request is pending... |
| 25 rostermanager.set_contact_pending_in(contact, host, user_jid); | 25 rostermanager.set_contact_pending_in(contact, host, user_jid); |
| 26 -- Update contact's roster to say subscription request approved... | 26 -- Update contact's roster to say subscription request approved... |
| 27 rostermanager.subscribed(contact, host, user_jid); | 27 rostermanager.subscribed(contact, host, user_jid); |
| 28 -- Update user's roster to say subscription request approved... | 28 -- Update user's roster to say subscription request approved... |
| 29 rostermanager.process_inbound_subscription_approval(user, host, contact_jid); | 29 rostermanager.process_inbound_subscription_approval(user, host, contact_jid); |
| 30 | 30 |
| 31 if group_name then | |
| 32 local user_roster = rostermanager.load_roster(user, host); | |
| 33 user_roster[contact_jid].groups[group_name] = true; | |
| 34 end | |
| 35 | |
| 31 -- Push updates to both rosters | 36 -- Push updates to both rosters |
| 32 rostermanager.roster_push(user, host, contact_jid); | 37 rostermanager.roster_push(user, host, contact_jid); |
| 33 rostermanager.roster_push(contact, host, user_jid); | 38 rostermanager.roster_push(contact, host, user_jid); |
| 34 end | 39 end |
| 35 | 40 |
| 38 end | 43 end |
| 39 | 44 |
| 40 local function do_single_group_subscriptions(username, group_id) | 45 local function do_single_group_subscriptions(username, group_id) |
| 41 local members = group_members_store:get(group_id); | 46 local members = group_members_store:get(group_id); |
| 42 if not members then return; end | 47 if not members then return; end |
| 48 local group_name = group_info_store:get_key(group_id, "name"); | |
| 43 local user_jid = jid_join(username, host); | 49 local user_jid = jid_join(username, host); |
| 44 for membername in pairs(members) do | 50 for membername in pairs(members) do |
| 45 if membername ~= username then | 51 if membername ~= username then |
| 46 local member_jid = jid_join(membername, host); | 52 local member_jid = jid_join(membername, host); |
| 47 if not is_contact_subscribed(username, host, member_jid) then | 53 if not is_contact_subscribed(username, host, member_jid) then |
| 48 module:log("debug", "[group %s] Subscribing %s to %s", member_jid, user_jid); | 54 module:log("debug", "[group %s] Subscribing %s to %s", member_jid, user_jid); |
| 49 subscribe(membername, member_jid, username, user_jid); | 55 subscribe(membername, member_jid, username, user_jid, group_name); |
| 50 end | 56 end |
| 51 if not is_contact_subscribed(membername, host, user_jid) then | 57 if not is_contact_subscribed(membername, host, user_jid) then |
| 52 module:log("debug", "[group %s] Subscribing %s to %s", user_jid, member_jid); | 58 module:log("debug", "[group %s] Subscribing %s to %s", user_jid, member_jid); |
| 53 subscribe(username, user_jid, membername, member_jid); | 59 subscribe(username, user_jid, membername, member_jid, group_name); |
| 54 end | 60 end |
| 55 end | 61 end |
| 56 end | 62 end |
| 57 end | 63 end |
| 58 | 64 |