Automated merge with http://waqas.ath.cx:8000/
[prosody.git] / core / offlinemanager.lua
1 -- Prosody IM v0.2
2 -- Copyright (C) 2008 Matthew Wild
3 -- Copyright (C) 2008 Waqas Hussain
4 -- 
5 -- This program is free software; you can redistribute it and/or
6 -- modify it under the terms of the GNU General Public License
7 -- as published by the Free Software Foundation; either version 2
8 -- of the License, or (at your option) any later version.
9 -- 
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 -- GNU General Public License for more details.
14 -- 
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 --
19
20
21 \r
22 local datamanager = require "util.datamanager";\r
23 local st = require "util.stanza";\r
24 local datetime = require "util.datetime";\r
25 local ipairs = ipairs;\r
26 \r
27 module "offlinemanager"\r
28 \r
29 function store(node, host, stanza)\r
30         stanza.attr.stamp = datetime.datetime();\r
31         stanza.attr.stamp_legacy = datetime.legacy();\r
32         return datamanager.list_append(node, host, "offline", st.preserialize(stanza));\r
33 end\r
34 \r
35 function load(node, host)\r
36         local data = datamanager.list_load(node, host, "offline");\r
37         if not data then return; end\r
38         for k, v in ipairs(data) do\r
39                 local stanza = st.deserialize(v);\r
40                 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203\r
41                 stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated)\r
42                 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;\r
43                 data[k] = stanza;\r
44         end\r
45         return data;\r
46 end\r
47 \r
48 function deleteAll(node, host)\r
49         return datamanager.list_store(node, host, "offline", nil);\r
50 end\r
51 \r
52 return _M;\r