Mercurial > prosody-modules
annotate mod_groups_internal/mod_groups_internal.lua @ 5230:ac252db71027
mod_http_oauth2: Log flows enabled and disabled
If a developer ever wants to be sure what the state is
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 10 Mar 2023 12:01:52 +0100 |
parents | 27f7ed9f50cd |
children | 9edc698848e9 |
rev | line source |
---|---|
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local rostermanager = require"core.rostermanager"; |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
2 local modulemanager = require"core.modulemanager"; |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local id = require "util.id"; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local jid = require "util.jid"; |
4399
846b7af5588c
mod_groups_internal: send invite to new members of groups
Jonas Schäfer <jonas@wielicki.name>
parents:
4392
diff
changeset
|
5 local st = require "util.stanza"; |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local jid_join = jid.join; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local host = module.host; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local group_info_store = module:open_store("group_info"); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local group_members_store = module:open_store("groups"); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local group_memberships = module:open_store("groups", "map"); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
4392
e5792ca1d704
mod_groups_internal: fix default value and handling of groups_muc_host
Jonas Schäfer <jonas@wielicki.name>
parents:
4389
diff
changeset
|
13 local muc_host_name = module:get_option("groups_muc_host", "groups."..host); |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
14 local muc_host = nil; |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
15 |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local is_contact_subscribed = rostermanager.is_contact_subscribed; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 -- Make a *one-way* subscription. User will see when contact is online, |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 -- contact will not see when user is online. |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local function subscribe(user, user_jid, contact, contact_jid) |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 -- Update user's roster to say subscription request is pending... |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 rostermanager.set_contact_pending_out(user, host, contact_jid); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 -- Update contact's roster to say subscription request is pending... |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 rostermanager.set_contact_pending_in(contact, host, user_jid); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 -- Update contact's roster to say subscription request approved... |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 rostermanager.subscribed(contact, host, user_jid); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 -- Update user's roster to say subscription request approved... |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 rostermanager.process_inbound_subscription_approval(user, host, contact_jid); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 -- Push updates to both rosters |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 rostermanager.roster_push(user, host, contact_jid); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 rostermanager.roster_push(contact, host, user_jid); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local function user_groups(username) |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 return pairs(group_memberships:get_all(username) or {}); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 local function do_single_group_subscriptions(username, group_id) |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 local members = group_members_store:get(group_id); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 if not members then return; end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 local user_jid = jid_join(username, host); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 for membername in pairs(members) do |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 if membername ~= username then |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 local member_jid = jid_join(membername, host); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 if not is_contact_subscribed(username, host, member_jid) then |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 module:log("debug", "[group %s] Subscribing %s to %s", member_jid, user_jid); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 subscribe(membername, member_jid, username, user_jid); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 if not is_contact_subscribed(membername, host, user_jid) then |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 module:log("debug", "[group %s] Subscribing %s to %s", user_jid, member_jid); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 subscribe(username, user_jid, membername, member_jid); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 local function do_all_group_subscriptions_by_user(username) |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 for group_id in user_groups(username) do |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 do_single_group_subscriptions(username, group_id); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 local function do_all_group_subscriptions_by_group(group_id) |
4419
1185acb2ab91
mod_groups_internal: handle empty groups correctly
Jonas Schäfer <jonas@wielicki.name>
parents:
4418
diff
changeset
|
65 local members = get_members(group_id) |
1185acb2ab91
mod_groups_internal: handle empty groups correctly
Jonas Schäfer <jonas@wielicki.name>
parents:
4418
diff
changeset
|
66 if not members then |
1185acb2ab91
mod_groups_internal: handle empty groups correctly
Jonas Schäfer <jonas@wielicki.name>
parents:
4418
diff
changeset
|
67 return |
1185acb2ab91
mod_groups_internal: handle empty groups correctly
Jonas Schäfer <jonas@wielicki.name>
parents:
4418
diff
changeset
|
68 end |
1185acb2ab91
mod_groups_internal: handle empty groups correctly
Jonas Schäfer <jonas@wielicki.name>
parents:
4418
diff
changeset
|
69 for membername in pairs(members) do |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 do_single_group_subscriptions(membername, group_id); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 module:hook("resource-bind", function(event) |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 module:log("debug", "Updating group subscriptions..."); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 do_all_group_subscriptions_by_user(event.session.username); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 end); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 --luacheck: ignore 131 |
4385
dfb34cc97028
mod_groups_internal: allow specifying a group_id on create
Jonas Schäfer <jonas@wielicki.name>
parents:
4383
diff
changeset
|
80 function create(group_info, create_muc, group_id) |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 if not group_info.name then |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 return nil, "group-name-required"; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 end |
4385
dfb34cc97028
mod_groups_internal: allow specifying a group_id on create
Jonas Schäfer <jonas@wielicki.name>
parents:
4383
diff
changeset
|
84 if group_id then |
dfb34cc97028
mod_groups_internal: allow specifying a group_id on create
Jonas Schäfer <jonas@wielicki.name>
parents:
4383
diff
changeset
|
85 if exists(group_id) then |
dfb34cc97028
mod_groups_internal: allow specifying a group_id on create
Jonas Schäfer <jonas@wielicki.name>
parents:
4383
diff
changeset
|
86 return nil, "conflict" |
dfb34cc97028
mod_groups_internal: allow specifying a group_id on create
Jonas Schäfer <jonas@wielicki.name>
parents:
4383
diff
changeset
|
87 end |
dfb34cc97028
mod_groups_internal: allow specifying a group_id on create
Jonas Schäfer <jonas@wielicki.name>
parents:
4383
diff
changeset
|
88 else |
dfb34cc97028
mod_groups_internal: allow specifying a group_id on create
Jonas Schäfer <jonas@wielicki.name>
parents:
4383
diff
changeset
|
89 group_id = id.short(); |
dfb34cc97028
mod_groups_internal: allow specifying a group_id on create
Jonas Schäfer <jonas@wielicki.name>
parents:
4383
diff
changeset
|
90 end |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
92 local muc_jid = nil |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
93 local room = nil |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 if create_muc then |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
95 if not muc_host_name then |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
96 module:log("error", "cannot create group with MUC: no MUC host configured") |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
97 return nil, "service-unavailable" |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
98 end |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
99 if not muc_host then |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
100 module:log("error", "cannot create group with MUC: MUC host %s not configured properly", muc_host_name) |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
101 return nil, "internal-server-error" |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
102 end |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
103 |
4403
31470a256851
mod_groups_internal: Prep MUC JID before exposing/storing it (just in case)
Matthew Wild <mwild1@gmail.com>
parents:
4399
diff
changeset
|
104 muc_jid = jid.prep(id.short() .. "@" .. muc_host_name); |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
105 room = muc_host.create_room(muc_jid) |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
106 if not room then |
4405
76d045f76f65
mod_groups_internal: Fix incorrect function name
Matthew Wild <mwild1@gmail.com>
parents:
4404
diff
changeset
|
107 delete(group_id) |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
108 return nil, "internal-server-error" |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
109 end |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
110 room:set_public(false) |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
111 room:set_persistent(true) |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
112 room:set_members_only(true) |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
113 room:set_allow_member_invites(false) |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
114 room:set_moderated(false) |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
115 room:set_whois("anyone") |
4415
c7424b96c75e
mod_groups_internal: maintain the name of the associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4407
diff
changeset
|
116 room:set_name(group_info.name) |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 local ok = group_info_store:set(group_id, { |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 name = group_info.name; |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
121 muc_jid = muc_jid; |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 }); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 if not ok then |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
124 if room then |
4423
ca821df93cb9
mod_groups_internal: correctly destroy MUC associated with group
Jonas Schäfer <jonas@wielicki.name>
parents:
4419
diff
changeset
|
125 room:destroy() |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
126 end |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 return nil, "internal-server-error"; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 end |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
129 |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 return group_id; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 function get_info(group_id) |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 return group_info_store:get(group_id); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 function set_info(group_id, info) |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 if not info then |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 return nil, "bad-request" |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 if not info.name or #info.name == 0 then |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 return nil, "bad-request" |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 |
4415
c7424b96c75e
mod_groups_internal: maintain the name of the associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4407
diff
changeset
|
146 -- TODO: we should probably prohibit changing/removing the MUC JID of |
c7424b96c75e
mod_groups_internal: maintain the name of the associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4407
diff
changeset
|
147 -- an existing group. |
c7424b96c75e
mod_groups_internal: maintain the name of the associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4407
diff
changeset
|
148 if info.muc_jid then |
4706
428861d1d1e4
mod_groups_internal: Fix accidental global [luacheck]
Kim Alvefur <zash@zash.se>
parents:
4430
diff
changeset
|
149 local room = muc_host.get_room_from_jid(info.muc_jid); |
4415
c7424b96c75e
mod_groups_internal: maintain the name of the associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4407
diff
changeset
|
150 room:set_name(info.name); |
c7424b96c75e
mod_groups_internal: maintain the name of the associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4407
diff
changeset
|
151 end |
c7424b96c75e
mod_groups_internal: maintain the name of the associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4407
diff
changeset
|
152 |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 local ok = group_info_store:set(group_id, info); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 if not ok then |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 return nil, "internal-server-error"; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 return true |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 function get_members(group_id) |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 return group_members_store:get(group_id); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 function exists(group_id) |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 return not not get_info(group_id); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 function get_user_groups(username) |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 local groups = {}; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 do |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 local group_set = group_memberships:get_all(username); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 if group_set then |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 for group_id in pairs(group_set) do |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 table.insert(groups, group_id); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 return groups; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 function delete(group_id) |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 if group_members_store:set(group_id, nil) then |
4407
105586ca9a79
mod_groups_internal: Style
Matthew Wild <mwild1@gmail.com>
parents:
4406
diff
changeset
|
183 local group_info = get_info(group_id); |
4406
d86592775a20
mod_groups_internal: Fix unintended global variable (thanks luacheck)
Matthew Wild <mwild1@gmail.com>
parents:
4405
diff
changeset
|
184 if group_info and group_info.muc_jid then |
4423
ca821df93cb9
mod_groups_internal: correctly destroy MUC associated with group
Jonas Schäfer <jonas@wielicki.name>
parents:
4419
diff
changeset
|
185 local room = muc_host.get_room_from_jid(group_info.muc_jid) |
ca821df93cb9
mod_groups_internal: correctly destroy MUC associated with group
Jonas Schäfer <jonas@wielicki.name>
parents:
4419
diff
changeset
|
186 if room then |
ca821df93cb9
mod_groups_internal: correctly destroy MUC associated with group
Jonas Schäfer <jonas@wielicki.name>
parents:
4419
diff
changeset
|
187 room:destroy() |
ca821df93cb9
mod_groups_internal: correctly destroy MUC associated with group
Jonas Schäfer <jonas@wielicki.name>
parents:
4419
diff
changeset
|
188 end |
4389
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
189 end |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 return group_info_store:set(group_id, nil); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 return nil, "internal-server-error"; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 |
4386
6357ac65b4eb
mod_groups_internal: allow delay of roster sync on group change
Jonas Schäfer <jonas@wielicki.name>
parents:
4385
diff
changeset
|
195 function add_member(group_id, username, delay_update) |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 local group_info = group_info_store:get(group_id); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 if not group_info then |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 return nil, "group-not-found"; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 if not group_memberships:set(group_id, username, {}) then |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
201 return nil, "internal-server-error"; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 end |
4389
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
203 if group_info.muc_jid then |
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
204 local room = muc_host.get_room_from_jid(group_info.muc_jid); |
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
205 if room then |
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
206 local user_jid = username .. "@" .. host; |
4407
105586ca9a79
mod_groups_internal: Style
Matthew Wild <mwild1@gmail.com>
parents:
4406
diff
changeset
|
207 room:set_affiliation(true, user_jid, "member"); |
4399
846b7af5588c
mod_groups_internal: send invite to new members of groups
Jonas Schäfer <jonas@wielicki.name>
parents:
4392
diff
changeset
|
208 module:send(st.message( |
846b7af5588c
mod_groups_internal: send invite to new members of groups
Jonas Schäfer <jonas@wielicki.name>
parents:
4392
diff
changeset
|
209 { from = group_info.muc_jid, to = user_jid } |
846b7af5588c
mod_groups_internal: send invite to new members of groups
Jonas Schäfer <jonas@wielicki.name>
parents:
4392
diff
changeset
|
210 ):tag("x", { |
846b7af5588c
mod_groups_internal: send invite to new members of groups
Jonas Schäfer <jonas@wielicki.name>
parents:
4392
diff
changeset
|
211 xmlns = "jabber:x:conference", |
846b7af5588c
mod_groups_internal: send invite to new members of groups
Jonas Schäfer <jonas@wielicki.name>
parents:
4392
diff
changeset
|
212 jid = group_info.muc_jid |
846b7af5588c
mod_groups_internal: send invite to new members of groups
Jonas Schäfer <jonas@wielicki.name>
parents:
4392
diff
changeset
|
213 }):up()); |
4407
105586ca9a79
mod_groups_internal: Style
Matthew Wild <mwild1@gmail.com>
parents:
4406
diff
changeset
|
214 module:log("debug", "set user %s to be member in %s and sent invite", username, group_info.muc_jid); |
4389
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
215 else |
4418
8c31d4b872c3
mod_groups_internal: fix log message not appearing
Jonas Schäfer <jonas@wielicki.name>
parents:
4417
diff
changeset
|
216 module:log("warn", "failed to update affiliation for %s in %s", username, group_info.muc_jid); |
4389
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
217 end |
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
218 end |
4424
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
219 module:fire_event( |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
220 "group-user-added", |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
221 { |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
222 id = group_id, |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
223 user = username, |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
224 host = host, |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
225 group_info = group_info, |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
226 } |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
227 ) |
4386
6357ac65b4eb
mod_groups_internal: allow delay of roster sync on group change
Jonas Schäfer <jonas@wielicki.name>
parents:
4385
diff
changeset
|
228 if not delay_update then |
6357ac65b4eb
mod_groups_internal: allow delay of roster sync on group change
Jonas Schäfer <jonas@wielicki.name>
parents:
4385
diff
changeset
|
229 do_all_group_subscriptions_by_group(group_id); |
6357ac65b4eb
mod_groups_internal: allow delay of roster sync on group change
Jonas Schäfer <jonas@wielicki.name>
parents:
4385
diff
changeset
|
230 end |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 return true; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 function remove_member(group_id, username) |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 local group_info = group_info_store:get(group_id); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 if not group_info then |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 return nil, "group-not-found"; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
238 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
239 if not group_memberships:set(group_id, username, nil) then |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
240 return nil, "internal-server-error"; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
241 end |
4389
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
242 if group_info.muc_jid then |
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
243 local room = muc_host.get_room_from_jid(group_info.muc_jid); |
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
244 if room then |
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
245 local user_jid = username .. "@" .. host; |
4407
105586ca9a79
mod_groups_internal: Style
Matthew Wild <mwild1@gmail.com>
parents:
4406
diff
changeset
|
246 room:set_affiliation(true, user_jid, nil); |
4389
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
247 else |
4418
8c31d4b872c3
mod_groups_internal: fix log message not appearing
Jonas Schäfer <jonas@wielicki.name>
parents:
4417
diff
changeset
|
248 module:log("warn", "failed to update affiliation for %s in %s", username, group_info.muc_jid); |
4389
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
249 end |
6cfa313cd524
mod_groups_internal: manage associated MUC
Jonas Schäfer <jonas@wielicki.name>
parents:
4388
diff
changeset
|
250 end |
4424
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
251 module:fire_event( |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
252 "group-user-removed", |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
253 { |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
254 id = group_id, |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
255 user = username, |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
256 host = host, |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
257 group_info = group_info, |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
258 } |
679be18e6a5e
mod_groups_internal: emit events for group membership changes
Jonas Schäfer <jonas@wielicki.name>
parents:
4423
diff
changeset
|
259 ) |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
260 return true; |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
261 end |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
262 |
4386
6357ac65b4eb
mod_groups_internal: allow delay of roster sync on group change
Jonas Schäfer <jonas@wielicki.name>
parents:
4385
diff
changeset
|
263 function sync(group_id) |
4407
105586ca9a79
mod_groups_internal: Style
Matthew Wild <mwild1@gmail.com>
parents:
4406
diff
changeset
|
264 do_all_group_subscriptions_by_group(group_id); |
4386
6357ac65b4eb
mod_groups_internal: allow delay of roster sync on group change
Jonas Schäfer <jonas@wielicki.name>
parents:
4385
diff
changeset
|
265 end |
6357ac65b4eb
mod_groups_internal: allow delay of roster sync on group change
Jonas Schäfer <jonas@wielicki.name>
parents:
4385
diff
changeset
|
266 |
4430
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
267 function emit_member_events(group_id) |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
268 local group_info, err = get_info(group_id) |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
269 if group_info == nil then |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
270 return false, err |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
271 end |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
272 |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
273 for username in pairs(get_members(group_id)) do |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
274 module:fire_event( |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
275 "group-user-added", |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
276 { |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
277 id = group_id, |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
278 user = username, |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
279 host = host, |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
280 group_info = group_info, |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
281 } |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
282 ) |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
283 end |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
284 |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
285 return true |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
286 end |
71c495fa03f3
mod_groups_internal: allow force-emitting group member addition events
Jonas Schäfer <jonas@wielicki.name>
parents:
4424
diff
changeset
|
287 |
4383
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
288 -- Returns iterator over group ids |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
289 function groups() |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
290 return group_info_store:users(); |
1e7406b85add
mod_groups_internal: new module for grouping beyond mod_adhoc_groups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
291 end |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
292 |
4417
7e379ccb8ed6
mod_groups_internal: make robust against module reloads
Jonas Schäfer <jonas@wielicki.name>
parents:
4415
diff
changeset
|
293 local function setup() |
4392
e5792ca1d704
mod_groups_internal: fix default value and handling of groups_muc_host
Jonas Schäfer <jonas@wielicki.name>
parents:
4389
diff
changeset
|
294 if not muc_host_name then |
4407
105586ca9a79
mod_groups_internal: Style
Matthew Wild <mwild1@gmail.com>
parents:
4406
diff
changeset
|
295 module:log("info", "MUC management disabled (groups_muc_host set to nil)"); |
105586ca9a79
mod_groups_internal: Style
Matthew Wild <mwild1@gmail.com>
parents:
4406
diff
changeset
|
296 return; |
4392
e5792ca1d704
mod_groups_internal: fix default value and handling of groups_muc_host
Jonas Schäfer <jonas@wielicki.name>
parents:
4389
diff
changeset
|
297 end |
e5792ca1d704
mod_groups_internal: fix default value and handling of groups_muc_host
Jonas Schäfer <jonas@wielicki.name>
parents:
4389
diff
changeset
|
298 |
4407
105586ca9a79
mod_groups_internal: Style
Matthew Wild <mwild1@gmail.com>
parents:
4406
diff
changeset
|
299 local target_module = modulemanager.get_module(muc_host_name, "muc"); |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
300 if not target_module then |
4407
105586ca9a79
mod_groups_internal: Style
Matthew Wild <mwild1@gmail.com>
parents:
4406
diff
changeset
|
301 module:log("error", "host %s is not a MUC host -- group management will not work correctly; check your groups_muc_host setting!", muc_host_name); |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
302 else |
4407
105586ca9a79
mod_groups_internal: Style
Matthew Wild <mwild1@gmail.com>
parents:
4406
diff
changeset
|
303 module:log("debug", "found MUC host at %s", muc_host_name); |
4388
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
304 muc_host = target_module; |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
305 end |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
306 end |
7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
Jonas Schäfer <jonas@wielicki.name>
parents:
4386
diff
changeset
|
307 |
4707
27f7ed9f50cd
mod_groups_internal: Remove deleted user from groups
Kim Alvefur <zash@zash.se>
parents:
4706
diff
changeset
|
308 module:hook_global("user-deleted", function(event) |
27f7ed9f50cd
mod_groups_internal: Remove deleted user from groups
Kim Alvefur <zash@zash.se>
parents:
4706
diff
changeset
|
309 if event.host ~= module.host then return end |
27f7ed9f50cd
mod_groups_internal: Remove deleted user from groups
Kim Alvefur <zash@zash.se>
parents:
4706
diff
changeset
|
310 local username = event.username; |
27f7ed9f50cd
mod_groups_internal: Remove deleted user from groups
Kim Alvefur <zash@zash.se>
parents:
4706
diff
changeset
|
311 for group_id in user_groups(username) do |
27f7ed9f50cd
mod_groups_internal: Remove deleted user from groups
Kim Alvefur <zash@zash.se>
parents:
4706
diff
changeset
|
312 remove_member(group_id, username); |
27f7ed9f50cd
mod_groups_internal: Remove deleted user from groups
Kim Alvefur <zash@zash.se>
parents:
4706
diff
changeset
|
313 end |
27f7ed9f50cd
mod_groups_internal: Remove deleted user from groups
Kim Alvefur <zash@zash.se>
parents:
4706
diff
changeset
|
314 end); |
27f7ed9f50cd
mod_groups_internal: Remove deleted user from groups
Kim Alvefur <zash@zash.se>
parents:
4706
diff
changeset
|
315 |
4417
7e379ccb8ed6
mod_groups_internal: make robust against module reloads
Jonas Schäfer <jonas@wielicki.name>
parents:
4415
diff
changeset
|
316 if prosody.start_time then -- server already started |
7e379ccb8ed6
mod_groups_internal: make robust against module reloads
Jonas Schäfer <jonas@wielicki.name>
parents:
4415
diff
changeset
|
317 setup(); |
7e379ccb8ed6
mod_groups_internal: make robust against module reloads
Jonas Schäfer <jonas@wielicki.name>
parents:
4415
diff
changeset
|
318 else |
7e379ccb8ed6
mod_groups_internal: make robust against module reloads
Jonas Schäfer <jonas@wielicki.name>
parents:
4415
diff
changeset
|
319 module:hook_global("server-started", setup); |
7e379ccb8ed6
mod_groups_internal: make robust against module reloads
Jonas Schäfer <jonas@wielicki.name>
parents:
4415
diff
changeset
|
320 end |