fix: Roster request being treated as a roster push
This commit is contained in:
parent
09d2601e85
commit
678564dbb3
@ -94,6 +94,7 @@ class XmppConnection {
|
||||
_awaitingResponseLock = Lock(),
|
||||
_xmppManagers = {},
|
||||
_incomingStanzaHandlers = List.empty(growable: true),
|
||||
_incomingEncryptionStanzaHandlers = List.empty(growable: true),
|
||||
_outgoingPreStanzaHandlers = List.empty(growable: true),
|
||||
_outgoingPostStanzaHandlers = List.empty(growable: true),
|
||||
_reconnectionPolicy = reconnectionPolicy,
|
||||
@ -133,6 +134,7 @@ class XmppConnection {
|
||||
/// Helpers
|
||||
///
|
||||
final List<StanzaHandler> _incomingStanzaHandlers;
|
||||
final List<StanzaHandler> _incomingEncryptionStanzaHandlers;
|
||||
final List<StanzaHandler> _outgoingPreStanzaHandlers;
|
||||
final List<StanzaHandler> _outgoingPostStanzaHandlers;
|
||||
final StreamController<XmppEvent> _eventStreamController;
|
||||
@ -223,11 +225,13 @@ class XmppConnection {
|
||||
}
|
||||
|
||||
_incomingStanzaHandlers.addAll(manager.getIncomingStanzaHandlers());
|
||||
_incomingEncryptionStanzaHandlers.addAll(manager.getIncomingEncryptionStanzaHandlers());
|
||||
_outgoingPreStanzaHandlers.addAll(manager.getOutgoingPreStanzaHandlers());
|
||||
_outgoingPostStanzaHandlers.addAll(manager.getOutgoingPostStanzaHandlers());
|
||||
|
||||
if (sortHandlers) {
|
||||
_incomingStanzaHandlers.sort(stanzaHandlerSortComparator);
|
||||
_incomingEncryptionStanzaHandlers.sort(stanzaHandlerSortComparator);
|
||||
_outgoingPreStanzaHandlers.sort(stanzaHandlerSortComparator);
|
||||
_outgoingPostStanzaHandlers.sort(stanzaHandlerSortComparator);
|
||||
}
|
||||
@ -634,6 +638,10 @@ class XmppConnection {
|
||||
return _runStanzaHandlers(_incomingStanzaHandlers, stanza);
|
||||
}
|
||||
|
||||
Future<StanzaHandlerData> _runIncomingEncryptionStanzaHandlers(Stanza stanza) async {
|
||||
return _runStanzaHandlers(_incomingEncryptionStanzaHandlers, stanza);
|
||||
}
|
||||
|
||||
Future<StanzaHandlerData> _runOutgoingPreStanzaHandlers(Stanza stanza, { StanzaHandlerData? initial }) async {
|
||||
return _runStanzaHandlers(_outgoingPreStanzaHandlers, stanza, initial: initial);
|
||||
}
|
||||
@ -673,18 +681,18 @@ class XmppConnection {
|
||||
|
||||
// Run the incoming stanza handlers and bounce with an error if no manager handled
|
||||
// it.
|
||||
final incomingHandlers = await _runIncomingStanzaHandlers(stanza);
|
||||
final prefix = incomingHandlers.encrypted ?
|
||||
final incomingEncryptionHandlers = await _runIncomingEncryptionStanzaHandlers(stanza);
|
||||
final prefix = incomingEncryptionHandlers.encrypted ?
|
||||
'(Encrypted) ' :
|
||||
'';
|
||||
_log.finest('<== $prefix${incomingHandlers.stanza.toXml()}');
|
||||
_log.finest('<== $prefix${incomingEncryptionHandlers.stanza.toXml()}');
|
||||
|
||||
// See if we are waiting for this stanza
|
||||
final id = stanza.attributes['id'] as String?;
|
||||
final id = incomingEncryptionHandlers.stanza.attributes['id'] as String?;
|
||||
var awaited = false;
|
||||
await _awaitingResponseLock.synchronized(() async {
|
||||
if (id != null && _awaitingResponse.containsKey(id)) {
|
||||
_awaitingResponse[id]!.complete(incomingHandlers.stanza);
|
||||
_awaitingResponse[id]!.complete(incomingEncryptionHandlers.stanza);
|
||||
_awaitingResponse.remove(id);
|
||||
awaited = true;
|
||||
}
|
||||
@ -695,6 +703,7 @@ class XmppConnection {
|
||||
}
|
||||
|
||||
// Only bounce if the stanza has neither been awaited, nor handled.
|
||||
final incomingHandlers = await _runIncomingStanzaHandlers(incomingEncryptionHandlers.stanza);
|
||||
if (!incomingHandlers.done) {
|
||||
handleUnhandledStanza(this, stanza);
|
||||
}
|
||||
|
@ -32,6 +32,10 @@ abstract class XmppManagerBase {
|
||||
/// receive.
|
||||
List<StanzaHandler> getIncomingStanzaHandlers() => [];
|
||||
|
||||
/// Return the StanzaHandlers associated with this manager that deal with stanzas we
|
||||
/// may decrypt.
|
||||
List<StanzaHandler> getIncomingEncryptionStanzaHandlers() => [];
|
||||
|
||||
/// Return the NonzaHandlers associated with this manager.
|
||||
List<NonzaHandler> getNonzaHandlers() => [];
|
||||
|
||||
|
@ -139,6 +139,7 @@ class RosterManager extends XmppManagerBase {
|
||||
}
|
||||
|
||||
final query = stanza.firstTag('query', xmlns: rosterXmlns)!;
|
||||
logger.fine('Roster push: ${query.toXml()}');
|
||||
final item = query.firstTag('item');
|
||||
|
||||
if (item == null) {
|
||||
@ -199,28 +200,34 @@ class RosterManager extends XmppManagerBase {
|
||||
return Result(result);
|
||||
}
|
||||
|
||||
/// Requests the roster following RFC 6121 without using roster versioning.
|
||||
/// Requests the roster following RFC 6121.
|
||||
Future<Result<RosterRequestResult, RosterError>> requestRoster() async {
|
||||
final attrs = getAttributes();
|
||||
final query = XMLNode.xmlns(
|
||||
tag: 'query',
|
||||
xmlns: rosterXmlns,
|
||||
);
|
||||
final rosterVersion = await _stateManager.getRosterVersion();
|
||||
if (rosterVersion != null && rosterVersioningAvailable()) {
|
||||
query.attributes['ver'] = rosterVersion;
|
||||
}
|
||||
|
||||
final response = await attrs.sendStanza(
|
||||
Stanza.iq(
|
||||
type: 'get',
|
||||
children: [
|
||||
XMLNode.xmlns(
|
||||
tag: 'query',
|
||||
xmlns: rosterXmlns,
|
||||
)
|
||||
query,
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (response.attributes['type'] != 'result') {
|
||||
logger.warning('Error requesting roster without roster versioning: ${response.toXml()}');
|
||||
logger.warning('Error requesting roster: ${response.toXml()}');
|
||||
return Result(UnknownError());
|
||||
}
|
||||
|
||||
final query = response.firstTag('query', xmlns: rosterXmlns);
|
||||
return _handleRosterResponse(query);
|
||||
final responseQuery = response.firstTag('query', xmlns: rosterXmlns);
|
||||
return _handleRosterResponse(responseQuery);
|
||||
}
|
||||
|
||||
/// Requests a series of roster pushes according to RFC6121. Requires that the server
|
||||
|
@ -53,7 +53,7 @@ abstract class BaseOmemoManager extends XmppManagerBase {
|
||||
Future<bool> isSupported() async => true;
|
||||
|
||||
@override
|
||||
List<StanzaHandler> getIncomingStanzaHandlers() => [
|
||||
List<StanzaHandler> getIncomingEncryptionStanzaHandlers() => [
|
||||
StanzaHandler(
|
||||
stanzaTag: 'iq',
|
||||
tagXmlns: omemoXmlns,
|
||||
|
@ -8,7 +8,7 @@ environment:
|
||||
sdk: '>=2.17.5 <3.0.0'
|
||||
|
||||
dependencies:
|
||||
collection: ^1.17.0
|
||||
collection: ^1.16.0
|
||||
cryptography: ^2.0.5
|
||||
freezed: ^2.1.0+1
|
||||
freezed_annotation: ^2.1.0
|
||||
|
Loading…
Reference in New Issue
Block a user