Annotate

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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1453
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2 local datamanager = require "util.datamanager";
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 local st = require "util.stanza";
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4 local datetime = require "util.datetime";
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 local ipairs = ipairs;
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7 module:add_feature("msgoffline");
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9 module:hook("message/offline/store", function(event)
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10 local origin, stanza = event.origin, event.stanza;
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 local to = stanza.attr.to;
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 local node, host;
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 if to then
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 node, host = jid_split(to)
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 else
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 node, host = origin.username, origin.host;
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 end
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 stanza.attr.stamp, stanza.attr.stamp_legacy = datetime.datetime(), datetime.legacy();
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 local result = datamanager.list_append(node, host, "offline", st.preserialize(stanza));
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 return true;
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 end);
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
25
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 module:hook("message/offline/broadcast", function(event)
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 local origin = event.origin;
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 local node, host = origin.username, origin.host;
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 local data = datamanager.list_load(node, host, "offline");
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 if not data then return true; end
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32 for _, stanza in ipairs(data) do
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 stanza = st.deserialize(stanza);
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated)
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 origin.send(stanza);
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 end
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 return true;
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 end);
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 module:hook("message/offline/delete", function(event)
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 local origin = event.origin;
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 local node, host = origin.username, origin.host;
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 return datamanager.list_store(node, host, "offline", nil);
64c77c6eb30e mod_offline: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 end);