Software /
code /
prosody-modules
Comparison
mod_groups_internal/mod_groups_internal.lua @ 5845:fe3bde6ef95a
mod_groups_internal: Sync MUC affiliations for multi-MUC groups
This was overlooked when multi-MUC support was added.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 12 Jan 2024 15:38:56 +0000 |
parent | 5844:c9279845fc41 |
child | 5847:f1e816df1f73 |
comparison
equal
deleted
inserted
replaced
5844:c9279845fc41 | 5845:fe3bde6ef95a |
---|---|
224 return nil, "group-not-found"; | 224 return nil, "group-not-found"; |
225 end | 225 end |
226 if not group_memberships:set(group_id, username, {}) then | 226 if not group_memberships:set(group_id, username, {}) then |
227 return nil, "internal-server-error"; | 227 return nil, "internal-server-error"; |
228 end | 228 end |
229 | |
229 if group_info.muc_jid then | 230 if group_info.muc_jid then |
230 local room = muc_host.get_room_from_jid(group_info.muc_jid); | 231 local room = muc_host.get_room_from_jid(group_info.muc_jid); |
231 if room then | 232 if room then |
232 local user_jid = username .. "@" .. host; | 233 local user_jid = username .. "@" .. host; |
233 room:set_affiliation(true, user_jid, "member"); | 234 room:set_affiliation(true, user_jid, "member"); |
239 }):up()); | 240 }):up()); |
240 module:log("debug", "set user %s to be member in %s and sent invite", username, group_info.muc_jid); | 241 module:log("debug", "set user %s to be member in %s and sent invite", username, group_info.muc_jid); |
241 else | 242 else |
242 module:log("warn", "failed to update affiliation for %s in %s", username, group_info.muc_jid); | 243 module:log("warn", "failed to update affiliation for %s in %s", username, group_info.muc_jid); |
243 end | 244 end |
244 end | 245 elseif group_info.mucs then |
246 local user_jid = username .. "@" .. host; | |
247 for i = #group_info.mucs, 1, -1 do | |
248 local muc_jid = group_info.mucs[i]; | |
249 local room = muc_host.get_room_from_jid(muc_jid); | |
250 if not room then | |
251 -- MUC no longer available, for some reason | |
252 -- Let's remove it from the circle metadata... | |
253 table.remove(group_info.mucs, i); | |
254 group_info_store:set_key(group_id, "mucs", group_info.mucs); | |
255 else | |
256 room:set_affiliation(true, user_jid, "member"); | |
257 module:send(st.message( | |
258 { from = muc_jid, to = user_jid } | |
259 ):tag("x", { | |
260 xmlns = "jabber:x:conference", | |
261 jid = muc_jid | |
262 }):up()); | |
263 module:log("debug", "set user %s to be member in %s and sent invite", username, muc_jid); | |
264 end | |
265 end | |
266 end | |
267 | |
245 module:fire_event( | 268 module:fire_event( |
246 "group-user-added", | 269 "group-user-added", |
247 { | 270 { |
248 id = group_id, | 271 id = group_id, |
249 user = username, | 272 user = username, |
271 local user_jid = username .. "@" .. host; | 294 local user_jid = username .. "@" .. host; |
272 room:set_affiliation(true, user_jid, nil); | 295 room:set_affiliation(true, user_jid, nil); |
273 else | 296 else |
274 module:log("warn", "failed to update affiliation for %s in %s", username, group_info.muc_jid); | 297 module:log("warn", "failed to update affiliation for %s in %s", username, group_info.muc_jid); |
275 end | 298 end |
276 end | 299 elseif group_info.mucs then |
300 local user_jid = username .. "@" .. host; | |
301 for _, muc_jid in ipairs(group_info.mucs) do | |
302 local room = muc_host.get_room_from_jid(muc_jid); | |
303 if room then | |
304 room:set_affiliation(true, user_jid, nil); | |
305 else | |
306 module:log("warn", "failed to update affiliation for %s in %s", username, muc_jid); | |
307 end | |
308 end | |
309 end | |
310 | |
277 module:fire_event( | 311 module:fire_event( |
278 "group-user-removed", | 312 "group-user-removed", |
279 { | 313 { |
280 id = group_id, | 314 id = group_id, |
281 user = username, | 315 user = username, |
298 local muc_jid, room = _create_muc_room(name); | 332 local muc_jid, room = _create_muc_room(name); |
299 if not muc_jid then return nil, room; end | 333 if not muc_jid then return nil, room; end |
300 room:save(); -- This ensures the room is committed to storage | 334 room:save(); -- This ensures the room is committed to storage |
301 | 335 |
302 table.insert(mucs, muc_jid); | 336 table.insert(mucs, muc_jid); |
337 | |
303 if group_info.muc_jid then -- COMPAT include old muc_jid into array | 338 if group_info.muc_jid then -- COMPAT include old muc_jid into array |
304 table.insert(mucs, group_info.muc_jid); | 339 table.insert(mucs, group_info.muc_jid); |
305 end | 340 end |
306 local store_ok, store_err = group_info_store:set_key(group_id, "mucs", mucs); | 341 local store_ok, store_err = group_info_store:set_key(group_id, "mucs", mucs); |
307 if not store_ok then | 342 if not store_ok then |