Mercurial > prosody-modules
annotate 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 |
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 |
1324
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
16 local private_bookmarks_ns = "storage:storage:bookmarks"; |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
17 |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
18 local bookmarks = module:get_option("default_bookmarks"); |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
19 |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
20 module:hook("iq-get/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
|
21 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
|
22 local from = stanza.attr.from; |
1324
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
23 if not stanza.tags[1]:get_child("storage", "storage:bookmarks") then return end |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
24 local data, err = dm_load(origin.username, origin.host, "private"); |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
25 if data and data[private_bookmarks_ns] then return end |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
26 |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
27 local reply = st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}) |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
28 :tag("storage", { xmlns = "storage:bookmarks" }); |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
29 |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
30 local nick = jid_split(from); |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
31 |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
32 local bookmark; |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
33 for i=1,#bookmarks do |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
34 bookmark = bookmarks[i]; |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
35 if type(bookmark) ~= "table" then -- assume it's only a jid |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
36 bookmark = { jid = bookmark, name = jid_split(bookmark) }; |
479
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 end |
1324
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
38 reply:tag("conference", { |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
39 jid = bookmark.jid, |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
40 name = bookmark.name, |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
41 autojoin = "1", |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
42 }):tag("nick"):text(nick):up():up(); |
479
597c872d691e
mod_default_bookmarks: Serve a list of default bookmarks if the user has nil.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 end |
1324
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
44 origin.send(reply); |
853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents:
479
diff
changeset
|
45 return true; |
479
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, 1); |