Mercurial > prosody-modules
comparison mod_default_bookmarks/mod_default_bookmarks.lua @ 1325:b21236b6b8d8
Backed out changeset 853a382c9bd6
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 28 Feb 2014 15:37:55 +0100 |
parents | 853a382c9bd6 |
children | 7dbde05b48a9 |
comparison
equal
deleted
inserted
replaced
1324:853a382c9bd6 | 1325:b21236b6b8d8 |
---|---|
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 local private_bookmarks_ns = "storage:storage:bookmarks"; | 16 module:hook("iq/self/jabber:iq:private:query", function(event) |
17 | |
18 local bookmarks = module:get_option("default_bookmarks"); | |
19 | |
20 module:hook("iq-get/self/jabber:iq:private:query", function(event) | |
21 local origin, stanza = event.origin, event.stanza; | 17 local origin, stanza = event.origin, event.stanza; |
18 local typ = stanza.attr.type; | |
22 local from = stanza.attr.from; | 19 local from = stanza.attr.from; |
23 if not stanza.tags[1]:get_child("storage", "storage:bookmarks") then return end | 20 local query = stanza.tags[1]; |
24 local data, err = dm_load(origin.username, origin.host, "private"); | 21 if #query.tags == 1 and typ == "get" then |
25 if data and data[private_bookmarks_ns] then return end | 22 local tag = query.tags[1]; |
26 | 23 local key = tag.name..":"..tag.attr.xmlns; |
27 local reply = st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}) | 24 if key == "storage:storage:bookmarks" then |
28 :tag("storage", { xmlns = "storage:bookmarks" }); | 25 local data, err = dm_load(origin.username, origin.host, "private"); |
29 | 26 if not(data and data[key]) then |
30 local nick = jid_split(from); | 27 local bookmarks = module:get_option("default_bookmarks"); |
31 | 28 if bookmarks and #bookmarks > 0 then |
32 local bookmark; | 29 local reply = st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}) |
33 for i=1,#bookmarks do | 30 :tag("storage", { xmlns = "storage:bookmarks" }); |
34 bookmark = bookmarks[i]; | 31 local nick = jid_split(from); |
35 if type(bookmark) ~= "table" then -- assume it's only a jid | 32 for i=1,#bookmarks do |
36 bookmark = { jid = bookmark, name = jid_split(bookmark) }; | 33 local bookmark = bookmarks[i]; |
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 | |
37 end | 47 end |
38 reply:tag("conference", { | |
39 jid = bookmark.jid, | |
40 name = bookmark.name, | |
41 autojoin = "1", | |
42 }):tag("nick"):text(nick):up():up(); | |
43 end | 48 end |
44 origin.send(reply); | |
45 return true; | |
46 end, 1); | 49 end, 1); |