1 -- Prosody IM |
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
|
4 -- |
|
5 -- This project is MIT/X11 licensed. Please see the |
|
6 -- COPYING file in the source package for more information. |
|
7 -- |
|
8 |
|
9 |
|
10 |
|
11 local datamanager = require "util.datamanager"; |
|
12 local st = require "util.stanza"; |
|
13 local datetime = require "util.datetime"; |
|
14 local ipairs = ipairs; |
|
15 |
|
16 module "offlinemanager" |
|
17 |
|
18 function store(node, host, stanza) |
|
19 stanza.attr.stamp = datetime.datetime(); |
|
20 stanza.attr.stamp_legacy = datetime.legacy(); |
|
21 return datamanager.list_append(node, host, "offline", st.preserialize(stanza)); |
|
22 end |
|
23 |
|
24 function load(node, host) |
|
25 local data = datamanager.list_load(node, host, "offline"); |
|
26 if not data then return; end |
|
27 for k, v in ipairs(data) do |
|
28 local stanza = st.deserialize(v); |
|
29 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203 |
|
30 stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated) |
|
31 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil; |
|
32 data[k] = stanza; |
|
33 end |
|
34 return data; |
|
35 end |
|
36 |
|
37 function deleteAll(node, host) |
|
38 return datamanager.list_store(node, host, "offline", nil); |
|
39 end |
|
40 |
|
41 return _M; |
|