2 local datamanager = require "util.datamanager";
\r
3 local st = require "util.stanza";
\r
4 local datetime = require "util.datetime";
\r
5 local ipairs = ipairs;
\r
7 module:add_feature("msgoffline");
\r
9 module:hook("message/offline/store", function(event)
\r
10 local origin, stanza = event.origin, event.stanza;
\r
11 local to = stanza.attr.to;
\r
14 node, host = jid_split(to)
\r
16 node, host = origin.username, origin.host;
\r
19 stanza.attr.stamp, stanza.attr.stamp_legacy = datetime.datetime(), datetime.legacy();
\r
20 local result = datamanager.list_append(node, host, "offline", st.preserialize(stanza));
\r
21 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
\r
26 module:hook("message/offline/broadcast", function(event)
\r
27 local origin = event.origin;
\r
28 local node, host = origin.username, origin.host;
\r
30 local data = datamanager.list_load(node, host, "offline");
\r
31 if not data then return true; end
\r
32 for _, stanza in ipairs(data) do
\r
33 stanza = st.deserialize(stanza);
\r
34 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203
\r
35 stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated)
\r
36 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
\r
37 origin.send(stanza);
\r
42 module:hook("message/offline/delete", function(event)
\r
43 local origin = event.origin;
\r
44 local node, host = origin.username, origin.host;
\r
46 return datamanager.list_store(node, host, "offline", nil);
\r