Comparison

mod_groups_internal/mod_groups_internal.lua @ 4389:6cfa313cd524

mod_groups_internal: manage associated MUC Manage deletion and affiliations accordingly.
author Jonas Schäfer <jonas@wielicki.name>
date Mon, 25 Jan 2021 21:51:26 +0100
parent 4388:7de3c955cfe2
child 4392:e5792ca1d704
comparison
equal deleted inserted replaced
4388:7de3c955cfe2 4389:6cfa313cd524
181 return groups; 181 return groups;
182 end 182 end
183 183
184 function delete(group_id) 184 function delete(group_id)
185 if group_members_store:set(group_id, nil) then 185 if group_members_store:set(group_id, nil) then
186 info = get_info(group_id)
187 if info and info.muc_jid then
188 muc_host.delete_room(muc_host.get_room_from_jid(info.muc_jid))
189 end
186 return group_info_store:set(group_id, nil); 190 return group_info_store:set(group_id, nil);
187 end 191 end
188 return nil, "internal-server-error"; 192 return nil, "internal-server-error";
189 end 193 end
190 194
194 return nil, "group-not-found"; 198 return nil, "group-not-found";
195 end 199 end
196 if not group_memberships:set(group_id, username, {}) then 200 if not group_memberships:set(group_id, username, {}) then
197 return nil, "internal-server-error"; 201 return nil, "internal-server-error";
198 end 202 end
203 if group_info.muc_jid then
204 local room = muc_host.get_room_from_jid(group_info.muc_jid);
205 if room then
206 local user_jid = username .. "@" .. host;
207 room:set_affiliation(true, user_jid, "member")
208 else
209 module:log("warning", "failed to update affiliation for %s in %s", username, group_info.muc_jid)
210 end
211 end
199 if not delay_update then 212 if not delay_update then
200 do_all_group_subscriptions_by_group(group_id); 213 do_all_group_subscriptions_by_group(group_id);
201 end 214 end
202 return true; 215 return true;
203 end 216 end
207 if not group_info then 220 if not group_info then
208 return nil, "group-not-found"; 221 return nil, "group-not-found";
209 end 222 end
210 if not group_memberships:set(group_id, username, nil) then 223 if not group_memberships:set(group_id, username, nil) then
211 return nil, "internal-server-error"; 224 return nil, "internal-server-error";
225 end
226 if group_info.muc_jid then
227 local room = muc_host.get_room_from_jid(group_info.muc_jid);
228 if room then
229 local user_jid = username .. "@" .. host;
230 room:set_affiliation(true, user_jid, nil)
231 else
232 module:log("warning", "failed to update affiliation for %s in %s", username, group_info.muc_jid)
233 end
212 end 234 end
213 return true; 235 return true;
214 end 236 end
215 237
216 function sync(group_id) 238 function sync(group_id)