Remove version number from copyright headers
[prosody.git] / plugins / mod_offline.lua
1 -- Prosody IM
2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
4 -- 
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9 \r
10 local datamanager = require "util.datamanager";\r
11 local st = require "util.stanza";\r
12 local datetime = require "util.datetime";\r
13 local ipairs = ipairs;\r
14 \r
15 module:add_feature("msgoffline");\r
16 \r
17 module:hook("message/offline/store", function(event)\r
18         local origin, stanza = event.origin, event.stanza;\r
19         local to = stanza.attr.to;\r
20         local node, host;\r
21         if to then\r
22                 node, host = jid_split(to)\r
23         else\r
24                 node, host = origin.username, origin.host;\r
25         end\r
26         \r
27         stanza.attr.stamp, stanza.attr.stamp_legacy = datetime.datetime(), datetime.legacy();\r
28         local result = datamanager.list_append(node, host, "offline", st.preserialize(stanza));\r
29         stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;\r
30         \r
31         return true;\r
32 end);\r
33 \r
34 module:hook("message/offline/broadcast", function(event)\r
35         local origin = event.origin;\r
36         local node, host = origin.username, origin.host;\r
37         \r
38         local data = datamanager.list_load(node, host, "offline");\r
39         if not data then return true; end\r
40         for _, stanza in ipairs(data) do\r
41                 stanza = st.deserialize(stanza);\r
42                 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203\r
43                 stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated)\r
44                 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;\r
45                 origin.send(stanza);\r
46         end\r
47         return true;\r
48 end);\r
49 \r
50 module:hook("message/offline/delete", function(event)\r
51         local origin = event.origin;\r
52         local node, host = origin.username, origin.host;\r
53 \r
54         return datamanager.list_store(node, host, "offline", nil);\r
55 end);\r