Skip to content

Commit

Permalink
prefer early return
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Jan 8, 2025
1 parent 710b167 commit ce30e8b
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions packages/stream-management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,26 @@ export default function streamManagement({
}

middleware.filter((context, next) => {
if (!sm.enabled) return next();
const { stanza } = context;
if (sm.enabled && ["presence", "message", "iq"].includes(stanza.name)) {
let qStanza = stanza;
if (
qStanza.name === "message" &&
!qStanza.getChild("delay", "urn:xmpp:delay")
) {
qStanza = xml.clone(qStanza);
qStanza.c("delay", {
xmlns: "urn:xmpp:delay",
from: entity.jid.toString(),
stamp: datetime(),
});
}
sm.outbound_q.push(qStanza);
// Debounce requests so we send only one after a big run of stanza together
clearTimeout(requestAckTimeout);
requestAckTimeout = setTimeout(requestAck, 100);
if (!["presence", "message", "iq"].includes(stanza.name)) return next();

let qStanza = stanza;
if (
qStanza.name === "message" &&
!qStanza.getChild("delay", "urn:xmpp:delay")
) {
qStanza = xml.clone(qStanza);
qStanza.c("delay", {
xmlns: "urn:xmpp:delay",
from: entity.jid.toString(),
stamp: datetime(),
});
}
sm.outbound_q.push(qStanza);
// Debounce requests so we send only one after a big run of stanza together
clearTimeout(requestAckTimeout);
requestAckTimeout = setTimeout(requestAck, 100);
return next();
});

Expand Down

0 comments on commit ce30e8b

Please sign in to comment.