Software /
code /
prosody
Annotate
core/offlinemanager.lua @ 249:1fc47cf5d144
Added basic offline message support
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 13 Nov 2008 12:13:13 +0500 |
child | 267:6303b7454ad0 |
rev | line source |
---|---|
249
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 local datamanager = require "util.datamanager"; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 local st = require "util.stanza"; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 local datetime = require "util.datetime"; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 local ipairs = ipairs; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 module "offlinemanager" |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 function store(node, host, stanza) |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 stanza.attr.stamp = datetime.datetime(); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 stanza.attr.stamp_legacy = datetime.legacy(); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 return datamanager.list_append(node, host, "offline", st.preserialize(stanza)); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 function load(node, host) |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 local data = datamanager.list_load(node, host, "offline"); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 if not data then return; end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 for k, v in ipairs(data) do |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 stanza = st.deserialize(v); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 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
|
21 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
|
22 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 data[k] = stanza; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 return data; |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 function deleteAll(node, host) |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 return datamanager.list_store(node, host, "offline", nil); |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 end |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 |
1fc47cf5d144
Added basic offline message support
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 return _M; |