fix(xep): Do not set C2S counter to 0 after connecting

This commit is contained in:
PapaTutuWawa 2023-05-16 13:45:52 +02:00
parent 320f4a8d4c
commit 47b679d168
2 changed files with 23 additions and 9 deletions

View File

@ -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<void> _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<void> 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

View File

@ -733,6 +733,15 @@ void main() {
"<resume xmlns='urn:xmpp:sm:3' previd='id-1' h='10' />",
"<resumed xmlns='urn:xmpp:sm:3' h='id-1' h='12' />",
),
StanzaExpectation(
"<iq to='localhost' type='get' from='polynomdivision@test.server/abc123' xmlns='jabber:client' />",
'',
ignoreId: true,
),
StanzaExpectation(
"<r xmlns='urn:xmpp:sm:3' />",
'',
),
]);
final conn = XmppConnection(
@ -780,7 +789,7 @@ void main() {
// Wait for reconnect
await Future<void>.delayed(const Duration(seconds: 5));
expect(fakeSocket.getState(), 14);
expect(fakeSocket.getState(), 12);
});
test('Test SASL2 inline stream resumption', () async {