Mercurial > prosody-hg
comparison plugins/mod_roster.lua @ 13950:d00409d2329f 13.0
mod_roster: Add command for cleaning out invalid contact JIDs
Complements #1903
With the new validation, any existing roster entries with invalid JIDs
can't be touched via normal means and thus can't be removed.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 25 Sep 2025 16:51:06 +0200 |
| parents | 35819bc9471a |
| children | beb5a667c20d |
comparison
equal
deleted
inserted
replaced
| 13949:863dd118f8e8 | 13950:d00409d2329f |
|---|---|
| 311 handler = function(self, jid, contact) --luacheck: ignore 212/self | 311 handler = function(self, jid, contact) --luacheck: ignore 212/self |
| 312 return unsubscribe_both(jid, contact); | 312 return unsubscribe_both(jid, contact); |
| 313 end; | 313 end; |
| 314 }); | 314 }); |
| 315 | 315 |
| 316 module:add_item("shell-command", { | |
| 317 section = "roster"; | |
| 318 section_desc = "View and manage user rosters (contact lists)"; | |
| 319 name = "clean"; | |
| 320 desc = "Remove invalid JIDs from roster"; | |
| 321 args = { | |
| 322 { name = "jid", type = "string" }; | |
| 323 }; | |
| 324 host_selector = "jid"; | |
| 325 handler = function(self, jid) -- luacheck: ignore 212/self | |
| 326 local function iter(user, host) | |
| 327 if user then return pairs({ [user] = true }); end | |
| 328 local users = require"prosody.core.usermanager".users; | |
| 329 return users(host); | |
| 330 end | |
| 331 | |
| 332 local user, host = jid_split(jid); | |
| 333 local removed = 0; | |
| 334 for user_ in iter(user, host) do | |
| 335 local roster = assert(rm_load_roster(user_, host)); | |
| 336 for contact in pairs(roster) do | |
| 337 if type(contact) == "string" then | |
| 338 if not jid_prep(contact) or jid_resource(contact) then | |
| 339 roster[contact] = nil; | |
| 340 removed = removed + 1; | |
| 341 end | |
| 342 end | |
| 343 end | |
| 344 end | |
| 345 return true, ("%d invalid roster entrie(s) removed"):format(removed); | |
| 346 end; | |
| 347 }); | |
| 348 |
