annotate mod_default_bookmarks/mod_default_bookmarks.lua @ 1452:097c6af98d0a

Merge
author Kim Alvefur <zash@zash.se>
date Wed, 25 Jun 2014 20:46:35 +0200
parents 7dbde05b48a9
children 73906187f964
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
479
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- Prosody IM
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 -- Copyright (C) 2011 Kim Alvefur
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 1325
diff changeset
5 --
479
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 -- This project is MIT/X11 licensed. Please see the
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 -- COPYING file in the source package for more information.
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 --
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local st = require "util.stanza"
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 local dm_load = require "util.datamanager".load
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 local jid_split = require "util.jid".split
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15
1325
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
16 module:hook("iq/self/jabber:iq:private:query", function(event)
479
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 local origin, stanza = event.origin, event.stanza;
1325
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
18 local typ = stanza.attr.type;
479
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 local from = stanza.attr.from;
1325
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
20 local query = stanza.tags[1];
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
21 if #query.tags == 1 and typ == "get" then
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
22 local tag = query.tags[1];
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
23 local key = tag.name..":"..tag.attr.xmlns;
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
24 if key == "storage:storage:bookmarks" then
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
25 local data, err = dm_load(origin.username, origin.host, "private");
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
26 if not(data and data[key]) then
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
27 local bookmarks = module:get_option("default_bookmarks");
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
28 if bookmarks and #bookmarks > 0 then
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
29 local reply = st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"})
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
30 :tag("storage", { xmlns = "storage:bookmarks" });
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
31 local nick = jid_split(from);
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
32 for i=1,#bookmarks do
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
33 local bookmark = bookmarks[i];
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
34 if type(bookmark) ~= "table" then -- assume it's only a jid
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
35 bookmark = { jid = bookmark, name = jid_split(bookmark) };
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
36 end
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
37 reply:tag("conference", {
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
38 jid = bookmark.jid,
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
39 name = bookmark.name,
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
40 autojoin = "1",
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
41 }):tag("nick"):text(nick):up():up();
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
42 end
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
43 origin.send(reply);
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
44 return true;
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
45 end
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
46 end
479
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 end
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 end
597c872d691e mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 end, 1);