Skip to content

Commit

Permalink
Store pending stanzas along with SM data
Browse files Browse the repository at this point in the history
  • Loading branch information
singpolyma committed Sep 24, 2024
1 parent 602f307 commit de2ae14
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions snikket/streams/XmppJsStream.hx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ class XmppJsStream extends GenericStream {

if (initialSM != null) {
final parsedSM = haxe.Json.parse(Bytes.ofData(initialSM).toString());
final parsedPending: Null<Array<String>> = parsedSM.pending;
if (parsedPending != null) {
for (item in parsedPending) {
pending.push(XmppJsLtx.parse(item));
}
}
xmpp.streamManagement.id = parsedSM.id;
xmpp.streamManagement.outbound = parsedSM.outbound;
xmpp.streamManagement.inbound = parsedSM.inbound;
Expand Down Expand Up @@ -297,12 +303,11 @@ class XmppJsStream extends GenericStream {

public function sendStanza(stanza:Stanza) {
if (client == null || client.status != "online") {
// TODO: these aren't part of the sm state so they can get lost
pending.push(convertFromStanza(stanza));
} else {
client.send(convertFromStanza(stanza));
triggerSMupdate();
}
triggerSMupdate();
}

public function newId():String {
Expand All @@ -319,6 +324,7 @@ class XmppJsStream extends GenericStream {
outbound: client.streamManagement.outbound,
inbound: client.streamManagement.inbound,
outbound_q: (client.streamManagement.outbound_q ?? []).map((stanza) -> stanza.toString()),
pending: pending.map((stanza) -> stanza.toString())
})).getData()
}
);
Expand Down Expand Up @@ -359,6 +365,7 @@ class XmppJsStream extends GenericStream {
while ((item = pending.shift()) != null) {
client.send(item);
}
triggerSMupdate();
trigger("status/online", { jid: jid.toString(), resumed: resumed });
}

Expand Down

0 comments on commit de2ae14

Please sign in to comment.