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