Changeset

7909:428d4abee723

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Mon, 20 Feb 2017 01:46:54 +0100
parents 7900:41f783d4e127 (current diff) 7908:dbdaa8487ecd (diff)
children 7910:91db637be237
files plugins/mod_storage_sql.lua
diffstat 3 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_mam/mamprefsxml.lib.lua	Wed Feb 15 23:05:03 2017 +0100
+++ b/plugins/mod_mam/mamprefsxml.lib.lua	Mon Feb 20 01:46:54 2017 +0100
@@ -10,7 +10,7 @@
 --
 
 local st = require"util.stanza";
-local xmlns_mam = "urn:xmpp:mam:1";
+local xmlns_mam = "urn:xmpp:mam:2";
 
 local default_attrs = {
 	always = true, [true] = "always",
--- a/plugins/mod_mam/mod_mam.lua	Wed Feb 15 23:05:03 2017 +0100
+++ b/plugins/mod_mam/mod_mam.lua	Mon Feb 20 01:46:54 2017 +0100
@@ -9,7 +9,7 @@
 -- XEP-0313: Message Archive Management for Prosody
 --
 
-local xmlns_mam     = "urn:xmpp:mam:1";
+local xmlns_mam     = "urn:xmpp:mam:2";
 local xmlns_delay   = "urn:xmpp:delay";
 local xmlns_forward = "urn:xmpp:forward:0";
 local xmlns_st_id   = "urn:xmpp:sid:0";
@@ -89,7 +89,7 @@
 -- Serve form
 module:hook("iq-get/self/"..xmlns_mam..":query", function(event)
 	local origin, stanza = event.origin, event.stanza;
-	origin.send(st.reply(stanza):add_child(query_form:form()));
+	origin.send(st.reply(stanza):query(xmlns_mam):add_child(query_form:form()));
 	return true;
 end);
 
@@ -134,7 +134,6 @@
 	local before, after = qset and qset.before, qset and qset.after;
 	if type(before) ~= "string" then before = nil; end
 
-
 	-- Load all the data!
 	local data, err = archive:find(origin.username, {
 		start = qstart; ["end"] = qend; -- Time range
@@ -292,8 +291,9 @@
 		log("debug", "Archiving stanza: %s", stanza:top_tag());
 
 		-- And stash it
-		local ok, id = archive:append(store_user, nil, stanza, time_now(), with);
+		local ok = archive:append(store_user, nil, stanza, time_now(), with);
 		if ok then
+			local id = ok;
 			stanza:tag("stanza-id", { xmlns = xmlns_st_id, by = store_user.."@"..host, id = id }):up();
 			if cleanup then cleanup[store_user] = true; end
 			module:fire_event("archive-message-added", { origin = origin, stanza = stanza, for_user = store_user, id = id });
@@ -307,6 +307,18 @@
 	return message_handler(event, true);
 end
 
+local function strip_stanza_id(event)
+	local strip_by = jid_bare(event.origin.full_jid);
+	event.stanza:maptags(function(tag)
+		if not ( tag.attr.xmlns == xmlns_st_id and tag.attr.by == strip_by ) then
+			return tag;
+		end
+	end);
+end
+
+module:hook("pre-message/bare", strip_stanza_id, -1);
+module:hook("pre-message/full", strip_stanza_id, -1);
+
 local cleanup_after = module:get_option_string("archive_expires_after", "1w");
 local cleanup_interval = module:get_option_number("archive_cleanup_interval", 4 * 60 * 60);
 if cleanup_after ~= "never" then
@@ -334,7 +346,7 @@
 	-- Iterating over users is not supported by all authentication modules
 	-- Catch and ignore error if not supported
 	pcall(function ()
-		-- If this works, then we schedule cleanup for all known known
+		-- If this works, then we schedule cleanup for all known users on startup
 		for user in um.users(module.host) do
 			cleanup[user] = true;
 		end
@@ -360,7 +372,7 @@
 -- Stanzas sent by local clients
 module:hook("pre-message/bare", c2s_message_handler, 0);
 module:hook("pre-message/full", c2s_message_handler, 0);
--- Stanszas to local clients
+-- Stanzas to local clients
 module:hook("message/bare", message_handler, 0);
 module:hook("message/full", message_handler, 0);
 
--- a/plugins/mod_storage_sql.lua	Wed Feb 15 23:05:03 2017 +0100
+++ b/plugins/mod_storage_sql.lua	Mon Feb 20 01:46:54 2017 +0100
@@ -187,7 +187,7 @@
 		when, with, value = value, when, with;
 	end
 	local user,store = username,self.store;
-	return engine:transaction(function()
+	local ok, key = engine:transaction(function()
 		if key then
 			engine:delete("DELETE FROM `prosodyarchive` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, user or "", store, key);
 		else
@@ -197,6 +197,8 @@
 		engine:insert("INSERT INTO `prosodyarchive` (`host`, `user`, `store`, `when`, `with`, `key`, `type`, `value`) VALUES (?,?,?,?,?,?,?,?)", host, user or "", store, when, with, key, t, value);
 		return key;
 	end);
+	if not ok then return ok, key; end
+	return key;
 end
 
 -- Helpers for building the WHERE clause