Comparison

plugins/mod_offline.lua @ 1453:64c77c6eb30e

mod_offline: Initial commit
author Waqas Hussain <waqas20@gmail.com>
date Thu, 02 Jul 2009 00:48:18 +0500
child 1522:569d58d21612
comparison
equal deleted inserted replaced
1452:0ae8787e4e7d 1453:64c77c6eb30e
1
2 local datamanager = require "util.datamanager";
3 local st = require "util.stanza";
4 local datetime = require "util.datetime";
5 local ipairs = ipairs;
6
7 module:add_feature("msgoffline");
8
9 module:hook("message/offline/store", function(event)
10 local origin, stanza = event.origin, event.stanza;
11 local to = stanza.attr.to;
12 local node, host;
13 if to then
14 node, host = jid_split(to)
15 else
16 node, host = origin.username, origin.host;
17 end
18
19 stanza.attr.stamp, stanza.attr.stamp_legacy = datetime.datetime(), datetime.legacy();
20 local result = datamanager.list_append(node, host, "offline", st.preserialize(stanza));
21 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
22
23 return true;
24 end);
25
26 module:hook("message/offline/broadcast", function(event)
27 local origin = event.origin;
28 local node, host = origin.username, origin.host;
29
30 local data = datamanager.list_load(node, host, "offline");
31 if not data then return true; end
32 for _, stanza in ipairs(data) do
33 stanza = st.deserialize(stanza);
34 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203
35 stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated)
36 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
37 origin.send(stanza);
38 end
39 return true;
40 end);
41
42 module:hook("message/offline/delete", function(event)
43 local origin = event.origin;
44 local node, host = origin.username, origin.host;
45
46 return datamanager.list_store(node, host, "offline", nil);
47 end);