aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2021-12-20 15:39:26 +0000
committerMatthew Wild <mwild1@gmail.com>2021-12-20 15:39:26 +0000
commit5cb8d55857d6cf6d6aa3daeed2c83b885e323964 (patch)
tree4a2a3f318acf58433ccc3fb52e81dc5ba33d90cc /plugins
parent86617ab0085dd194a10998984b650b5e5b39bb93 (diff)
downloadprosody-5cb8d55857d6cf6d6aa3daeed2c83b885e323964.tar.gz
prosody-5cb8d55857d6cf6d6aa3daeed2c83b885e323964.zip
mod_storage_xep0227: Replace custom tag-removal helpers with :remove_children()
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_storage_xep0227.lua36
1 files changed, 9 insertions, 27 deletions
diff --git a/plugins/mod_storage_xep0227.lua b/plugins/mod_storage_xep0227.lua
index f5fc01f5..aaa7ec9b 100644
--- a/plugins/mod_storage_xep0227.lua
+++ b/plugins/mod_storage_xep0227.lua
@@ -3,7 +3,6 @@ local ipairs, pairs = ipairs, pairs;
local setmetatable = setmetatable;
local tostring = tostring;
local next, unpack = next, table.unpack or unpack; --luacheck: ignore 113/unpack
-local t_remove = table.remove;
local os_remove = os.remove;
local io_open = io.open;
local jid_bare = require "util.jid".bare;
@@ -66,18 +65,6 @@ local function createOuterXml(user, host)
:tag("host", {jid=host})
:tag("user", {name = user});
end
-local function removeFromArray(arr, value)
- for i,item in ipairs(arr) do
- if item == value then
- t_remove(arr, i);
- return;
- end
- end
-end
-local function removeStanzaChild(s, child)
- removeFromArray(s.tags, child);
- removeFromArray(s, child);
-end
local function hex_to_base64(s)
return base64.encode(hex.from(s));
@@ -171,16 +158,13 @@ handlers.vcard = {
local xml = getXml(user, self.host);
local usere = xml and getUserElement(xml);
if usere then
- local vcard = usere:get_child("vCard", 'vcard-temp');
- if vcard then
- removeStanzaChild(usere, vcard);
- elseif not data then
+ usere:remove_children("vCard", "vcard-temp");
+ if not data then
+ -- No data to set, old one deleted, success
return true;
end
- if data then
- vcard = st.deserialize(data);
- usere:add_child(vcard);
- end
+ local vcard = st.deserialize(data);
+ usere:add_child(vcard);
return setXml(user, self.host, xml);
end
return true;
@@ -204,10 +188,9 @@ handlers.private = {
local xml = getXml(user, self.host);
local usere = xml and getUserElement(xml);
if usere then
- local private = usere:get_child("query", 'jabber:iq:private');
- if private then removeStanzaChild(usere, private); end
+ usere:remove_children("query", "jabber:iq:private");
if data and next(data) ~= nil then
- private = st.stanza("query", {xmlns='jabber:iq:private'});
+ local private = st.stanza("query", {xmlns='jabber:iq:private'});
for _,tag in pairs(data) do
private:add_child(st.deserialize(tag));
end
@@ -254,8 +237,7 @@ handlers.roster = {
local xml = getXml(user, self.host);
local usere = xml and getUserElement(xml);
if usere then
- local roster = usere:get_child("query", 'jabber:iq:roster');
- if roster then removeStanzaChild(usere, roster); end
+ usere:remove_children("query", "jabber:iq:roster");
usere:maptags(function (tag)
if tag.attr.xmlns == "jabber:client" and tag.name == "presence" and tag.attr.type == "subscribe" then
return nil;
@@ -263,7 +245,7 @@ handlers.roster = {
return tag;
end);
if data and next(data) ~= nil then
- roster = st.stanza("query", {xmlns='jabber:iq:roster'});
+ local roster = st.stanza("query", {xmlns='jabber:iq:roster'});
usere:add_child(roster);
for jid, item in pairs(data) do
if jid then