Changeset

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 1497:d1836dfa4ae4
children 1499:698686dca982
files mod_mam_archive/mod_mam_archive.lua
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mod_mam_archive/mod_mam_archive.lua	Tue Aug 26 16:15:31 2014 +0200
+++ b/mod_mam_archive/mod_mam_archive.lua	Sun Aug 31 20:13:54 2014 +0200
@@ -9,6 +9,7 @@
 local jid_bare = require "util.jid".bare;
 local jid_prep = require "util.jid".prep;
 local date_parse = require "util.datetime".parse;
+local date_format = require "util.datetime".datetime;
 
 local st = require "util.stanza";
 local archive_store = "archive2";
@@ -16,6 +17,7 @@
 local global_default_policy = module:get_option("default_archive_policy", false);
 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50);
 local conversation_interval = tonumber(module:get_option_number("archive_conversation_interval", 86400));
+local resolve_relative_path = require "core.configmanager".resolve_relative_path;
 
 -- Feature discovery
 local xmlns_archive = "urn:xmpp:archive"
@@ -30,10 +32,6 @@
 module:add_feature("http://jabber.org/protocol/rsm");
 -- --------------------------------------------------
 
-local function date_format(s)
-    return os.date("%Y-%m-%dT%H:%M:%SZ", s);
-end
-
 local function prefs_to_stanza(prefs)
     local prefstanza = st.stanza("pref", { xmlns="urn:xmpp:archive" });
     local default = prefs[false] ~= nil and prefs[false] or global_default_policy;
@@ -265,6 +263,7 @@
     local count = err;
 
     local chat = reply:tag("chat", {xmlns=xmlns_archive, with=qwith, start=date_format(qstart), version=count});
+    local first, last;
 
     module:log("debug", "Count "..count);
     for id, item, when in data do
@@ -273,10 +272,13 @@
         end
         module:log("debug", tostring(item));
 
-        local tag = jid_bare(item.attr["from"]) == jid_bare(origin.full_jid) and "from" or "to";
+        local tag = jid_bare(item.attr["from"]) == jid_bare(origin.full_jid) and "to" or "from";
         tag = chat:tag(tag, {secs = when - qstart});
         tag:add_child(item:get_child("body")):up();
+        if not first then first = id; end
+        last = id;
     end
+    reply:add_child(rsm.generate{ first = first, last = last, count = count })
 
     origin.send(reply);
     return true;