From 47b679d168431fb8eda243adaea249932c7176c7 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Tue, 16 May 2023 13:45:52 +0200 Subject: [PATCH] fix(xep): Do not set C2S counter to 0 after connecting --- .../lib/src/xeps/xep_0198/xep_0198.dart | 21 ++++++++++++------- packages/moxxmpp/test/xeps/xep_0198_test.dart | 11 +++++++++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/packages/moxxmpp/lib/src/xeps/xep_0198/xep_0198.dart b/packages/moxxmpp/lib/src/xeps/xep_0198/xep_0198.dart index 6595833..38a566b 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0198/xep_0198.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0198/xep_0198.dart @@ -188,7 +188,9 @@ class StreamManagementManager extends XmppManagerBase { switch (event.state) { case XmppConnectionState.connected: // Push out all pending stanzas - await onStreamResumed(0); + if (!_streamResumed) { + await _resendStanzas(); + } break; case XmppConnectionState.error: case XmppConnectionState.notConnected: @@ -407,20 +409,23 @@ class StreamManagementManager extends XmppManagerBase { return state; } + Future _resendStanzas() async { + final stanzas = _unackedStanzas.values.toList(); + _unackedStanzas.clear(); + + for (final stanza in stanzas) { + await getAttributes().sendStanza(stanza, awaitable: false); + } + } + /// To be called when the stream has been resumed @visibleForTesting Future onStreamResumed(int h) async { _streamResumed = true; await _handleAckResponse(StreamManagementAckNonza(h)); - final stanzas = _unackedStanzas.values.toList(); - _unackedStanzas.clear(); - // Retransmit the rest of the queue - final attrs = getAttributes(); - for (final stanza in stanzas) { - await attrs.sendStanza(stanza, awaitable: false); - } + await _resendStanzas(); } /// Pings the connection open by send an ack request diff --git a/packages/moxxmpp/test/xeps/xep_0198_test.dart b/packages/moxxmpp/test/xeps/xep_0198_test.dart index f0a317a..d1f1058 100644 --- a/packages/moxxmpp/test/xeps/xep_0198_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0198_test.dart @@ -733,6 +733,15 @@ void main() { "", "", ), + StanzaExpectation( + "", + '', + ignoreId: true, + ), + StanzaExpectation( + "", + '', + ), ]); final conn = XmppConnection( @@ -780,7 +789,7 @@ void main() { // Wait for reconnect await Future.delayed(const Duration(seconds: 5)); - expect(fakeSocket.getState(), 14); + expect(fakeSocket.getState(), 12); }); test('Test SASL2 inline stream resumption', () async {