2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 -- Copyright (C) 2011 Kim Alvefur
5 -- Copyright (C) 2018 Emmanuel Gil Peyrot
7 -- This project is MIT/X11 licensed. Please see the
8 -- COPYING file in the source package for more information.
11 local st
= require
"util.stanza"
12 local dm_load
= require
"util.datamanager".load
13 local jid_split
= require
"util.jid".split
16 local is_on_trunk
= false;
17 local mm
= require
"core.modulemanager";
18 if mm
.get_modules_for_host
then
19 if mm
.get_modules_for_host(module
.host
):contains("bookmarks") then
24 local function get_default_bookmarks(nickname
)
25 local bookmarks
= module
:get_option("default_bookmarks");
26 if not bookmarks
or #bookmarks
== 0 then
29 local reply
= st
.stanza("storage", { xmlns
= "storage:bookmarks" });
30 local nick
= nickname
and st
.stanza("nick"):text(nickname
);
31 for _
, bookmark
in ipairs(bookmarks
) do
32 if type(bookmark
) ~= "table" then -- assume it's only a jid
33 bookmark
= { jid
= bookmark
, name
= jid_split(bookmark
) };
35 reply
:tag("conference", {
41 reply
:add_child(nick
):up();
43 if bookmark
.password
then
44 reply
:tag("password"):text(bookmark
.password
):up();
52 local mod_bookmarks
= module
:depends
"bookmarks";
53 local function on_bookmarks_empty(event
)
54 local session
= event
.session
;
55 local bookmarks
= get_default_bookmarks(session
.username
);
57 mod_bookmarks
.publish_to_pep(session
.full_jid
, bookmarks
);
60 module
:hook("bookmarks/empty", on_bookmarks_empty
);
62 local function on_private_xml_get(event
)
63 local origin
, stanza
= event
.origin
, event
.stanza
;
64 local tag = stanza
.tags
[1].tags
[1];
65 local key
= tag.name
..":"..tag.attr
.xmlns
;
66 if key
~= "storage:storage:bookmarks" then
70 local data
, err
= dm_load(origin
.username
, origin
.host
, "private");
71 if data
and data
[key
] then
75 local bookmarks
= get_default_bookmarks(origin
.username
);
80 local reply
= st
.reply(stanza
):tag("query", { xmlns
= "jabber:iq:private" })
81 :add_child(bookmarks
);
85 module
:hook("iq-get/self/jabber:iq:private:query", on_private_xml_get
, 1);