changeset 5823:220502eb05aa

mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group This was overlooked when multi-MUC support was first implemented.
author Matthew Wild <mwild1@gmail.com>
date Fri, 12 Jan 2024 15:40:23 +0000 (11 months ago)
parents fe3bde6ef95a
children f1e816df1f73
files mod_groups_muc_bookmarks/mod_groups_muc_bookmarks.lua
diffstat 1 files changed, 24 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mod_groups_muc_bookmarks/mod_groups_muc_bookmarks.lua	Fri Jan 12 15:38:56 2024 +0000
+++ b/mod_groups_muc_bookmarks/mod_groups_muc_bookmarks.lua	Fri Jan 12 15:40:23 2024 +0000
@@ -70,30 +70,43 @@
 	update_bookmark(jid, pep_service, room, found)
 end
 
-local function remove_bookmark(jid, room, autojoin, name)
+local function remove_bookmark(jid, room)
 	local pep_service = mod_pep.get_pep_service(jid_split(jid))
 
 	return pep_service:retract(XMLNS_BM2, jid, room, st.stanza("retract", { id = room }));
 end
 
 local function handle_user_added(event)
-	if not event.group_info.muc_jid then
-		module:log("debug", "ignoring user added event on group %s because it has no MUC", event.id)
-		return
+	local group_info = event.group_info;
+
+	local jid = event.user .. "@" .. event.host
+
+	if group_info.muc_jid then
+		inject_bookmark(jid, group_info.muc_jid, true, group_info.name);
+	elseif group_info.mucs then
+		for _, chat in ipairs(mod_groups.get_group_chats(event.id)) do
+			inject_bookmark(jid, chat.jid, true, chat.name);
+		end
+	else
+		module:log("debug", "ignoring user added event on group %s because it has no MUCs", event.id)
 	end
-	local jid = event.user .. "@" .. event.host
-	inject_bookmark(jid, event.group_info.muc_jid, true, event.group_info.name)
 end
 
 local function handle_user_removed(event)
-	if not event.group_info.muc_jid then
-		module:log("debug", "ignoring user removed event on group %s because it has no MUC", event.id)
-		return
-	end
 	-- Removing the bookmark is fine as the user just lost any privilege to
 	-- be in the MUC (as group MUCs are members-only).
+	local group_info = event.group_info;
 	local jid = event.user .. "@" .. event.host
-	remove_bookmark(jid, event.group_info.muc_jid, true, event.group_info.name)
+
+	if group_info.muc_jid then
+		remove_bookmark(jid, event.group_info.muc_jid);
+	elseif group_info.mucs then
+		for _, muc_jid in ipairs(group_info.mucs) do
+			remove_bookmark(jid, muc_jid);
+		end
+	else
+		module:log("debug", "ignoring user removed event on group %s because it has no MUC", event.id)
+	end
 end
 
 module:hook("group-user-added", handle_user_added)