From 3cb5a568ce4a58c5953113e1221526e476a88c05 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sat, 17 Jun 2023 21:45:00 +0200 Subject: [PATCH] feat(xep,core): Migrate to moxlib's Result type --- packages/moxxmpp/lib/moxxmpp.dart | 1 - packages/moxxmpp/lib/src/connection.dart | 1 - packages/moxxmpp/lib/src/managers/base.dart | 1 - .../moxxmpp/lib/src/managers/handlers.dart | 10 +++--- .../lib/src/negotiators/negotiator.dart | 5 ++- packages/moxxmpp/lib/src/presence.dart | 2 +- .../src/rfcs/rfc_6120/resource_binding.dart | 2 +- .../src/rfcs/rfc_6120/sasl/negotiator.dart | 8 ++--- .../lib/src/rfcs/rfc_6120/sasl/plain.dart | 2 +- .../lib/src/rfcs/rfc_6120/sasl/scram.dart | 2 +- .../lib/src/rfcs/rfc_6120/starttls.dart | 2 +- packages/moxxmpp/lib/src/roster/roster.dart | 2 +- packages/moxxmpp/lib/src/types/result.dart | 16 --------- packages/moxxmpp/lib/src/util/queue.dart | 8 +---- .../moxxmpp/lib/src/xeps/staging/fast.dart | 2 +- packages/moxxmpp/lib/src/xeps/xep_0004.dart | 4 +-- .../lib/src/xeps/xep_0030/xep_0030.dart | 2 +- packages/moxxmpp/lib/src/xeps/xep_0054.dart | 2 +- .../lib/src/xeps/xep_0060/xep_0060.dart | 2 +- packages/moxxmpp/lib/src/xeps/xep_0084.dart | 3 +- .../lib/src/xeps/xep_0198/negotiator.dart | 2 +- packages/moxxmpp/lib/src/xeps/xep_0352.dart | 2 +- .../lib/src/xeps/xep_0363/xep_0363.dart | 10 +++--- .../lib/src/xeps/xep_0384/xep_0384.dart | 33 ++++++++++--------- packages/moxxmpp/lib/src/xeps/xep_0386.dart | 2 +- .../lib/src/xeps/xep_0388/negotiators.dart | 2 +- .../lib/src/xeps/xep_0388/xep_0388.dart | 2 +- packages/moxxmpp/lib/src/xeps/xep_0447.dart | 5 ++- packages/moxxmpp/lib/src/xeps/xep_0448.dart | 5 ++- packages/moxxmpp/lib/src/xeps/xep_0449.dart | 2 +- packages/moxxmpp/test/negotiator_test.dart | 2 ++ packages/moxxmpp/test/xeps/xep_0060_test.dart | 1 + packages/moxxmpp/test/xeps/xep_0115_test.dart | 1 + packages/moxxmpp/test/xeps/xep_0388_test.dart | 2 ++ 34 files changed, 63 insertions(+), 85 deletions(-) delete mode 100644 packages/moxxmpp/lib/src/types/result.dart diff --git a/packages/moxxmpp/lib/moxxmpp.dart b/packages/moxxmpp/lib/moxxmpp.dart index 10cbb94..221ca5e 100644 --- a/packages/moxxmpp/lib/moxxmpp.dart +++ b/packages/moxxmpp/lib/moxxmpp.dart @@ -38,7 +38,6 @@ export 'package:moxxmpp/src/settings.dart'; export 'package:moxxmpp/src/socket.dart'; export 'package:moxxmpp/src/stanza.dart'; export 'package:moxxmpp/src/stringxml.dart'; -export 'package:moxxmpp/src/types/result.dart'; export 'package:moxxmpp/src/util/typed_map.dart'; export 'package:moxxmpp/src/xeps/staging/extensible_file_thumbnails.dart'; export 'package:moxxmpp/src/xeps/staging/fast.dart'; diff --git a/packages/moxxmpp/lib/src/connection.dart b/packages/moxxmpp/lib/src/connection.dart index 6a0442d..223551a 100644 --- a/packages/moxxmpp/lib/src/connection.dart +++ b/packages/moxxmpp/lib/src/connection.dart @@ -25,7 +25,6 @@ import 'package:moxxmpp/src/settings.dart'; import 'package:moxxmpp/src/socket.dart'; import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/util/queue.dart'; import 'package:moxxmpp/src/util/typed_map.dart'; import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart'; diff --git a/packages/moxxmpp/lib/src/managers/base.dart b/packages/moxxmpp/lib/src/managers/base.dart index dca035b..ab61ed3 100644 --- a/packages/moxxmpp/lib/src/managers/base.dart +++ b/packages/moxxmpp/lib/src/managers/base.dart @@ -47,7 +47,6 @@ abstract class XmppManagerBase { final result = await dm!.discoInfoQuery( _managerAttributes.getConnectionSettings().jid.toDomain(), - shouldEncrypt: false, ); if (result.isType()) { return false; diff --git a/packages/moxxmpp/lib/src/managers/handlers.dart b/packages/moxxmpp/lib/src/managers/handlers.dart index f35a849..f38d944 100644 --- a/packages/moxxmpp/lib/src/managers/handlers.dart +++ b/packages/moxxmpp/lib/src/managers/handlers.dart @@ -1,4 +1,4 @@ -import 'package:moxlib/moxlib.dart'; +import 'package:collection/collection.dart'; import 'package:moxxmpp/src/managers/data.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/stanza.dart'; @@ -100,10 +100,10 @@ class StanzaHandler extends Handler { matches &= firstTag?.xmlns == tagXmlns; } } else if (tagXmlns != null) { - matches &= listContains( - node.children, - (XMLNode node_) => node_.attributes['xmlns'] == tagXmlns, - ); + matches &= node.children.firstWhereOrNull( + (XMLNode node_) => node_.attributes['xmlns'] == tagXmlns, + ) != + null; } return matches; diff --git a/packages/moxxmpp/lib/src/negotiators/negotiator.dart b/packages/moxxmpp/lib/src/negotiators/negotiator.dart index 600e872..5e5c378 100644 --- a/packages/moxxmpp/lib/src/negotiators/negotiator.dart +++ b/packages/moxxmpp/lib/src/negotiators/negotiator.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:meta/meta.dart'; import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/connection.dart'; @@ -8,7 +9,6 @@ import 'package:moxxmpp/src/managers/base.dart'; import 'package:moxxmpp/src/settings.dart'; import 'package:moxxmpp/src/socket.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; /// The state a negotiator is currently in enum NegotiatorState { @@ -117,8 +117,7 @@ abstract class XmppFeatureNegotiatorBase { /// Returns true if a feature in [features], which are the children of the /// nonza, can be negotiated. Otherwise, returns false. bool matchesFeature(List features) { - return firstWhereOrNull( - features, + return features.firstWhereOrNull( (XMLNode feature) => feature.attributes['xmlns'] == negotiatingXmlns, ) != null; diff --git a/packages/moxxmpp/lib/src/presence.dart b/packages/moxxmpp/lib/src/presence.dart index f248601..d53d349 100644 --- a/packages/moxxmpp/lib/src/presence.dart +++ b/packages/moxxmpp/lib/src/presence.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/managers/base.dart'; @@ -10,7 +11,6 @@ import 'package:moxxmpp/src/negotiators/namespaces.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; /// A function that will be called when presence, outside of subscription request /// management, will be sent. Useful for managers that want to add [XMLNode]s to said diff --git a/packages/moxxmpp/lib/src/rfcs/rfc_6120/resource_binding.dart b/packages/moxxmpp/lib/src/rfcs/rfc_6120/resource_binding.dart index 2ebb737..3f7afb4 100644 --- a/packages/moxxmpp/lib/src/rfcs/rfc_6120/resource_binding.dart +++ b/packages/moxxmpp/lib/src/rfcs/rfc_6120/resource_binding.dart @@ -1,10 +1,10 @@ +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/managers/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/negotiators/namespaces.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0198/xep_0198.dart'; import 'package:uuid/uuid.dart'; diff --git a/packages/moxxmpp/lib/src/rfcs/rfc_6120/sasl/negotiator.dart b/packages/moxxmpp/lib/src/rfcs/rfc_6120/sasl/negotiator.dart index e0cef18..5ef0a86 100644 --- a/packages/moxxmpp/lib/src/rfcs/rfc_6120/sasl/negotiator.dart +++ b/packages/moxxmpp/lib/src/rfcs/rfc_6120/sasl/negotiator.dart @@ -1,4 +1,4 @@ -import 'package:moxlib/moxlib.dart'; +import 'package:collection/collection.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/stringxml.dart'; @@ -13,15 +13,13 @@ abstract class SaslNegotiator extends XmppFeatureNegotiatorBase { @override bool matchesFeature(List features) { // Is SASL advertised? - final mechanisms = firstWhereOrNull( - features, + final mechanisms = features.firstWhereOrNull( (XMLNode feature) => feature.attributes['xmlns'] == saslXmlns, ); if (mechanisms == null) return false; // Is SASL PLAIN advertised? - return firstWhereOrNull( - mechanisms.children, + return mechanisms.children.firstWhereOrNull( (XMLNode mechanism) => mechanism.text == mechanismName, ) != null; diff --git a/packages/moxxmpp/lib/src/rfcs/rfc_6120/sasl/plain.dart b/packages/moxxmpp/lib/src/rfcs/rfc_6120/sasl/plain.dart index 573762c..e839a4d 100644 --- a/packages/moxxmpp/lib/src/rfcs/rfc_6120/sasl/plain.dart +++ b/packages/moxxmpp/lib/src/rfcs/rfc_6120/sasl/plain.dart @@ -1,12 +1,12 @@ import 'dart:convert'; import 'package:logging/logging.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/negotiators/namespaces.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/rfcs/rfc_6120/sasl/errors.dart'; import 'package:moxxmpp/src/rfcs/rfc_6120/sasl/nonza.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0388/negotiators.dart'; import 'package:moxxmpp/src/xeps/xep_0388/xep_0388.dart'; import 'package:saslprep/saslprep.dart'; diff --git a/packages/moxxmpp/lib/src/rfcs/rfc_6120/sasl/scram.dart b/packages/moxxmpp/lib/src/rfcs/rfc_6120/sasl/scram.dart index 9ea570b..e753c53 100644 --- a/packages/moxxmpp/lib/src/rfcs/rfc_6120/sasl/scram.dart +++ b/packages/moxxmpp/lib/src/rfcs/rfc_6120/sasl/scram.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:math' show Random; import 'package:cryptography/cryptography.dart'; import 'package:logging/logging.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/negotiators/namespaces.dart'; @@ -10,7 +11,6 @@ import 'package:moxxmpp/src/rfcs/rfc_6120/sasl/errors.dart'; import 'package:moxxmpp/src/rfcs/rfc_6120/sasl/kv.dart'; import 'package:moxxmpp/src/rfcs/rfc_6120/sasl/nonza.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0388/negotiators.dart'; import 'package:moxxmpp/src/xeps/xep_0388/xep_0388.dart'; import 'package:random_string/random_string.dart'; diff --git a/packages/moxxmpp/lib/src/rfcs/rfc_6120/starttls.dart b/packages/moxxmpp/lib/src/rfcs/rfc_6120/starttls.dart index b8e07d1..bb92d40 100644 --- a/packages/moxxmpp/lib/src/rfcs/rfc_6120/starttls.dart +++ b/packages/moxxmpp/lib/src/rfcs/rfc_6120/starttls.dart @@ -1,9 +1,9 @@ import 'package:logging/logging.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/negotiators/namespaces.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; enum _StartTlsState { ready, requested } diff --git a/packages/moxxmpp/lib/src/roster/roster.dart b/packages/moxxmpp/lib/src/roster/roster.dart index c6d7758..61fa837 100644 --- a/packages/moxxmpp/lib/src/roster/roster.dart +++ b/packages/moxxmpp/lib/src/roster/roster.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:collection/collection.dart'; import 'package:meta/meta.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/managers/attributes.dart'; import 'package:moxxmpp/src/managers/base.dart'; @@ -14,7 +15,6 @@ import 'package:moxxmpp/src/roster/errors.dart'; import 'package:moxxmpp/src/roster/state.dart'; import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; @immutable class XmppRosterItem { diff --git a/packages/moxxmpp/lib/src/types/result.dart b/packages/moxxmpp/lib/src/types/result.dart deleted file mode 100644 index a277740..0000000 --- a/packages/moxxmpp/lib/src/types/result.dart +++ /dev/null @@ -1,16 +0,0 @@ -class Result { - const Result(this._data) - : assert( - _data is T || _data is V, - 'Invalid data type: Must be either $T or $V', - ); - final dynamic _data; - - bool isType() => _data is S; - - S get() { - assert(_data is S, 'Data is not $S'); - - return _data as S; - } -} diff --git a/packages/moxxmpp/lib/src/util/queue.dart b/packages/moxxmpp/lib/src/util/queue.dart index b10047b..203da8d 100644 --- a/packages/moxxmpp/lib/src/util/queue.dart +++ b/packages/moxxmpp/lib/src/util/queue.dart @@ -33,7 +33,7 @@ class AsyncStanzaQueue { this._canSendCallback, ); - /// The lock for accessing [AsyncStanzaQueue._lock] and [AsyncStanzaQueue._running]. + /// The lock for accessing [AsyncStanzaQueue._queue]. final Lock _lock = Lock(); /// The actual job queue. @@ -44,9 +44,6 @@ class AsyncStanzaQueue { final CanSendCallback _canSendCallback; - /// Indicates whether we are currently executing a job. - bool _running = false; - @visibleForTesting Queue get queue => _queue; @@ -75,8 +72,6 @@ class AsyncStanzaQueue { unawaited( _runJob(_queue.removeFirst()), ); - } else { - _running = false; } }); } @@ -86,7 +81,6 @@ class AsyncStanzaQueue { await _lock.synchronized(() { if (_queue.isNotEmpty) { - _running = true; unawaited( _runJob(_queue.removeFirst()), ); diff --git a/packages/moxxmpp/lib/src/xeps/staging/fast.dart b/packages/moxxmpp/lib/src/xeps/staging/fast.dart index 3a873fd..c1ad724 100644 --- a/packages/moxxmpp/lib/src/xeps/staging/fast.dart +++ b/packages/moxxmpp/lib/src/xeps/staging/fast.dart @@ -1,11 +1,11 @@ import 'package:collection/collection.dart'; import 'package:logging/logging.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/negotiators/namespaces.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0388/negotiators.dart'; import 'package:moxxmpp/src/xeps/xep_0388/xep_0388.dart'; diff --git a/packages/moxxmpp/lib/src/xeps/xep_0004.dart b/packages/moxxmpp/lib/src/xeps/xep_0004.dart index 27ea054..7b4a684 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0004.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0004.dart @@ -1,4 +1,4 @@ -import 'package:moxlib/moxlib.dart'; +import 'package:collection/collection.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/stringxml.dart'; @@ -80,7 +80,7 @@ class DataForm { final List> items; DataFormField? getFieldByVar(String varAttr) { - return firstWhereOrNull(fields, (field) => field.varAttr == varAttr); + return fields.firstWhereOrNull((field) => field.varAttr == varAttr); } XMLNode toXml() { diff --git a/packages/moxxmpp/lib/src/xeps/xep_0030/xep_0030.dart b/packages/moxxmpp/lib/src/xeps/xep_0030/xep_0030.dart index 98679de..09443d2 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0030/xep_0030.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0030/xep_0030.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'package:meta/meta.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/managers/base.dart'; @@ -9,7 +10,6 @@ import 'package:moxxmpp/src/managers/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/util/wait.dart'; import 'package:moxxmpp/src/xeps/xep_0030/cache.dart'; import 'package:moxxmpp/src/xeps/xep_0030/errors.dart'; diff --git a/packages/moxxmpp/lib/src/xeps/xep_0054.dart b/packages/moxxmpp/lib/src/xeps/xep_0054.dart index e38d3d0..90c76e8 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0054.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0054.dart @@ -1,3 +1,4 @@ +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/managers/base.dart'; @@ -7,7 +8,6 @@ import 'package:moxxmpp/src/managers/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; abstract class VCardError {} diff --git a/packages/moxxmpp/lib/src/xeps/xep_0060/xep_0060.dart b/packages/moxxmpp/lib/src/xeps/xep_0060/xep_0060.dart index a6d590d..661274c 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0060/xep_0060.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0060/xep_0060.dart @@ -1,5 +1,6 @@ import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:meta/meta.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/managers/base.dart'; @@ -9,7 +10,6 @@ import 'package:moxxmpp/src/managers/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0004.dart'; import 'package:moxxmpp/src/xeps/xep_0030/errors.dart'; import 'package:moxxmpp/src/xeps/xep_0030/types.dart'; diff --git a/packages/moxxmpp/lib/src/xeps/xep_0084.dart b/packages/moxxmpp/lib/src/xeps/xep_0084.dart index 17bdd88..08ffef4 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0084.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0084.dart @@ -1,11 +1,11 @@ import 'dart:convert'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/managers/base.dart'; import 'package:moxxmpp/src/managers/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0030/errors.dart'; import 'package:moxxmpp/src/xeps/xep_0030/types.dart'; import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart'; @@ -225,7 +225,6 @@ class UserAvatarManager extends XmppManagerBase { final response = await disco.discoItemsQuery( jid, node: userAvatarDataXmlns, - shouldEncrypt: false, ); if (response.isType()) return Result(UnknownAvatarError()); diff --git a/packages/moxxmpp/lib/src/xeps/xep_0198/negotiator.dart b/packages/moxxmpp/lib/src/xeps/xep_0198/negotiator.dart index 0f3176e..d96f2e8 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0198/negotiator.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0198/negotiator.dart @@ -1,12 +1,12 @@ import 'package:collection/collection.dart'; import 'package:logging/logging.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/managers/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/negotiators/namespaces.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0198/nonzas.dart'; import 'package:moxxmpp/src/xeps/xep_0198/state.dart'; import 'package:moxxmpp/src/xeps/xep_0198/xep_0198.dart'; diff --git a/packages/moxxmpp/lib/src/xeps/xep_0352.dart b/packages/moxxmpp/lib/src/xeps/xep_0352.dart index 718d805..e2d73f7 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0352.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0352.dart @@ -1,10 +1,10 @@ +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/managers/base.dart'; import 'package:moxxmpp/src/managers/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/negotiators/namespaces.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0386.dart'; class CSIActiveNonza extends XMLNode { diff --git a/packages/moxxmpp/lib/src/xeps/xep_0363/xep_0363.dart b/packages/moxxmpp/lib/src/xeps/xep_0363/xep_0363.dart index b63ffab..7b7507e 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0363/xep_0363.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0363/xep_0363.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:meta/meta.dart'; import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/events.dart'; @@ -7,7 +8,6 @@ import 'package:moxxmpp/src/managers/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0030/errors.dart'; import 'package:moxxmpp/src/xeps/xep_0030/types.dart'; import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart'; @@ -58,10 +58,10 @@ class HttpFileUploadManager extends XmppManagerBase { /// Returns whether the entity provided an identity that tells us that we can ask it /// for an HTTP upload slot. bool _containsFileUploadIdentity(DiscoInfo info) { - return listContains( - info.identities, - (Identity id) => id.category == 'store' && id.type == 'file', - ); + return info.identities.firstWhereOrNull( + (Identity id) => id.category == 'store' && id.type == 'file', + ) != + null; } /// Extract the maximum filesize in octets from the disco response. Returns null diff --git a/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart b/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart index e02a014..b94537d 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:meta/meta.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/managers/base.dart'; @@ -10,7 +11,6 @@ import 'package:moxxmpp/src/managers/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0030/errors.dart'; import 'package:moxxmpp/src/xeps/xep_0030/types.dart'; import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart'; @@ -205,15 +205,18 @@ abstract class BaseOmemoManager extends XmppManagerBase { ) { final keyElements = >{}; for (final keys in result.encryptedKeys.entries) { - keyElements[keys.key] = keys.value.map((ek) => XMLNode( - tag: 'key', - attributes: { - 'rid': ek.rid.toString(), - if (ek.kex) - 'kex': 'true', - }, - text: ek.value, - ),).toList(); + keyElements[keys.key] = keys.value + .map( + (ek) => XMLNode( + tag: 'key', + attributes: { + 'rid': ek.rid.toString(), + if (ek.kex) 'kex': 'true', + }, + text: ek.value, + ), + ) + .toList(); } final keysElements = keyElements.entries.map((entry) { @@ -235,7 +238,6 @@ abstract class BaseOmemoManager extends XmppManagerBase { tag: 'payload', text: base64Encode(result.ciphertext!), ), - XMLNode( tag: 'header', attributes: { @@ -364,8 +366,8 @@ abstract class BaseOmemoManager extends XmppManagerBase { ..cancel = true // If we have no device list for toJid, then the contact most likely does not // support OMEMO:2 - ..cancelReason = result.deviceEncryptionErrors[toJid.toString()]!.first.error - is omemo.NoKeyMaterialAvailableError + ..cancelReason = result.deviceEncryptionErrors[toJid.toString()]!.first + .error is omemo.NoKeyMaterialAvailableError ? OmemoNotSupportedForContactException() : UnknownOmemoError() // TODO @@ -578,7 +580,8 @@ abstract class BaseOmemoManager extends XmppManagerBase { /// nodes. /// /// On success, returns true. On failure, returns an OmemoError. - Future> publishBundle(omemo.OmemoBundle bundle) async { + Future> publishBundle( + omemo.OmemoBundle bundle,) async { final attrs = getAttributes(); final pm = attrs.getManagerById(pubsubManager)!; final bareJid = attrs.getFullJID().toBare(); @@ -651,7 +654,7 @@ abstract class BaseOmemoManager extends XmppManagerBase { /// On failure, returns an OmemoError. Future> supportsOmemo(JID jid) async { final dm = getAttributes().getManagerById(discoManager)!; - final items = await dm.discoItemsQuery(jid.toBare(), shouldEncrypt: false); + final items = await dm.discoItemsQuery(jid.toBare()); if (items.isType()) return Result(UnknownOmemoError()); diff --git a/packages/moxxmpp/lib/src/xeps/xep_0386.dart b/packages/moxxmpp/lib/src/xeps/xep_0386.dart index 4f61add..ad2fbfa 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0386.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0386.dart @@ -1,10 +1,10 @@ import 'package:collection/collection.dart'; import 'package:meta/meta.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/negotiators/namespaces.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0388/negotiators.dart'; import 'package:moxxmpp/src/xeps/xep_0388/xep_0388.dart'; diff --git a/packages/moxxmpp/lib/src/xeps/xep_0388/negotiators.dart b/packages/moxxmpp/lib/src/xeps/xep_0388/negotiators.dart index 948930f..24af826 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0388/negotiators.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0388/negotiators.dart @@ -1,7 +1,7 @@ +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/rfcs/rfc_6120/sasl/negotiator.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; /// A special type of [XmppFeatureNegotiatorBase] that is aware of SASL2. abstract class Sasl2FeatureNegotiator extends XmppFeatureNegotiatorBase { diff --git a/packages/moxxmpp/lib/src/xeps/xep_0388/xep_0388.dart b/packages/moxxmpp/lib/src/xeps/xep_0388/xep_0388.dart index e871c03..9e56694 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0388/xep_0388.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0388/xep_0388.dart @@ -1,10 +1,10 @@ +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/negotiators/namespaces.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/rfcs/rfc_6120/sasl/errors.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0388/errors.dart'; import 'package:moxxmpp/src/xeps/xep_0388/negotiators.dart'; import 'package:moxxmpp/src/xeps/xep_0388/user_agent.dart'; diff --git a/packages/moxxmpp/lib/src/xeps/xep_0447.dart b/packages/moxxmpp/lib/src/xeps/xep_0447.dart index 36bf848..d29ce5d 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0447.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0447.dart @@ -1,4 +1,4 @@ -import 'package:moxlib/moxlib.dart'; +import 'package:collection/collection.dart'; import 'package:moxxmpp/src/managers/base.dart'; import 'package:moxxmpp/src/managers/data.dart'; import 'package:moxxmpp/src/managers/handlers.dart'; @@ -114,8 +114,7 @@ class StatelessFileSharingData implements StanzaHandlerExtension { } StatelessFileSharingUrlSource? getFirstUrlSource() { - return firstWhereOrNull( - sources, + return sources.firstWhereOrNull( (StatelessFileSharingSource source) => source is StatelessFileSharingUrlSource, ) as StatelessFileSharingUrlSource?; diff --git a/packages/moxxmpp/lib/src/xeps/xep_0448.dart b/packages/moxxmpp/lib/src/xeps/xep_0448.dart index 545bd3d..a6a829b 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0448.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0448.dart @@ -1,5 +1,5 @@ import 'dart:convert'; -import 'package:moxlib/moxlib.dart'; +import 'package:collection/collection.dart'; import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/xeps/xep_0300.dart'; @@ -54,8 +54,7 @@ class StatelessFileSharingEncryptedSource extends StatelessFileSharingSource { final sources = element.firstTag('sources', xmlns: sfsXmlns)!.children; // Find the first URL source - final source = firstWhereOrNull( - sources, + final source = sources.firstWhereOrNull( (XMLNode child) => child.tag == 'url-data' && child.attributes['xmlns'] == urlDataXmlns, )!; diff --git a/packages/moxxmpp/lib/src/xeps/xep_0449.dart b/packages/moxxmpp/lib/src/xeps/xep_0449.dart index b32aa3c..26bfc3c 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0449.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0449.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/managers/base.dart'; import 'package:moxxmpp/src/managers/data.dart'; @@ -9,7 +10,6 @@ import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/rfcs/rfc_4790.dart'; import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stringxml.dart'; -import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/util/typed_map.dart'; import 'package:moxxmpp/src/xeps/xep_0060/errors.dart'; import 'package:moxxmpp/src/xeps/xep_0060/xep_0060.dart'; diff --git a/packages/moxxmpp/test/negotiator_test.dart b/packages/moxxmpp/test/negotiator_test.dart index 15de453..622cad5 100644 --- a/packages/moxxmpp/test/negotiator_test.dart +++ b/packages/moxxmpp/test/negotiator_test.dart @@ -1,6 +1,8 @@ +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/moxxmpp.dart'; import 'package:moxxmpp/src/parser.dart'; import 'package:test/test.dart'; + import 'helpers/logging.dart'; const exampleXmlns1 = 'im:moxxmpp:example1'; diff --git a/packages/moxxmpp/test/xeps/xep_0060_test.dart b/packages/moxxmpp/test/xeps/xep_0060_test.dart index da31d14..0aaf10b 100644 --- a/packages/moxxmpp/test/xeps/xep_0060_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0060_test.dart @@ -1,3 +1,4 @@ +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/moxxmpp.dart'; import 'package:test/test.dart'; diff --git a/packages/moxxmpp/test/xeps/xep_0115_test.dart b/packages/moxxmpp/test/xeps/xep_0115_test.dart index 10ef205..46c073b 100644 --- a/packages/moxxmpp/test/xeps/xep_0115_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0115_test.dart @@ -1,3 +1,4 @@ +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/moxxmpp.dart'; import 'package:test/test.dart'; diff --git a/packages/moxxmpp/test/xeps/xep_0388_test.dart b/packages/moxxmpp/test/xeps/xep_0388_test.dart index f11e98a..8fa81ab 100644 --- a/packages/moxxmpp/test/xeps/xep_0388_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0388_test.dart @@ -1,6 +1,8 @@ import 'package:collection/collection.dart'; +import 'package:moxlib/moxlib.dart'; import 'package:moxxmpp/moxxmpp.dart'; import 'package:test/test.dart'; + import '../helpers/logging.dart'; import '../helpers/xmpp.dart';