Comparison

mod_bookmarks/mod_bookmarks.lua @ 3235:bd8e94ff726b

mod_bookmarks: Expose publish_to_pep() to other modules.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 18 Aug 2018 17:25:44 +0100
parent 3234:b1e25943a004
child 3238:786ba175f2e5
comparison
equal deleted inserted replaced
3234:b1e25943a004 3235:bd8e94ff726b
40 module:log("debug", "Sending back private for %s: %s", username, content); 40 module:log("debug", "Sending back private for %s: %s", username, content);
41 session.send(st.reply(stanza):query("jabber:iq:private"):add_child(content)); 41 session.send(st.reply(stanza):query("jabber:iq:private"):add_child(content));
42 return true; 42 return true;
43 end 43 end
44 44
45 local function publish_to_pep(username, jid, bookmarks) 45 function publish_to_pep(jid, bookmarks)
46 local service = mod_pep.get_pep_service(username); 46 local service = mod_pep.get_pep_service(jid_split(jid));
47 local item = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = "current" }) 47 local item = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = "current" })
48 :add_child(bookmarks); 48 :add_child(bookmarks);
49 local options = { 49 local options = {
50 ["persist_items"] = true; 50 ["persist_items"] = true;
51 ["access_model"] = "whitelist"; 51 ["access_model"] = "whitelist";
65 if bookmarks == nil then 65 if bookmarks == nil then
66 return; 66 return;
67 end 67 end
68 68
69 module:log("debug", "Private bookmarks set by client, publishing to pep"); 69 module:log("debug", "Private bookmarks set by client, publishing to pep");
70 local ok, err = publish_to_pep(session.username, session.full_jid, bookmarks); 70 local ok, err = publish_to_pep(session.full_jid, bookmarks);
71 if not ok then 71 if not ok then
72 module:log("error", "Failed to publish to PEP bookmarks for %s: %s", session.username, err); 72 module:log("error", "Failed to publish to PEP bookmarks for %s: %s", session.username, err);
73 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP")); 73 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP"));
74 return; 74 return;
75 end 75 end
95 end 95 end
96 local bookmarks = st.deserialize(data); 96 local bookmarks = st.deserialize(data);
97 module:log("debug", "Got private bookmarks of %s: %s", username, bookmarks); 97 module:log("debug", "Got private bookmarks of %s: %s", username, bookmarks);
98 98
99 module:log("debug", "Going to store PEP item for %s", username); 99 module:log("debug", "Going to store PEP item for %s", username);
100 local ok, err = publish_to_pep(username, session.host, bookmarks); 100 local ok, err = publish_to_pep(session.full_jid, bookmarks);
101 if not ok then 101 if not ok then
102 module:log("error", "Failed to store bookmarks to PEP for %s, aborting migration: %s", username, err); 102 module:log("error", "Failed to store bookmarks to PEP for %s, aborting migration: %s", username, err);
103 return; 103 return;
104 end 104 end
105 module:log("debug", "Stored bookmarks to PEP for %s", username); 105 module:log("debug", "Stored bookmarks to PEP for %s", username);