Software /
code /
prosody-modules
Comparison
mod_onhold/mod_onhold.lua @ 2:b8012f99acfb
Initial commit of mod_onhold, using configuration in prosody config file.
author | Jeff Mitchell <jeffrey.mitchell@gmail.com> |
---|---|
date | Thu, 10 Sep 2009 20:55:41 +0000 |
child | 1343:7dbde05b48a9 |
comparison
equal
deleted
inserted
replaced
1:21e089282b8f | 2:b8012f99acfb |
---|---|
1 -- Prosody IM | |
2 -- Copyright (C) 2008-2009 Matthew Wild | |
3 -- Copyright (C) 2008-2009 Waqas Hussain | |
4 -- Copyright (C) 2009 Jeff Mitchell | |
5 -- | |
6 -- This project is MIT/X11 licensed. Please see the | |
7 -- COPYING file in the source package for more information. | |
8 -- | |
9 | |
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 | |
18 | |
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); | |
23 local node, host; | |
24 local onhold_node, onhold_host; | |
25 | |
26 if to then | |
27 node, host = jid_split(to) | |
28 else | |
29 node, host = session.username, session.host; | |
30 end | |
31 | |
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; | |
36 return true; | |
37 end | |
38 return nil; | |
39 end | |
40 | |
41 module:hook("message/bare", process_message, 5); | |
42 | |
43 module:hook("message/full", process_message, 5); | |
44 | |
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; | |
49 local from; | |
50 local de_stanza; | |
51 | |
52 local data = datamanager.list_load(node, host, "onhold"); | |
53 local newdata = {}; | |
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); | |
63 else | |
64 table.insert(newdata, stanza); | |
65 end | |
66 end | |
67 datamanager.list_store(node, host, "onhold", newdata); | |
68 return nil; | |
69 end, 5); | |
70 |