Software /
code /
prosody-modules
Comparison
mod_default_bookmarks/mod_default_bookmarks.lua @ 4859:33208c3ae586
mod_default_bookmarks: Add support for XEP-0402 via mod_bookmarks(2)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 08 Jan 2022 02:24:42 +0100 |
parent | 4858:727f147aac4d |
child | 4860:4a34ed2bb9a2 |
comparison
equal
deleted
inserted
replaced
4858:727f147aac4d | 4859:33208c3ae586 |
---|---|
61 mod_bookmarks.publish_to_pep(session.full_jid, bookmarks); | 61 mod_bookmarks.publish_to_pep(session.full_jid, bookmarks); |
62 end | 62 end |
63 end | 63 end |
64 module:hook("bookmarks/empty", on_bookmarks_empty); | 64 module:hook("bookmarks/empty", on_bookmarks_empty); |
65 else | 65 else |
66 module:log("error", "Method for publishing legacy bookmarks not exposed by mod_bookmarks") | 66 local mod_pep = module:depends "pep"; |
67 | |
68 local function publish_bookmarks2(event) | |
69 local session = event.session; | |
70 local publish_options = { | |
71 ["persist_items"] = true; | |
72 ["max_items"] = "max"; | |
73 ["send_last_published_item"] = "never"; | |
74 ["access_model"] = "whitelist"; | |
75 } | |
76 if not pcall(mod_pep.check_node_config, nil, nil, publish_options) then | |
77 -- 0.11 or earlier not supporting max_items="max" trows an error here | |
78 module:log("debug", "Setting max_items=pep_max_items because 'max' is not supported in this version"); | |
79 publish_options["max_items"] = module:get_option_number("pep_max_items", 256); | |
80 end | |
81 local service = mod_pep.get_pep_service(session.username); | |
82 local bookmarks = module:get_option("default_bookmarks"); | |
83 local ns = event.version or "urn:xmpp:bookmarks:1"; | |
84 for i, bookmark in ipairs(bookmarks) do | |
85 local item = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub"; id = bookmark.jid }); | |
86 item:tag("conference", { xmlns = ns; name = bookmark.name; autojoin = bookmark.autojoin and "true" or nil }); | |
87 if bookmark.nick then item:text_tag("nick", bookmarks.nick); end | |
88 if bookmark.password then item:text_tag("password", bookmarks.password); end | |
89 service:publish("urn:xmpp:bookmarks:1", session.full_jid, bookmark.jid, item, publish_options); | |
90 end | |
91 end | |
92 module:hook("bookmarks/empty", publish_bookmarks2); | |
67 end | 93 end |
68 else | 94 else |
69 local function on_private_xml_get(event) | 95 local function on_private_xml_get(event) |
70 local origin, stanza = event.origin, event.stanza; | 96 local origin, stanza = event.origin, event.stanza; |
71 local tag = stanza.tags[1].tags[1]; | 97 local tag = stanza.tags[1].tags[1]; |