40 end |
40 end |
41 end |
41 end |
42 return data; |
42 return data; |
43 end |
43 end |
44 |
44 |
45 module:hook("iq/self/jabber:iq:private:query", function(event) |
45 module:hook("iq-get/self/jabber:iq:private:query", function(event) |
46 local origin, stanza = event.origin, event.stanza; |
46 local origin, stanza = event.origin, event.stanza; |
47 local type = stanza.attr.type; |
|
48 local query = stanza.tags[1]; |
47 local query = stanza.tags[1]; |
49 if #query.tags == 1 then |
48 if #query.tags == 1 then |
50 local tag = query.tags[1]; |
49 local tag = query.tags[1]; |
51 local key = tag.name..":"..tag.attr.xmlns; |
50 local key = tag.name..":"..tag.attr.xmlns; |
52 local data, err = dm_load(origin.username, origin.host, "private"); |
51 local data, err = dm_load(origin.username, origin.host, "private"); |
53 if err then |
52 if err then |
54 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); |
53 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); |
55 return true; |
54 return true; |
56 end |
55 end |
57 if stanza.attr.type == "get" then |
56 local data = data and data[key]; |
58 local data = data and data[key]; |
57 if (not data) and key == "storage:storage:bookmarks" then |
59 if (not data) and key == "storage:storage:bookmarks" then |
58 data = st.stanza("storage", { xmlns = "storage:bookmarks" }); |
60 data = st.stanza("storage", { xmlns = "storage:bookmarks" }); |
59 end |
|
60 if data then |
|
61 data = st.deserialize(data); |
|
62 if key == "storage:storage:bookmarks" then |
|
63 data = inject_bookmarks(origin.username, origin.host, data); |
61 end |
64 end |
62 if data then |
65 origin.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}) |
63 data = st.deserialize(data); |
66 :add_child(data)); |
64 if key == "storage:storage:bookmarks" then |
67 else |
65 data = inject_bookmarks(origin.username, origin.host, data); |
68 origin.send(st.reply(stanza):add_child(stanza.tags[1])); |
66 end |
|
67 origin.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}) |
|
68 :add_child(data)); |
|
69 else |
|
70 origin.send(st.reply(stanza):add_child(stanza.tags[1])); |
|
71 end |
|
72 return true; |
|
73 end |
69 end |
|
70 return true; |
74 end |
71 end |
75 end, 1); |
72 end, 1); |
76 |
73 |
77 function module.load() |
74 function module.load() |
78 bookmarks_file = module:get_option_string("group_bookmarks_file"); |
75 bookmarks_file = module:get_option_string("group_bookmarks_file"); |