Software /
code /
prosody-modules
Annotate
mod_default_bookmarks/mod_default_bookmarks.lua @ 1056:b307b72ae527
mod_listusers: fixed banner skipping cycle
author | Vadim Misbakh-Soloviov <mva@mva.name> |
---|---|
date | Fri, 07 Jun 2013 17:54:45 +0700 |
parent | 479:597c872d691e |
child | 1324:853a382c9bd6 |
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 |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 -- |
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 |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 module:hook("iq/self/jabber:iq:private:query", function(event) |
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; |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 local typ = stanza.attr.type; |
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; |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 local query = stanza.tags[1]; |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 if #query.tags == 1 and typ == "get" then |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 local tag = query.tags[1]; |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 local key = tag.name..":"..tag.attr.xmlns; |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 if key == "storage:storage:bookmarks" then |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 local data, err = dm_load(origin.username, origin.host, "private"); |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 if not(data and data[key]) then |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 local bookmarks = module:get_option("default_bookmarks"); |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 if bookmarks and #bookmarks > 0 then |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 local reply = st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}) |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 :tag("storage", { xmlns = "storage:bookmarks" }); |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 local nick = jid_split(from); |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 for i=1,#bookmarks do |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 local bookmark = bookmarks[i]; |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 if type(bookmark) ~= "table" then -- assume it's only a jid |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 bookmark = { jid = bookmark, name = jid_split(bookmark) }; |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 end |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 reply:tag("conference", { |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 jid = bookmark.jid, |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 name = bookmark.name, |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 autojoin = "1", |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 }):tag("nick"):text(nick):up():up(); |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 end |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 origin.send(reply); |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 return true; |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 end |
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 end |
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); |