comparison mod_groups_muc_bookmarks/mod_groups_muc_bookmarks.lua @ 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
parents d5ff386dc97f
children 791aa8072f58
comparison
equal deleted inserted replaced
5822:fe3bde6ef95a 5823:220502eb05aa
68 end 68 end
69 69
70 update_bookmark(jid, pep_service, room, found) 70 update_bookmark(jid, pep_service, room, found)
71 end 71 end
72 72
73 local function remove_bookmark(jid, room, autojoin, name) 73 local function remove_bookmark(jid, room)
74 local pep_service = mod_pep.get_pep_service(jid_split(jid)) 74 local pep_service = mod_pep.get_pep_service(jid_split(jid))
75 75
76 return pep_service:retract(XMLNS_BM2, jid, room, st.stanza("retract", { id = room })); 76 return pep_service:retract(XMLNS_BM2, jid, room, st.stanza("retract", { id = room }));
77 end 77 end
78 78
79 local function handle_user_added(event) 79 local function handle_user_added(event)
80 if not event.group_info.muc_jid then 80 local group_info = event.group_info;
81 module:log("debug", "ignoring user added event on group %s because it has no MUC", event.id) 81
82 return 82 local jid = event.user .. "@" .. event.host
83
84 if group_info.muc_jid then
85 inject_bookmark(jid, group_info.muc_jid, true, group_info.name);
86 elseif group_info.mucs then
87 for _, chat in ipairs(mod_groups.get_group_chats(event.id)) do
88 inject_bookmark(jid, chat.jid, true, chat.name);
89 end
90 else
91 module:log("debug", "ignoring user added event on group %s because it has no MUCs", event.id)
83 end 92 end
84 local jid = event.user .. "@" .. event.host
85 inject_bookmark(jid, event.group_info.muc_jid, true, event.group_info.name)
86 end 93 end
87 94
88 local function handle_user_removed(event) 95 local function handle_user_removed(event)
89 if not event.group_info.muc_jid then
90 module:log("debug", "ignoring user removed event on group %s because it has no MUC", event.id)
91 return
92 end
93 -- Removing the bookmark is fine as the user just lost any privilege to 96 -- Removing the bookmark is fine as the user just lost any privilege to
94 -- be in the MUC (as group MUCs are members-only). 97 -- be in the MUC (as group MUCs are members-only).
98 local group_info = event.group_info;
95 local jid = event.user .. "@" .. event.host 99 local jid = event.user .. "@" .. event.host
96 remove_bookmark(jid, event.group_info.muc_jid, true, event.group_info.name) 100
101 if group_info.muc_jid then
102 remove_bookmark(jid, event.group_info.muc_jid);
103 elseif group_info.mucs then
104 for _, muc_jid in ipairs(group_info.mucs) do
105 remove_bookmark(jid, muc_jid);
106 end
107 else
108 module:log("debug", "ignoring user removed event on group %s because it has no MUC", event.id)
109 end
97 end 110 end
98 111
99 module:hook("group-user-added", handle_user_added) 112 module:hook("group-user-added", handle_user_added)
100 module:hook("group-user-removed", handle_user_removed) 113 module:hook("group-user-removed", handle_user_removed)
101 114