comparison mod_default_bookmarks/mod_default_bookmarks.lua @ 1324:853a382c9bd6

mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
author Kim Alvefur <zash@zash.se>
date Fri, 28 Feb 2014 15:36:06 +0100
parents 597c872d691e
children b21236b6b8d8
comparison
equal deleted inserted replaced
1323:c84ff82658cb 1324:853a382c9bd6
11 local st = require "util.stanza" 11 local st = require "util.stanza"
12 12
13 local dm_load = require "util.datamanager".load 13 local dm_load = require "util.datamanager".load
14 local jid_split = require "util.jid".split 14 local jid_split = require "util.jid".split
15 15
16 module:hook("iq/self/jabber:iq:private:query", function(event) 16 local private_bookmarks_ns = "storage:storage:bookmarks";
17
18 local bookmarks = module:get_option("default_bookmarks");
19
20 module:hook("iq-get/self/jabber:iq:private:query", function(event)
17 local origin, stanza = event.origin, event.stanza; 21 local origin, stanza = event.origin, event.stanza;
18 local typ = stanza.attr.type;
19 local from = stanza.attr.from; 22 local from = stanza.attr.from;
20 local query = stanza.tags[1]; 23 if not stanza.tags[1]:get_child("storage", "storage:bookmarks") then return end
21 if #query.tags == 1 and typ == "get" then 24 local data, err = dm_load(origin.username, origin.host, "private");
22 local tag = query.tags[1]; 25 if data and data[private_bookmarks_ns] then return end
23 local key = tag.name..":"..tag.attr.xmlns; 26
24 if key == "storage:storage:bookmarks" then 27 local reply = st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"})
25 local data, err = dm_load(origin.username, origin.host, "private"); 28 :tag("storage", { xmlns = "storage:bookmarks" });
26 if not(data and data[key]) then 29
27 local bookmarks = module:get_option("default_bookmarks"); 30 local nick = jid_split(from);
28 if bookmarks and #bookmarks > 0 then 31
29 local reply = st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}) 32 local bookmark;
30 :tag("storage", { xmlns = "storage:bookmarks" }); 33 for i=1,#bookmarks do
31 local nick = jid_split(from); 34 bookmark = bookmarks[i];
32 for i=1,#bookmarks do 35 if type(bookmark) ~= "table" then -- assume it's only a jid
33 local bookmark = bookmarks[i]; 36 bookmark = { jid = bookmark, name = jid_split(bookmark) };
34 if type(bookmark) ~= "table" then -- assume it's only a jid
35 bookmark = { jid = bookmark, name = jid_split(bookmark) };
36 end
37 reply:tag("conference", {
38 jid = bookmark.jid,
39 name = bookmark.name,
40 autojoin = "1",
41 }):tag("nick"):text(nick):up():up();
42 end
43 origin.send(reply);
44 return true;
45 end
46 end
47 end 37 end
38 reply:tag("conference", {
39 jid = bookmark.jid,
40 name = bookmark.name,
41 autojoin = "1",
42 }):tag("nick"):text(nick):up():up();
48 end 43 end
44 origin.send(reply);
45 return true;
49 end, 1); 46 end, 1);