aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-10-19 12:08:40 +0200
committerKim Alvefur <zash@zash.se>2017-10-19 12:08:40 +0200
commit227e6843e4e38800d685a2ff792e2b5998079b00 (patch)
treec7e6a26f648927e176c5fa039613969683251723
parent07eb5f7f9885fd1f3e2d4fb5947aab2344e4acef (diff)
downloadprosody-227e6843e4e38800d685a2ff792e2b5998079b00.tar.gz
prosody-227e6843e4e38800d685a2ff792e2b5998079b00.zip
mod_storage_xep0227: Add roster storage (fixes #1023)
-rw-r--r--plugins/mod_storage_xep0227.lua73
1 files changed, 73 insertions, 0 deletions
diff --git a/plugins/mod_storage_xep0227.lua b/plugins/mod_storage_xep0227.lua
index e9ba56a2..bdc10a10 100644
--- a/plugins/mod_storage_xep0227.lua
+++ b/plugins/mod_storage_xep0227.lua
@@ -164,6 +164,79 @@ handlers.private = {
end;
};
+handlers.roster = {
+ get = function(self, user)
+ user = getUserElement(getXml(user, self.host));
+ if user then
+ local roster = user:get_child("query", "jabber:iq:roster");
+ if roster then
+ local r = {
+ [false] = {
+ version = roster.attr.version;
+ pending = {};
+ }
+ };
+ for item in roster:childtags("item") do
+ r[item.attr.jid] = {
+ jid = item.attr.jid,
+ subscription = item.attr.subscription,
+ ask = item.attr.ask,
+ name = item.attr.name,
+ groups = {};
+ };
+ for group in item:childtags("group") do
+ r[item.attr.jid].groups[group:get_text()] = true;
+ end
+ for pending in user:childtags("presence", "jabber:client") do
+ r[false].pending[pending.attr.from] = true;
+ end
+ end
+ return r;
+ end
+ end
+ end;
+ set = function(self, user, data)
+ 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:maptags(function (tag)
+ if tag.attr.xmlns == "jabber:client" and tag.name == "presence" and tag.attr.type == "subscribe" then
+ return nil;
+ end
+ return tag;
+ end);
+ if data and next(data) ~= nil then
+ roster = st.stanza("query", {xmlns='jabber:iq:roster'});
+ usere:add_child(roster);
+ for jid, item in pairs(data) do
+ if jid then
+ roster:tag("item", {
+ jid = jid,
+ subscription = item.subscription,
+ ask = item.ask,
+ name = item.name,
+ });
+ for group in pairs(item.groups) do
+ roster:tag("group"):text(group):up();
+ end
+ roster:up(); -- move out from item
+ else
+ roster.attr.version = item.version;
+ for pending_jid in pairs(item.pending) do
+ usere:add_child(st.presence({ from = pending_jid, type = "subscribe" }));
+ end
+ end
+ end
+ end
+ return setXml(user, self.host, xml);
+ end
+ return true;
+ end;
+};
+
+
-----------------------------
local driver = {};