2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
10 local datamanager = require "util.datamanager";
\r
11 local st = require "util.stanza";
\r
12 local datetime = require "util.datetime";
\r
13 local ipairs = ipairs;
\r
15 module:add_feature("msgoffline");
\r
17 module:hook("message/offline/store", function(event)
\r
18 local origin, stanza = event.origin, event.stanza;
\r
19 local to = stanza.attr.to;
\r
22 node, host = jid_split(to)
\r
24 node, host = origin.username, origin.host;
\r
27 stanza.attr.stamp, stanza.attr.stamp_legacy = datetime.datetime(), datetime.legacy();
\r
28 local result = datamanager.list_append(node, host, "offline", st.preserialize(stanza));
\r
29 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
\r
34 module:hook("message/offline/broadcast", function(event)
\r
35 local origin = event.origin;
\r
36 local node, host = origin.username, origin.host;
\r
38 local data = datamanager.list_load(node, host, "offline");
\r
39 if not data then return true; end
\r
40 for _, stanza in ipairs(data) do
\r
41 stanza = st.deserialize(stanza);
\r
42 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203
\r
43 stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated)
\r
44 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
\r
45 origin.send(stanza);
\r
50 module:hook("message/offline/delete", function(event)
\r
51 local origin = event.origin;
\r
52 local node, host = origin.username, origin.host;
\r
54 return datamanager.list_store(node, host, "offline", nil);
\r