mod_csi_simple: Consider messages encrypted payload as important (fixes part of ...
[prosody.git] / plugins / mod_offline.lua
blob487098d1189bd49b8e6b73b13c4ce0042391797a
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 --
10 local datetime = require "util.datetime";
11 local jid_split = require "util.jid".split;
13 local offline_messages = module:open_store("offline", "archive");
15 module:add_feature("msgoffline");
17 module:hook("message/offline/handle", function(event)
18 local origin, stanza = event.origin, event.stanza;
19 local to = stanza.attr.to;
20 local node;
21 if to then
22 node = jid_split(to)
23 else
24 node = origin.username;
25 end
27 return offline_messages:append(node, nil, stanza, os.time(), "");
28 end, -1);
30 module:hook("message/offline/broadcast", function(event)
31 local origin = event.origin;
33 local node, host = origin.username, origin.host;
35 local data = offline_messages:find(node);
36 if not data then return true; end
37 for _, stanza, when in data do
38 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = datetime.datetime(when)}):up(); -- XEP-0203
39 origin.send(stanza);
40 end
41 offline_messages:delete(node);
42 return true;
43 end, -1);