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;
14 local jid_split = require "util.jid".split;
\r
16 module:add_feature("msgoffline");
\r
18 module:hook("message/offline/store", function(event)
\r
19 local origin, stanza = event.origin, event.stanza;
\r
20 local to = stanza.attr.to;
\r
23 node, host = jid_split(to)
\r
25 node, host = origin.username, origin.host;
\r
28 stanza.attr.stamp, stanza.attr.stamp_legacy = datetime.datetime(), datetime.legacy();
\r
29 local result = datamanager.list_append(node, host, "offline", st.preserialize(stanza));
\r
30 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
\r
35 module:hook("message/offline/broadcast", function(event)
\r
36 local origin = event.origin;
\r
37 local node, host = origin.username, origin.host;
\r
39 local data = datamanager.list_load(node, host, "offline");
\r
40 if not data then return true; end
\r
41 for _, stanza in ipairs(data) do
\r
42 stanza = st.deserialize(stanza);
\r
43 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203
\r
44 stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated)
\r
45 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
\r
46 origin.send(stanza);
\r
51 module:hook("message/offline/delete", function(event)
\r
52 local origin = event.origin;
\r
53 local node, host = origin.username, origin.host;
\r
55 return datamanager.list_store(node, host, "offline", nil);
\r