Software /
code /
prosody
Annotate
core/offlinemanager.lua @ 758:b1885732e979
GPL->MIT!
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 30 Jan 2009 17:22:56 +0000 |
parent | 615:4ae3e81513f3 |
child | 759:5cccfb5da6cb |
rev | line source |
---|---|
615 | 1 -- Prosody IM v0.2 |
519
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 -- |
758 | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
7 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
8 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
267
diff
changeset
|
9 |
249
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 local datamanager = require "util.datamanager"; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 local st = require "util.stanza"; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 local datetime = require "util.datetime"; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 local ipairs = ipairs; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 module "offlinemanager" |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 function store(node, host, stanza) |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 stanza.attr.stamp = datetime.datetime(); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 stanza.attr.stamp_legacy = datetime.legacy(); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 return datamanager.list_append(node, host, "offline", st.preserialize(stanza)); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 function load(node, host) |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 local data = datamanager.list_load(node, host, "offline"); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 if not data then return; end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 for k, v in ipairs(data) do |
267 | 28 local stanza = st.deserialize(v); |
249
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 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
|
30 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
|
31 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 data[k] = 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 return data; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 function deleteAll(node, host) |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 return datamanager.list_store(node, host, "offline", nil); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 return _M; |