2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
4 -- Copyright (C) 2009 Jeff Mitchell
6 -- This project is MIT/X11 licensed. Please see the
7 -- COPYING file in the source package for more information.
10 local datamanager
= require
"util.datamanager";
11 local jid_bare
= require
"util.jid".bare
;
12 local jid_split
= require
"util.jid".split
;
13 local st
= require
"util.stanza";
14 local datetime
= require
"util.datetime";
15 local ipairs
= ipairs
;
16 local onhold_jids
= module
:get_option("onhold_jids") or {};
17 for _
, jid
in ipairs(onhold_jids
) do onhold_jids
[jid
] = true; end
19 function process_message(event
)
20 local session
, stanza
= event
.origin
, event
.stanza
;
21 local to
= stanza
.attr
.to
;
22 local from
= jid_bare(stanza
.attr
.from
);
24 local onhold_node
, onhold_host
;
27 node
, host
= jid_split(to
)
29 node
, host
= session
.username
, session
.host
;
32 if onhold_jids
[from
] then
33 stanza
.attr
.stamp
, stanza
.attr
.stamp_legacy
= datetime
.datetime(), datetime
.legacy();
34 local result
= datamanager
.list_append(node
, host
, "onhold", st
.preserialize(stanza
));
35 stanza
.attr
.stamp
, stanza
.attr
.stamp_legacy
= nil, nil;
41 module
:hook("message/bare", process_message
, 5);
43 module
:hook("message/full", process_message
, 5);
45 module
:hook("presence/bare", function(event
)
46 if event
.origin
.presence
then return nil; end
47 local session
= event
.origin
;
48 local node
, host
= session
.username
, session
.host
;
52 local data
= datamanager
.list_load(node
, host
, "onhold");
54 if not data
then return nil; end
55 for _
, stanza
in ipairs(data
) do
56 de_stanza
= st
.deserialize(stanza
);
57 from
= jid_bare(de_stanza
.attr
.from
);
58 if not onhold_jids
[from
] then
59 de_stanza
:tag("delay", {xmlns
= "urn:xmpp:delay", from
= host
, stamp
= de_stanza
.attr
.stamp
}):up(); -- XEP-0203
60 de_stanza
:tag("x", {xmlns
= "jabber:x:delay", from
= host
, stamp
= de_stanza
.attr
.stamp_legacy
}):up(); -- XEP-0091 (deprecated)
61 de_stanza
.attr
.stamp
, de_stanza
.attr
.stamp_legacy
= nil, nil;
62 session
.send(de_stanza
);
64 table.insert(newdata
, stanza
);
67 datamanager
.list_store(node
, host
, "onhold", newdata
);