Mercurial > prosody-modules
comparison mod_groups_internal/mod_groups_internal.lua @ 4388:7de3c955cfe2
mod_groups_internal: allow creating MUCs if a MUC host is linked
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Mon, 25 Jan 2021 21:47:38 +0100 |
parents | 6357ac65b4eb |
children | 6cfa313cd524 |
comparison
equal
deleted
inserted
replaced
4387:e5b4ebacbf7a | 4388:7de3c955cfe2 |
---|---|
1 local rostermanager = require"core.rostermanager"; | 1 local rostermanager = require"core.rostermanager"; |
2 local modulemanager = require"core.modulemanager"; | |
2 local id = require "util.id"; | 3 local id = require "util.id"; |
3 local jid = require "util.jid"; | 4 local jid = require "util.jid"; |
4 local jid_join = jid.join; | 5 local jid_join = jid.join; |
5 local host = module.host; | 6 local host = module.host; |
6 | 7 |
7 local group_info_store = module:open_store("group_info"); | 8 local group_info_store = module:open_store("group_info"); |
8 local group_members_store = module:open_store("groups"); | 9 local group_members_store = module:open_store("groups"); |
9 local group_memberships = module:open_store("groups", "map"); | 10 local group_memberships = module:open_store("groups", "map"); |
11 | |
12 local muc_host_name = module:get_option("groups_muc_host", "chats."..host); | |
13 local muc_host = nil; | |
10 | 14 |
11 local is_contact_subscribed = rostermanager.is_contact_subscribed; | 15 local is_contact_subscribed = rostermanager.is_contact_subscribed; |
12 | 16 |
13 -- Make a *one-way* subscription. User will see when contact is online, | 17 -- Make a *one-way* subscription. User will see when contact is online, |
14 -- contact will not see when user is online. | 18 -- contact will not see when user is online. |
94 end | 98 end |
95 else | 99 else |
96 group_id = id.short(); | 100 group_id = id.short(); |
97 end | 101 end |
98 | 102 |
103 local muc_jid = nil | |
104 local room = nil | |
99 if create_muc then | 105 if create_muc then |
100 return nil, "not-implemented"; | 106 if not muc_host_name then |
107 module:log("error", "cannot create group with MUC: no MUC host configured") | |
108 return nil, "service-unavailable" | |
109 end | |
110 if not muc_host then | |
111 module:log("error", "cannot create group with MUC: MUC host %s not configured properly", muc_host_name) | |
112 return nil, "internal-server-error" | |
113 end | |
114 | |
115 muc_jid = id.short() .. "@" .. muc_host_name | |
116 room = muc_host.create_room(muc_jid) | |
117 if not room then | |
118 delete_group(group_id) | |
119 return nil, "internal-server-error" | |
120 end | |
121 room:set_public(false) | |
122 room:set_persistent(true) | |
123 room:set_members_only(true) | |
124 room:set_allow_member_invites(false) | |
125 room:set_moderated(false) | |
126 room:set_whois("anyone") | |
101 end | 127 end |
102 | 128 |
103 local ok = group_info_store:set(group_id, { | 129 local ok = group_info_store:set(group_id, { |
104 name = group_info.name; | 130 name = group_info.name; |
131 muc_jid = muc_jid; | |
105 }); | 132 }); |
106 if not ok then | 133 if not ok then |
107 return nil, "internal-server-error"; | 134 if room then |
108 end | 135 muc_host:delete_room(room) |
136 end | |
137 return nil, "internal-server-error"; | |
138 end | |
139 | |
109 return group_id; | 140 return group_id; |
110 end | 141 end |
111 | 142 |
112 function get_info(group_id) | 143 function get_info(group_id) |
113 return group_info_store:get(group_id); | 144 return group_info_store:get(group_id); |
188 | 219 |
189 -- Returns iterator over group ids | 220 -- Returns iterator over group ids |
190 function groups() | 221 function groups() |
191 return group_info_store:users(); | 222 return group_info_store:users(); |
192 end | 223 end |
224 | |
225 local function handle_server_started() | |
226 local target_module = modulemanager.get_module(muc_host_name, "muc") | |
227 if not target_module then | |
228 module:log("error", "host %s is not a MUC host -- group management will not work correctly", muc_host_name) | |
229 else | |
230 module:log("debug", "found MUC host") | |
231 muc_host = target_module; | |
232 end | |
233 end | |
234 | |
235 module:hook_global("server-started", handle_server_started) |