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
84 module
:hook("csi-client-inactive", function (event
)
85 local session
= event
.origin
;
89 local bare_jid
= jid
.join(session
.username
, session
.host
);
90 local send
= session
.send
;
91 session
._orig_send
= send
;
92 local pump
= new_pump(session
.send
, queue_size
);
95 function session
.send(stanza
)
96 if session
.state
== "active" or module
:fire_event("csi-is-stanza-important", { stanza
= stanza
, session
= session
}) then
100 if st
.is_stanza(stanza
) and stanza
.attr
.xmlns
== nil and stanza
.name
~= "iq" then
101 stanza
= st
.clone(stanza
);
102 stanza
:add_direct_child(st
.stanza("delay", {xmlns
= "urn:xmpp:delay", from
= bare_jid
, stamp
= dt
.datetime()}));
111 module
:hook("csi-client-active", function (event
)
112 local session
= event
.origin
;
114 session
.pump
:resume();