Mercurial > prosody-modules
comparison mod_mam_archive/mod_mam_archive.lua @ 1498:e82592ed744b
mod_mam_archive: Applying @vstakhov 's patch (https://gist.github.com/vstakhov/306ea813a38021dcf3d4).
Fixing SQLite-related bugs, to-from bugs, rst compatibility, etc. Thanks Vsevolod!
author | syn@syn.im |
---|---|
date | Sun, 31 Aug 2014 20:13:54 +0200 |
parents | db870913e1cf |
children | 71af9c272d72 |
comparison
equal
deleted
inserted
replaced
1497:d1836dfa4ae4 | 1498:e82592ed744b |
---|---|
7 local set_prefs = module:require"mod_mam/mamprefs".set; | 7 local set_prefs = module:require"mod_mam/mamprefs".set; |
8 local rsm = module:require "mod_mam/rsm"; | 8 local rsm = module:require "mod_mam/rsm"; |
9 local jid_bare = require "util.jid".bare; | 9 local jid_bare = require "util.jid".bare; |
10 local jid_prep = require "util.jid".prep; | 10 local jid_prep = require "util.jid".prep; |
11 local date_parse = require "util.datetime".parse; | 11 local date_parse = require "util.datetime".parse; |
12 local date_format = require "util.datetime".datetime; | |
12 | 13 |
13 local st = require "util.stanza"; | 14 local st = require "util.stanza"; |
14 local archive_store = "archive2"; | 15 local archive_store = "archive2"; |
15 local archive = module:open_store(archive_store, "archive"); | 16 local archive = module:open_store(archive_store, "archive"); |
16 local global_default_policy = module:get_option("default_archive_policy", false); | 17 local global_default_policy = module:get_option("default_archive_policy", false); |
17 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); | 18 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); |
18 local conversation_interval = tonumber(module:get_option_number("archive_conversation_interval", 86400)); | 19 local conversation_interval = tonumber(module:get_option_number("archive_conversation_interval", 86400)); |
20 local resolve_relative_path = require "core.configmanager".resolve_relative_path; | |
19 | 21 |
20 -- Feature discovery | 22 -- Feature discovery |
21 local xmlns_archive = "urn:xmpp:archive" | 23 local xmlns_archive = "urn:xmpp:archive" |
22 local feature_archive = st.stanza("feature", {xmlns=xmlns_archive}):tag("optional"); | 24 local feature_archive = st.stanza("feature", {xmlns=xmlns_archive}):tag("optional"); |
23 if(global_default_policy) then | 25 if(global_default_policy) then |
27 module:add_feature("urn:xmpp:archive:auto"); | 29 module:add_feature("urn:xmpp:archive:auto"); |
28 module:add_feature("urn:xmpp:archive:manage"); | 30 module:add_feature("urn:xmpp:archive:manage"); |
29 module:add_feature("urn:xmpp:archive:pref"); | 31 module:add_feature("urn:xmpp:archive:pref"); |
30 module:add_feature("http://jabber.org/protocol/rsm"); | 32 module:add_feature("http://jabber.org/protocol/rsm"); |
31 -- -------------------------------------------------- | 33 -- -------------------------------------------------- |
32 | |
33 local function date_format(s) | |
34 return os.date("%Y-%m-%dT%H:%M:%SZ", s); | |
35 end | |
36 | 34 |
37 local function prefs_to_stanza(prefs) | 35 local function prefs_to_stanza(prefs) |
38 local prefstanza = st.stanza("pref", { xmlns="urn:xmpp:archive" }); | 36 local prefstanza = st.stanza("pref", { xmlns="urn:xmpp:archive" }); |
39 local default = prefs[false] ~= nil and prefs[false] or global_default_policy; | 37 local default = prefs[false] ~= nil and prefs[false] or global_default_policy; |
40 | 38 |
263 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); | 261 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); |
264 end | 262 end |
265 local count = err; | 263 local count = err; |
266 | 264 |
267 local chat = reply:tag("chat", {xmlns=xmlns_archive, with=qwith, start=date_format(qstart), version=count}); | 265 local chat = reply:tag("chat", {xmlns=xmlns_archive, with=qwith, start=date_format(qstart), version=count}); |
266 local first, last; | |
268 | 267 |
269 module:log("debug", "Count "..count); | 268 module:log("debug", "Count "..count); |
270 for id, item, when in data do | 269 for id, item, when in data do |
271 if not getmetatable(item) == st.stanza_mt then | 270 if not getmetatable(item) == st.stanza_mt then |
272 item = st.deserialize(item); | 271 item = st.deserialize(item); |
273 end | 272 end |
274 module:log("debug", tostring(item)); | 273 module:log("debug", tostring(item)); |
275 | 274 |
276 local tag = jid_bare(item.attr["from"]) == jid_bare(origin.full_jid) and "from" or "to"; | 275 local tag = jid_bare(item.attr["from"]) == jid_bare(origin.full_jid) and "to" or "from"; |
277 tag = chat:tag(tag, {secs = when - qstart}); | 276 tag = chat:tag(tag, {secs = when - qstart}); |
278 tag:add_child(item:get_child("body")):up(); | 277 tag:add_child(item:get_child("body")):up(); |
279 end | 278 if not first then first = id; end |
279 last = id; | |
280 end | |
281 reply:add_child(rsm.generate{ first = first, last = last, count = count }) | |
280 | 282 |
281 origin.send(reply); | 283 origin.send(reply); |
282 return true; | 284 return true; |
283 end | 285 end |
284 | 286 |