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 datetime
= require
"util.datetime";
11 local jid_split
= require
"util.jid".split
;
13 local offline_messages
= module
:open_store("offline", "archive");
15 module
:add_feature("msgoffline");
17 module
:hook("message/offline/handle", function(event
)
18 local origin
, stanza
= event
.origin
, event
.stanza
;
19 local to
= stanza
.attr
.to
;
24 node
= origin
.username
;
27 return offline_messages
:append(node
, nil, stanza
, os
.time(), "");
30 module
:hook("message/offline/broadcast", function(event
)
31 local origin
= event
.origin
;
33 local node
, host
= origin
.username
, origin
.host
;
35 local data
= offline_messages
:find(node
);
36 if not data
then return true; end
37 for _
, stanza
, when
in data
do
38 stanza
:tag("delay", {xmlns
= "urn:xmpp:delay", from
= host
, stamp
= datetime
.datetime(when
)}):up(); -- XEP-0203
41 offline_messages
:delete(node
);