1 -- Copyright (C) 2016-2018 Kim Alvefur
3 -- This project is MIT/X11 licensed. Please see the
4 -- COPYING file in the source package for more information.
9 local jid
= require
"util.jid";
10 local st
= require
"util.stanza";
11 local dt
= require
"util.datetime";
12 local new_queue
= require
"util.queue".new
;
14 local function new_pump(output
, ...)
15 -- luacheck: ignore 212/self
16 local q
= new_queue(...);
27 local ok
= push(self
, item
);
37 local item
= self
:pop();
47 local queue_size
= module
:get_option_number("csi_queue_size", 256);
49 module
:hook("csi-is-stanza-important", function (event
)
50 local stanza
= event
.stanza
;
51 if not st
.is_stanza(stanza
) then
54 local st_name
= stanza
.name
;
55 if not st_name
then return false; end
56 local st_type
= stanza
.attr
.type;
57 if st_name
== "presence" then
58 if st_type
== nil or st_type
== "unavailable" then
62 elseif st_name
== "message" then
63 if st_type
== "headline" then
66 if stanza
:get_child("sent", "urn:xmpp:carbons:2") then
69 local forwarded
= stanza
:find("{urn:xmpp:carbons:2}received/{urn:xmpp:forward:0}/{jabber:client}message");
73 if stanza
:get_child("body") then
76 if stanza
:get_child("subject") then
79 if stanza
:get_child("encryption", "urn:xmpp:eme:0") then
87 module
:hook("csi-client-inactive", function (event
)
88 local session
= event
.origin
;
92 local bare_jid
= jid
.join(session
.username
, session
.host
);
93 local send
= session
.send
;
94 session
._orig_send
= send
;
95 local pump
= new_pump(session
.send
, queue_size
);
98 function session
.send(stanza
)
99 if session
.state
== "active" or module
:fire_event("csi-is-stanza-important", { stanza
= stanza
, session
= session
}) then
103 if st
.is_stanza(stanza
) and stanza
.attr
.xmlns
== nil and stanza
.name
~= "iq" then
104 stanza
= st
.clone(stanza
);
105 stanza
:add_direct_child(st
.stanza("delay", {xmlns
= "urn:xmpp:delay", from
= bare_jid
, stamp
= dt
.datetime()}));
114 module
:hook("csi-client-active", function (event
)
115 local session
= event
.origin
;
117 session
.pump
:resume();