# HG changeset patch # User Jonas Schäfer # Date 1611607886 -3600 # Node ID 6cfa313cd524c0dbf57150326edfd76798db26fe # Parent 7de3c955cfe26fb76b4825bf6c2069589bbfc206 mod_groups_internal: manage associated MUC Manage deletion and affiliations accordingly. diff -r 7de3c955cfe2 -r 6cfa313cd524 mod_groups_internal/mod_groups_internal.lua --- a/mod_groups_internal/mod_groups_internal.lua Mon Jan 25 21:47:38 2021 +0100 +++ b/mod_groups_internal/mod_groups_internal.lua Mon Jan 25 21:51:26 2021 +0100 @@ -183,6 +183,10 @@ function delete(group_id) if group_members_store:set(group_id, nil) then + info = get_info(group_id) + if info and info.muc_jid then + muc_host.delete_room(muc_host.get_room_from_jid(info.muc_jid)) + end return group_info_store:set(group_id, nil); end return nil, "internal-server-error"; @@ -196,6 +200,15 @@ if not group_memberships:set(group_id, username, {}) then return nil, "internal-server-error"; end + if group_info.muc_jid then + local room = muc_host.get_room_from_jid(group_info.muc_jid); + if room then + local user_jid = username .. "@" .. host; + room:set_affiliation(true, user_jid, "member") + else + module:log("warning", "failed to update affiliation for %s in %s", username, group_info.muc_jid) + end + end if not delay_update then do_all_group_subscriptions_by_group(group_id); end @@ -210,6 +223,15 @@ if not group_memberships:set(group_id, username, nil) then return nil, "internal-server-error"; end + if group_info.muc_jid then + local room = muc_host.get_room_from_jid(group_info.muc_jid); + if room then + local user_jid = username .. "@" .. host; + room:set_affiliation(true, user_jid, nil) + else + module:log("warning", "failed to update affiliation for %s in %s", username, group_info.muc_jid) + end + end return true; end