Wed, 26 Nov 2008 09:47:16 +0500
Wrapped a core_process_stanza call in an xpcall call
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 |
267 | 19 | local stanza = st.deserialize(v); |
249
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; |