Comparison

mod_groups_internal/mod_groups_internal.lua @ 4407:105586ca9a79

mod_groups_internal: Style
author Matthew Wild <mwild1@gmail.com>
date Wed, 27 Jan 2021 15:14:47 +0000
parent 4406:d86592775a20
child 4415:c7424b96c75e
comparison
equal deleted inserted replaced
4406:d86592775a20 4407:105586ca9a79
166 return groups; 166 return groups;
167 end 167 end
168 168
169 function delete(group_id) 169 function delete(group_id)
170 if group_members_store:set(group_id, nil) then 170 if group_members_store:set(group_id, nil) then
171 local group_info = get_info(group_id) 171 local group_info = get_info(group_id);
172 if group_info and group_info.muc_jid then 172 if group_info and group_info.muc_jid then
173 muc_host.delete_room(muc_host.get_room_from_jid(group_info.muc_jid)) 173 muc_host.delete_room(muc_host.get_room_from_jid(group_info.muc_jid));
174 end 174 end
175 return group_info_store:set(group_id, nil); 175 return group_info_store:set(group_id, nil);
176 end 176 end
177 return nil, "internal-server-error"; 177 return nil, "internal-server-error";
178 end 178 end
187 end 187 end
188 if group_info.muc_jid then 188 if group_info.muc_jid then
189 local room = muc_host.get_room_from_jid(group_info.muc_jid); 189 local room = muc_host.get_room_from_jid(group_info.muc_jid);
190 if room then 190 if room then
191 local user_jid = username .. "@" .. host; 191 local user_jid = username .. "@" .. host;
192 room:set_affiliation(true, user_jid, "member") 192 room:set_affiliation(true, user_jid, "member");
193 module:send(st.message( 193 module:send(st.message(
194 { from = group_info.muc_jid, to = user_jid } 194 { from = group_info.muc_jid, to = user_jid }
195 ):tag("x", { 195 ):tag("x", {
196 xmlns = "jabber:x:conference", 196 xmlns = "jabber:x:conference",
197 jid = group_info.muc_jid 197 jid = group_info.muc_jid
198 }):up()); 198 }):up());
199 module:log("debug", "set user %s to be member in %s and sent invite", username, group_info.muc_jid) 199 module:log("debug", "set user %s to be member in %s and sent invite", username, group_info.muc_jid);
200 else 200 else
201 module:log("warning", "failed to update affiliation for %s in %s", username, group_info.muc_jid) 201 module:log("warning", "failed to update affiliation for %s in %s", username, group_info.muc_jid);
202 end 202 end
203 end 203 end
204 if not delay_update then 204 if not delay_update then
205 do_all_group_subscriptions_by_group(group_id); 205 do_all_group_subscriptions_by_group(group_id);
206 end 206 end
217 end 217 end
218 if group_info.muc_jid then 218 if group_info.muc_jid then
219 local room = muc_host.get_room_from_jid(group_info.muc_jid); 219 local room = muc_host.get_room_from_jid(group_info.muc_jid);
220 if room then 220 if room then
221 local user_jid = username .. "@" .. host; 221 local user_jid = username .. "@" .. host;
222 room:set_affiliation(true, user_jid, nil) 222 room:set_affiliation(true, user_jid, nil);
223 else 223 else
224 module:log("warning", "failed to update affiliation for %s in %s", username, group_info.muc_jid) 224 module:log("warning", "failed to update affiliation for %s in %s", username, group_info.muc_jid);
225 end 225 end
226 end 226 end
227 return true; 227 return true;
228 end 228 end
229 229
230 function sync(group_id) 230 function sync(group_id)
231 do_all_group_subscriptions_by_group(group_id) 231 do_all_group_subscriptions_by_group(group_id);
232 end 232 end
233 233
234 -- Returns iterator over group ids 234 -- Returns iterator over group ids
235 function groups() 235 function groups()
236 return group_info_store:users(); 236 return group_info_store:users();
237 end 237 end
238 238
239 local function handle_server_started() 239 local function handle_server_started()
240 if not muc_host_name then 240 if not muc_host_name then
241 module:log("info", "MUC management disabled (groups_muc_host set to nil)") 241 module:log("info", "MUC management disabled (groups_muc_host set to nil)");
242 return 242 return;
243 end 243 end
244 244
245 local target_module = modulemanager.get_module(muc_host_name, "muc") 245 local target_module = modulemanager.get_module(muc_host_name, "muc");
246 if not target_module then 246 if not target_module then
247 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) 247 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);
248 else 248 else
249 module:log("debug", "found MUC host at %s", muc_host_name) 249 module:log("debug", "found MUC host at %s", muc_host_name);
250 muc_host = target_module; 250 muc_host = target_module;
251 end 251 end
252 end 252 end
253 253
254 module:hook_global("server-started", handle_server_started) 254 module:hook_global("server-started", handle_server_started);