Changeset

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
parents 4388:7de3c955cfe2
children 4390:17d44ba8fde2
files mod_groups_internal/mod_groups_internal.lua
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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