Software /
code /
prosody
Annotate
core/offlinemanager.lua @ 537:c157c1412bda 0.1.0
Fix Makefile to link with Lua again
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 03 Dec 2008 20:00:17 +0000 |
parent | 519:cccd610a0ef9 |
child | 615:4ae3e81513f3 |
rev | line source |
---|---|
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
1 -- Prosody IM v0.1 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
2 -- Copyright (C) 2008 Matthew Wild |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
3 -- Copyright (C) 2008 Waqas Hussain |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
4 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
5 -- This program is free software; you can redistribute it and/or |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
6 -- modify it under the terms of the GNU General Public License |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
7 -- as published by the Free Software Foundation; either version 2 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
8 -- of the License, or (at your option) any later version. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
9 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
10 -- This program is distributed in the hope that it will be useful, |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
13 -- GNU General Public License for more details. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
14 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
15 -- You should have received a copy of the GNU General Public License |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
16 -- along with this program; if not, write to the Free Software |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
18 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
19 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
20 |
249
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 local datamanager = require "util.datamanager"; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 local st = require "util.stanza"; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 local datetime = require "util.datetime"; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 local ipairs = ipairs; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 module "offlinemanager" |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 function store(node, host, stanza) |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 stanza.attr.stamp = datetime.datetime(); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 stanza.attr.stamp_legacy = datetime.legacy(); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 return datamanager.list_append(node, host, "offline", st.preserialize(stanza)); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 function load(node, host) |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 local data = datamanager.list_load(node, host, "offline"); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 if not data then return; end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 for k, v in ipairs(data) do |
267 | 39 local stanza = st.deserialize(v); |
249
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated) |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 data[k] = stanza; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 return data; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 function deleteAll(node, host) |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 return datamanager.list_store(node, host, "offline", nil); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 return _M; |