Compare commits

..

No commits in common. "4f9a0605c7b94789910a9de19e05768540146f36" and "29a5417b310a800ace4f9b059f6c5d521b8077ef" have entirely different histories.

50 changed files with 194 additions and 463 deletions

View File

@ -30,12 +30,11 @@ class EchoMessageManager extends XmppManagerBase {
StanzaHandlerData state,
) async {
final body = stanza.firstTag('body');
if (body == null) return state..done = true;
if (body == null) return state.copyWith(done: true);
final bodyText = body.innerText();
await getAttributes().sendStanza(
StanzaDetails(
Stanza.message(
to: stanza.from,
children: [
@ -46,10 +45,9 @@ class EchoMessageManager extends XmppManagerBase {
],
),
awaitable: false,
),
);
return state..done = true;
return state.copyWith(done: true);
}
}

View File

@ -1,116 +0,0 @@
import 'package:chalkdart/chalk.dart';
import 'package:cli_repl/cli_repl.dart';
import 'package:example_dart/arguments.dart';
import 'package:example_dart/socket.dart';
import 'package:logging/logging.dart';
import 'package:moxxmpp/moxxmpp.dart';
import 'package:omemo_dart/omemo_dart.dart' as omemo;
void main(List<String> args) async {
// Set up logging
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
// ignore: avoid_print
print(
'[${record.level.name}] (${record.loggerName}) ${record.time}: ${record.message}',
);
});
final parser = ArgumentParser()
..parser.addOption('to', help: 'The JID to send messages to');
final options = parser.handleArguments(args);
if (options == null) {
return;
}
// Connect
final jid = parser.jid;
final to = JID.fromString(options['to']! as String).toBare();
final connection = XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(),
ExampleTCPSocketWrapper(parser.srvRecord),
)..connectionSettings = parser.connectionSettings;
// Generate OMEMO data
omemo.OmemoManager? oom;
final moxxmppOmemo = OmemoManager(
() async => oom!,
(toJid, _) async => toJid == to,
);
oom = omemo.OmemoManager(
await omemo.OmemoDevice.generateNewDevice(jid.toString(), opkAmount: 5),
omemo.BlindTrustBeforeVerificationTrustManager(),
moxxmppOmemo.sendEmptyMessageImpl,
moxxmppOmemo.fetchDeviceList,
moxxmppOmemo.fetchDeviceBundle,
moxxmppOmemo.subscribeToDeviceListImpl,
moxxmppOmemo.publishDeviceImpl,
);
final deviceId = await oom.getDeviceId();
Logger.root.info('Our device id: $deviceId');
// Register the managers and negotiators
await connection.registerManagers([
PresenceManager(),
DiscoManager([]),
PubSubManager(),
MessageManager(),
moxxmppOmemo,
]);
await connection.registerFeatureNegotiators([
SaslPlainNegotiator(),
ResourceBindingNegotiator(),
StartTlsNegotiator(),
SaslScramNegotiator(10, '', '', ScramHashType.sha1),
]);
// Set up event handlers
connection.asBroadcastStream().listen((event) {
if (event is MessageEvent) {
Logger.root.info(event.id);
Logger.root.info(event.extensions.keys.toList());
final body = event.encryptionError != null
? chalk.red('Failed to decrypt message: ${event.encryptionError}')
: chalk.green(event.get<MessageBodyData>()?.body ?? '');
print('[${event.from.toString()}] $body');
}
});
// Connect
Logger.root.info('Connecting...');
final result =
await connection.connect(shouldReconnect: false, waitUntilLogin: true);
if (!result.isType<bool>()) {
Logger.root.severe('Authentication failed!');
return;
}
Logger.root.info('Connected.');
// Publish our bundle
Logger.root.info('Publishing bundle');
final device = await oom.getDevice();
final omemoResult = await moxxmppOmemo.publishBundle(await device.toBundle());
if (!omemoResult.isType<bool>()) {
Logger.root.severe(
'Failed to publish OMEMO bundle: ${omemoResult.get<OmemoError>()}');
return;
}
final repl = Repl(prompt: '> ');
await for (final line in repl.runAsync()) {
await connection
.getManagerById<MessageManager>(messageManager)!
.sendMessage(
to,
TypedMap<StanzaHandlerExtension>.fromList([
MessageBodyData(line),
]),
);
}
// Disconnect
await connection.disconnect();
}

View File

@ -1,84 +0,0 @@
import 'package:args/args.dart';
import 'package:chalkdart/chalk.dart';
import 'package:moxxmpp/moxxmpp.dart';
import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
extension StringToInt on String {
int toInt() => int.parse(this);
}
/// A wrapper around [ArgParser] for providing convenience functions and standard parameters
/// to the examples.
class ArgumentParser {
ArgumentParser() {
parser
..addOption('jid', help: 'The JID to connect as')
..addOption('password', help: 'The password to use for authenticating')
..addOption('host',
help:
'The host address to connect to (By default uses the domain part of the JID)')
..addOption('port', help: 'The port to connect to')
..addOption('xmpps-srv',
help:
'Inject a SRV record for _xmpps-client._tcp. Format: <priority>,<weight>,<target>,<port>')
..addFlag('help',
abbr: 'h',
negatable: false,
defaultsTo: false,
help: 'Show this help text');
}
/// The [ArgParser] that handles parsing the arguments.
final ArgParser parser = ArgParser();
/// The parsed options. Only valid after calling [handleArguments].
late ArgResults options;
ArgResults? handleArguments(List<String> args) {
options = parser.parse(args);
if (options['help']!) {
print(parser.usage);
return null;
}
if (options['jid'] == null) {
print(chalk.red('No JID specified'));
print(parser.usage);
return null;
}
if (options['password'] == null) {
print(chalk.red('No password specified'));
print(parser.usage);
return null;
}
return options;
}
/// The JID to connect as.
JID get jid => JID.fromString(options['jid']!).toBare();
/// Construct connection settings from the parsed options.
ConnectionSettings get connectionSettings => ConnectionSettings(
jid: jid,
password: options['password']!,
host: options['host'],
port: (options['port'] as String?)?.toInt(),
);
/// Construct an xmpps-client SRV record for injection, if specified.
MoxSrvRecord? get srvRecord {
if (options['xmpps-srv'] == null) {
return null;
}
final parts = options['xmpps-srv']!.split(',');
return MoxSrvRecord(
int.parse(parts[0]),
int.parse(parts[1]),
parts[2],
int.parse(parts[3]),
);
}
}

View File

@ -1,22 +0,0 @@
import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
/// A simple socket for examples that allows injection of SRV records (since
/// we cannot use moxdns here).
class ExampleTCPSocketWrapper extends TCPSocketWrapper {
ExampleTCPSocketWrapper(this.srvRecord);
/// A potential SRV record to inject for testing.
final MoxSrvRecord? srvRecord;
@override
bool onBadCertificate(dynamic certificate, String domain) {
return true;
}
@override
Future<List<MoxSrvRecord>> srvQuery(String domain, bool dnssec) async {
return [
if (srvRecord != null) srvRecord!,
];
}
}

View File

@ -7,9 +7,6 @@ environment:
sdk: '>=2.18.0 <3.0.0'
dependencies:
args: 2.4.1
chalkdart: 2.0.9
cli_repl: 0.2.3
logging: ^1.0.2
moxxmpp:
hosted: https://git.polynom.me/api/packages/Moxxy/pub
@ -17,9 +14,6 @@ dependencies:
moxxmpp_socket_tcp:
hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: 0.3.1
omemo_dart:
hosted: https://git.polynom.me/api/packages/PapaTutuWawa/pub
version: ^0.5.0
dependency_overrides:
moxxmpp:

View File

@ -1,2 +0,0 @@
prosodyctl --config ./prosody.cfg.lua register testuser1 localhost abc123
prosodyctl --config ./prosody.cfg.lua register testuser2 localhost abc123

View File

@ -16,7 +16,6 @@
- **BREAKING**: `MessageEvent` now makes use of `TypedMap`.
- **BREAKING**: Removed `PresenceReceivedEvent`. Use a manager registering handlers with priority greater than `[PresenceManager.presenceHandlerPriority]` instead.
- **BREAKING**: `ChatState.toString()` is now `ChatState.toName()`
- **BREAKING**: Overriding `BaseOmemoManager` is no longer required. `OmemoManager` now takes callback methods instead.
## 0.3.1

View File

@ -38,6 +38,7 @@ 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';

View File

@ -25,6 +25,7 @@ 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';
@ -478,7 +479,6 @@ class XmppConnection {
newStanza,
TypedMap(),
encrypted: details.encrypted,
shouldEncrypt: details.shouldEncrypt,
forceEncryption: details.forceEncryption,
),
);
@ -736,13 +736,6 @@ class XmppConnection {
: '';
_log.finest('<== $prefix${incomingPreHandlers.stanza.toXml()}');
if (incomingPreHandlers.skip) {
_log.fine(
'Not processing stanza (${incomingPreHandlers.stanza.tag}, ${incomingPreHandlers.stanza.id}) due to skip=true.',
);
return;
}
final awaited = await _stanzaAwaiter.onData(
incomingPreHandlers.stanza,
connectionSettings.jid.toBare(),
@ -760,7 +753,6 @@ class XmppConnection {
incomingPreHandlers.stanza,
incomingPreHandlers.extensions,
encrypted: incomingPreHandlers.encrypted,
encryptionError: incomingPreHandlers.encryptionError,
cancelReason: incomingPreHandlers.cancelReason,
),
);

View File

@ -70,9 +70,9 @@ class MessageEvent extends XmppEvent {
MessageEvent(
this.from,
this.to,
this.id,
this.encrypted,
this.extensions, {
this.id,
this.type,
this.error,
this.encryptionError,
@ -85,7 +85,7 @@ class MessageEvent extends XmppEvent {
final JID to;
/// The id attribute of the message.
final String? id;
final String id;
/// The type attribute of the message.
final String? type;

View File

@ -47,6 +47,7 @@ abstract class XmppManagerBase {
final result = await dm!.discoInfoQuery(
_managerAttributes.getConnectionSettings().jid.toDomain(),
shouldEncrypt: false,
);
if (result.isType<DiscoError>()) {
return false;

View File

@ -13,20 +13,12 @@ class StanzaHandlerData {
this.encryptionError,
this.encrypted = false,
this.forceEncryption = false,
this.shouldEncrypt = true,
this.skip = false,
});
/// Indicates to the runner that processing is now done. This means that all
/// pre-processing is done and no other handlers should be consulted.
bool done;
/// Only useful in combination with [done] = true: When [skip] is set to true and
/// this [StanzaHandlerData] object is returned from a IncomingPreStanzaHandler, then
/// moxxmpp will skip checking whether the stanza was awaited and will not run any actual
/// IncomingStanzaHandler callbacks.
bool skip;
/// Indicates to the runner that processing is to be cancelled and no further handlers
/// should run. The stanza also will not be sent.
bool cancel;
@ -41,7 +33,7 @@ class StanzaHandlerData {
/// absolutely necessary, e.g. with Message Carbons or OMEMO.
Stanza stanza;
/// Whether the stanza is already encrypted
/// Whether the stanza was received encrypted
bool encrypted;
// If true, forces the encryption manager to encrypt to the JID, even if it
@ -50,10 +42,6 @@ class StanzaHandlerData {
// to the JID anyway.
bool forceEncryption;
/// Flag indicating whether a E2EE implementation should encrypt the stanza (true)
/// or not (false).
bool shouldEncrypt;
/// Additional data from other managers.
final TypedMap<StanzaHandlerExtension> extensions;
}

View File

@ -1,4 +1,4 @@
import 'package:collection/collection.dart';
import 'package:moxlib/moxlib.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 &= node.children.firstWhereOrNull(
matches &= listContains(
node.children,
(XMLNode node_) => node_.attributes['xmlns'] == tagXmlns,
) !=
null;
);
}
return matches;

View File

@ -73,23 +73,16 @@ class MessageManager extends XmppManagerBase {
Future<bool> isSupported() async => true;
Future<StanzaHandlerData> _onMessage(
Stanza stanza,
Stanza _,
StanzaHandlerData state,
) async {
final body = stanza.firstTag('body');
if (body != null) {
state.extensions.set(
MessageBodyData(body.innerText()),
);
}
getAttributes().sendEvent(
MessageEvent(
JID.fromString(state.stanza.attributes['from']! as String),
JID.fromString(state.stanza.attributes['to']! as String),
state.stanza.attributes['id']! as String,
state.encrypted,
state.extensions,
id: state.stanza.attributes['id'] as String?,
type: state.stanza.attributes['type'] as String?,
error: StanzaError.fromStanza(state.stanza),
encryptionError: state.encryptionError,

View File

@ -1,4 +1,3 @@
import 'package:collection/collection.dart';
import 'package:meta/meta.dart';
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/connection.dart';
@ -9,6 +8,7 @@ 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,7 +117,8 @@ abstract class XmppFeatureNegotiatorBase {
/// Returns true if a feature in [features], which are the children of the
/// <stream:features /> nonza, can be negotiated. Otherwise, returns false.
bool matchesFeature(List<XMLNode> features) {
return features.firstWhereOrNull(
return firstWhereOrNull(
features,
(XMLNode feature) => feature.attributes['xmlns'] == negotiatingXmlns,
) !=
null;

View File

@ -1,5 +1,4 @@
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';
@ -11,6 +10,7 @@ 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

View File

@ -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';

View File

@ -1,4 +1,4 @@
import 'package:collection/collection.dart';
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/negotiators/negotiator.dart';
import 'package:moxxmpp/src/stringxml.dart';
@ -13,13 +13,15 @@ abstract class SaslNegotiator extends XmppFeatureNegotiatorBase {
@override
bool matchesFeature(List<XMLNode> features) {
// Is SASL advertised?
final mechanisms = features.firstWhereOrNull(
final mechanisms = firstWhereOrNull(
features,
(XMLNode feature) => feature.attributes['xmlns'] == saslXmlns,
);
if (mechanisms == null) return false;
// Is SASL PLAIN advertised?
return mechanisms.children.firstWhereOrNull(
return firstWhereOrNull(
mechanisms.children,
(XMLNode mechanism) => mechanism.text == mechanismName,
) !=
null;

View File

@ -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';

View File

@ -2,7 +2,6 @@ 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';
@ -11,6 +10,7 @@ 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';

View File

@ -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 }

View File

@ -1,7 +1,6 @@
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';
@ -15,6 +14,7 @@ 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 {

View File

@ -7,7 +7,6 @@ class StanzaDetails {
this.stanza, {
this.addId = true,
this.awaitable = true,
this.shouldEncrypt = true,
this.encrypted = false,
this.forceEncryption = false,
this.bypassQueue = false,
@ -23,16 +22,9 @@ class StanzaDetails {
/// Track the stanza to allow awaiting its response.
final bool awaitable;
final bool forceEncryption;
/// Flag indicating whether the stanza that is sent is already encrypted (true)
/// or not (false). This is only useful for E2EE implementations that have to
/// send heartbeats that must bypass themselves.
final bool encrypted;
/// Tells an E2EE implementation, if available, to encrypt the stanza (true) or
/// ignore the stanza (false).
final bool shouldEncrypt;
final bool forceEncryption;
/// Bypasses being put into the queue. Useful for sending stanzas that must go out
/// now, where it's okay if it does not get sent.

View File

@ -0,0 +1,16 @@
class Result<T, V> {
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<S>() => _data is S;
S get<S>() {
assert(_data is S, 'Data is not $S');
return _data as S;
}
}

View File

@ -33,7 +33,7 @@ class AsyncStanzaQueue {
this._canSendCallback,
);
/// The lock for accessing [AsyncStanzaQueue._queue].
/// The lock for accessing [AsyncStanzaQueue._lock] and [AsyncStanzaQueue._running].
final Lock _lock = Lock();
/// The actual job queue.
@ -44,15 +44,22 @@ class AsyncStanzaQueue {
final CanSendCallback _canSendCallback;
/// Indicates whether we are currently executing a job.
bool _running = false;
@visibleForTesting
Queue<StanzaQueueEntry> get queue => _queue;
@visibleForTesting
bool get isRunning => _running;
/// Adds a job [entry] to the queue.
Future<void> enqueueStanza(StanzaQueueEntry entry) async {
await _lock.synchronized(() async {
_queue.add(entry);
if (_queue.isNotEmpty && await _canSendCallback()) {
if (!_running && _queue.isNotEmpty && await _canSendCallback()) {
_running = true;
unawaited(
_runJob(_queue.removeFirst()),
);
@ -72,6 +79,8 @@ class AsyncStanzaQueue {
unawaited(
_runJob(_queue.removeFirst()),
);
} else {
_running = false;
}
});
}
@ -81,6 +90,7 @@ class AsyncStanzaQueue {
await _lock.synchronized(() {
if (_queue.isNotEmpty) {
_running = true;
unawaited(
_runJob(_queue.removeFirst()),
);

View File

@ -20,6 +20,4 @@ class TypedMap<B> {
/// Return the object of type [T] from the map, if it has been stored.
T? get<T>() => _data[T] as T?;
Iterable<Object> get keys => _data.keys;
}

View File

@ -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';

View File

@ -1,4 +1,4 @@
import 'package:collection/collection.dart';
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/stringxml.dart';
@ -80,7 +80,7 @@ class DataForm {
final List<List<DataFormField>> items;
DataFormField? getFieldByVar(String varAttr) {
return fields.firstWhereOrNull((field) => field.varAttr == varAttr);
return firstWhereOrNull(fields, (field) => field.varAttr == varAttr);
}
XMLNode toXml() {

View File

@ -1,6 +1,5 @@
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';
@ -10,6 +9,7 @@ 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';
@ -255,7 +255,7 @@ class DiscoManager extends XmppManagerBase {
Future<Result<DiscoError, DiscoInfo>> discoInfoQuery(
JID entity, {
String? node,
bool shouldEncrypt = false,
bool shouldEncrypt = true,
bool shouldCache = true,
}) async {
DiscoInfo? info;
@ -294,7 +294,7 @@ class DiscoManager extends XmppManagerBase {
final stanza = (await getAttributes().sendStanza(
StanzaDetails(
buildDiscoInfoQueryStanza(entity, node),
shouldEncrypt: shouldEncrypt,
encrypted: !shouldEncrypt,
),
))!;
final query = stanza.firstTag('query');
@ -325,7 +325,7 @@ class DiscoManager extends XmppManagerBase {
Future<Result<DiscoError, List<DiscoItem>>> discoItemsQuery(
JID entity, {
String? node,
bool shouldEncrypt = false,
bool shouldEncrypt = true,
}) async {
final key = DiscoCacheKey(entity, node);
final future = await _discoItemsTracker.waitFor(key);

View File

@ -1,4 +1,3 @@
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/events.dart';
import 'package:moxxmpp/src/jid.dart';
import 'package:moxxmpp/src/managers/base.dart';
@ -8,6 +7,7 @@ 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 {}

View File

@ -1,6 +1,5 @@
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';
@ -10,6 +9,7 @@ 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';
@ -202,7 +202,6 @@ class PubSubManager extends XmppManagerBase {
),
],
),
shouldEncrypt: false,
),
))!;
@ -246,7 +245,6 @@ class PubSubManager extends XmppManagerBase {
),
],
),
shouldEncrypt: false,
),
))!;
@ -331,7 +329,6 @@ class PubSubManager extends XmppManagerBase {
)
],
),
shouldEncrypt: false,
),
))!;
if (result.attributes['type'] != 'result') {
@ -422,7 +419,6 @@ class PubSubManager extends XmppManagerBase {
)
],
),
shouldEncrypt: false,
),
))!;
@ -475,7 +471,6 @@ class PubSubManager extends XmppManagerBase {
),
],
),
shouldEncrypt: false,
),
))!;
@ -526,7 +521,6 @@ class PubSubManager extends XmppManagerBase {
),
],
),
shouldEncrypt: false,
),
))!;
if (form.attributes['type'] != 'result') {
@ -556,7 +550,6 @@ class PubSubManager extends XmppManagerBase {
),
],
),
shouldEncrypt: false,
),
))!;
if (submit.attributes['type'] != 'result') {
@ -587,7 +580,6 @@ class PubSubManager extends XmppManagerBase {
),
],
),
shouldEncrypt: false,
),
))!;
@ -632,7 +624,6 @@ class PubSubManager extends XmppManagerBase {
),
],
),
shouldEncrypt: false,
),
))!;

View File

@ -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,6 +225,7 @@ class UserAvatarManager extends XmppManagerBase {
final response = await disco.discoItemsQuery(
jid,
node: userAvatarDataXmlns,
shouldEncrypt: false,
);
if (response.isType<DiscoError>()) return Result(UnknownAvatarError());

View File

@ -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';

View File

@ -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 {

View File

@ -1,4 +1,3 @@
import 'package:collection/collection.dart';
import 'package:meta/meta.dart';
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/events.dart';
@ -8,6 +7,7 @@ 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 info.identities.firstWhereOrNull(
return listContains(
info.identities,
(Identity id) => id.category == 'store' && id.type == 'file',
) !=
null;
);
}
/// Extract the maximum filesize in octets from the disco response. Returns null

View File

@ -13,8 +13,9 @@ class DoNotEncrypt {
/// An encryption error caused by OMEMO.
class OmemoEncryptionError {
const OmemoEncryptionError(this.deviceEncryptionErrors);
const OmemoEncryptionError(this.jids, this.devices);
/// See omemo_dart's EncryptionResult for info on this field.
final Map<String, List<EncryptToJidError>> deviceEncryptionErrors;
/// See omemo_dart's EncryptionResult for info on these fields.
final Map<String, OmemoException> jids;
final Map<RatchetMapKey, OmemoException> devices;
}

View File

@ -1,7 +1,6 @@
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';
@ -11,11 +10,13 @@ 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';
import 'package:moxxmpp/src/xeps/xep_0060/errors.dart';
import 'package:moxxmpp/src/xeps/xep_0060/xep_0060.dart';
import 'package:moxxmpp/src/xeps/xep_0203.dart';
import 'package:moxxmpp/src/xeps/xep_0280.dart';
import 'package:moxxmpp/src/xeps/xep_0334.dart';
import 'package:moxxmpp/src/xeps/xep_0380.dart';
@ -23,21 +24,9 @@ import 'package:moxxmpp/src/xeps/xep_0384/crypto.dart';
import 'package:moxxmpp/src/xeps/xep_0384/errors.dart';
import 'package:moxxmpp/src/xeps/xep_0384/helpers.dart';
import 'package:moxxmpp/src/xeps/xep_0384/types.dart';
import 'package:omemo_dart/omemo_dart.dart' as omemo;
import 'package:omemo_dart/omemo_dart.dart';
import 'package:xml/xml.dart';
/// A callback that is executed whenever we need to acquire the OmemoManager backing
/// the manager.
typedef GetOmemoManagerCallback = Future<omemo.OmemoManager> Function();
/// A callback for figuring out whether a stanza should be encrypted or not. Note that
/// returning true here does not necessarily mean that a stanza gets encrypted because
/// handlers can indicate that a stanza should not be encrypted, e.g. PubSub.
typedef ShouldEncryptStanzaCallback = Future<bool> Function(
JID toJid,
Stanza stanza,
);
const _doNotEncryptList = [
// XEP-0033
DoNotEncrypt('addresses', extendedAddressingXmlns),
@ -54,15 +43,8 @@ const _doNotEncryptList = [
DoNotEncrypt('stanza-id', stableIdXmlns),
];
class OmemoManager extends XmppManagerBase {
OmemoManager(this._getOmemoManager, this._shouldEncryptStanza)
: super(omemoManager);
/// Callback for getting the [omemo.OmemoManager].
final GetOmemoManagerCallback _getOmemoManager;
/// Callback for checking whether a stanza should be encrypted or not.
final ShouldEncryptStanzaCallback _shouldEncryptStanza;
abstract class BaseOmemoManager extends XmppManagerBase {
BaseOmemoManager() : super(omemoManager);
// TODO(Unknown): Technically, this is not always true
@override
@ -131,19 +113,22 @@ class OmemoManager extends XmppManagerBase {
}
// Tell the OmemoManager
await (await _getOmemoManager()).onDeviceListUpdate(jid.toString(), ids);
(await getOmemoManager()).onDeviceListUpdate(jid.toString(), ids);
// Generate an event
getAttributes().sendEvent(OmemoDeviceListUpdatedEvent(jid, ids));
}
}
/// Wrapper around using getSessionManager and then calling getDeviceId on it.
Future<int> _getDeviceId() async => (await _getOmemoManager()).getDeviceId();
@visibleForOverriding
Future<OmemoManager> getOmemoManager();
/// Wrapper around using getSessionManager and then calling getDeviceId on it.
Future<omemo.OmemoBundle> _getDeviceBundle() async {
final om = await _getOmemoManager();
Future<int> _getDeviceId() async => (await getOmemoManager()).getDeviceId();
/// Wrapper around using getSessionManager and then calling getDeviceId on it.
Future<OmemoBundle> _getDeviceBundle() async {
final om = await getOmemoManager();
final device = await om.getDevice();
return device.toBundle();
}
@ -214,45 +199,53 @@ class OmemoManager extends XmppManagerBase {
}
XMLNode _buildEncryptedElement(
omemo.EncryptionResult result,
EncryptionResult result,
String recipientJid,
int deviceId,
) {
final keyElements = <String, List<XMLNode>>{};
for (final keys in result.encryptedKeys.entries) {
keyElements[keys.key] = keys.value
.map(
(ek) => XMLNode(
for (final key in result.encryptedKeys) {
final keyElement = XMLNode(
tag: 'key',
attributes: {
'rid': ek.rid.toString(),
if (ek.kex) 'kex': 'true',
attributes: <String, String>{
'rid': '${key.rid}',
'kex': key.kex ? 'true' : 'false',
},
text: ek.value,
),
)
.toList();
text: key.value,
);
if (keyElements.containsKey(key.jid)) {
keyElements[key.jid]!.add(keyElement);
} else {
keyElements[key.jid] = [keyElement];
}
}
final keysElements = keyElements.entries.map((entry) {
return XMLNode(
tag: 'keys',
attributes: {
attributes: <String, String>{
'jid': entry.key,
},
children: entry.value,
);
}).toList();
var payloadElement = <XMLNode>[];
if (result.ciphertext != null) {
payloadElement = [
XMLNode(
tag: 'payload',
text: base64.encode(result.ciphertext!),
),
];
}
return XMLNode.xmlns(
tag: 'encrypted',
xmlns: omemoXmlns,
children: [
if (result.ciphertext != null)
XMLNode(
tag: 'payload',
text: base64Encode(result.ciphertext!),
),
...payloadElement,
XMLNode(
tag: 'header',
attributes: <String, String>{
@ -266,7 +259,7 @@ class OmemoManager extends XmppManagerBase {
/// For usage with omemo_dart's OmemoManager.
Future<void> sendEmptyMessageImpl(
omemo.EncryptionResult result,
EncryptionResult result,
String toJid,
) async {
await getAttributes().sendStanza(
@ -295,7 +288,7 @@ class OmemoManager extends XmppManagerBase {
/// Send a heartbeat message to [jid].
Future<void> sendOmemoHeartbeat(String jid) async {
final om = await _getOmemoManager();
final om = await getOmemoManager();
await om.sendOmemoHeartbeat(jid);
}
@ -308,22 +301,17 @@ class OmemoManager extends XmppManagerBase {
}
/// For usage with omemo_dart's OmemoManager
Future<omemo.OmemoBundle?> fetchDeviceBundle(String jid, int id) async {
Future<OmemoBundle?> fetchDeviceBundle(String jid, int id) async {
final result = await retrieveDeviceBundle(JID.fromString(jid), id);
if (result.isType<OmemoError>()) return null;
return result.get<omemo.OmemoBundle>();
return result.get<OmemoBundle>();
}
Future<StanzaHandlerData> _onOutgoingStanza(
Stanza stanza,
StanzaHandlerData state,
) async {
if (!state.shouldEncrypt) {
logger.finest('Not encrypting since state.shouldEncrypt is false');
return state;
}
if (state.encrypted) {
logger.finest('Not encrypting since state.encrypted is true');
return state;
@ -336,7 +324,7 @@ class OmemoManager extends XmppManagerBase {
}
final toJid = JID.fromString(stanza.to!).toBare();
final shouldEncryptResult = await _shouldEncryptStanza(toJid, stanza);
final shouldEncryptResult = await shouldEncryptStanza(toJid, stanza);
if (!shouldEncryptResult && !state.forceEncryption) {
logger.finest(
'Not encrypting stanza for $toJid: Both shouldEncryptStanza and forceEncryption are false.',
@ -363,29 +351,29 @@ class OmemoManager extends XmppManagerBase {
.getManagerById<CarbonsManager>(carbonsManager)
?.isEnabled ??
false;
final om = await _getOmemoManager();
final encryptToJids = [
final om = await getOmemoManager();
final result = await om.onOutgoingStanza(
OmemoOutgoingStanza(
[
toJid.toString(),
if (carbonsEnabled) getAttributes().getFullJID().toBare().toString(),
];
final result = await om.onOutgoingStanza(
omemo.OmemoOutgoingStanza(
encryptToJids,
],
_buildEnvelope(toEncrypt, toJid.toString()),
),
);
logger.finest('Encryption done');
if (!result.canSend) {
if (!result.isSuccess(2)) {
return state
..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.jidEncryptionErrors[toJid.toString()]
is NoKeyMaterialAvailableException
? OmemoNotSupportedForContactException()
: UnknownOmemoError()
..encryptionError = OmemoEncryptionError(
result.jidEncryptionErrors,
result.deviceEncryptionErrors,
);
}
@ -413,45 +401,53 @@ class OmemoManager extends XmppManagerBase {
..encrypted = true;
}
/// This function is called whenever a message is to be encrypted. If it returns true,
/// then the message will be encrypted. If it returns false, the message won't be
/// encrypted.
@visibleForOverriding
Future<bool> shouldEncryptStanza(JID toJid, Stanza stanza);
Future<StanzaHandlerData> _onIncomingStanza(
Stanza stanza,
StanzaHandlerData state,
) async {
final encrypted = stanza.firstTag('encrypted', xmlns: omemoXmlns);
if (encrypted == null) return state;
if (stanza.from == null) return state;
final encrypted = stanza.firstTag('encrypted', xmlns: omemoXmlns)!;
final fromJid = JID.fromString(stanza.from!).toBare();
final header = encrypted.firstTag('header')!;
final ourJid = getAttributes().getFullJID();
final ourJidString = ourJid.toBare().toString();
final keys = List<omemo.EncryptedKey>.empty(growable: true);
final payloadElement = encrypted.firstTag('payload');
final keys = List<EncryptedKey>.empty(growable: true);
for (final keysElement in header.findTags('keys')) {
// We only care about our own JID
final jid = keysElement.attributes['jid']! as String;
if (jid != ourJidString) {
continue;
}
keys.addAll(
keysElement.findTags('key').map(
(key) => omemo.EncryptedKey(
for (final key in keysElement.findTags('key')) {
keys.add(
EncryptedKey(
jid,
int.parse(key.attributes['rid']! as String),
key.innerText(),
key.attributes['kex'] == 'true',
),
),
);
}
}
final ourJid = getAttributes().getFullJID();
final sid = int.parse(header.attributes['sid']! as String);
final om = await _getOmemoManager();
final om = await getOmemoManager();
final result = await om.onIncomingStanza(
omemo.OmemoIncomingStanza(
OmemoIncomingStanza(
fromJid.toString(),
sid,
state.extensions
.get<DelayedDeliveryData>()
?.timestamp
.millisecondsSinceEpoch ??
DateTime.now().millisecondsSinceEpoch,
keys,
encrypted.firstTag('payload')?.innerText(),
false,
payloadElement?.innerText(),
),
);
@ -468,7 +464,6 @@ class OmemoManager extends XmppManagerBase {
.toList();
}
logger.finest('Got payload: ${result.payload != null}');
if (result.payload != null) {
XMLNode envelope;
try {
@ -486,8 +481,6 @@ class OmemoManager extends XmppManagerBase {
// Do not add forbidden elements from the envelope
envelopeChildren.where(shouldEncryptElement),
);
logger.finest('Adding children: ${envelopeChildren.map((c) => c.tag)}');
} else {
logger.warning('Invalid envelope element: No <content /> element');
}
@ -497,15 +490,6 @@ class OmemoManager extends XmppManagerBase {
}
}
// Ignore heartbeat messages
if (stanza.tag == 'message' && encrypted.firstTag('payload') == null) {
logger.finest('Received empty OMEMO message. Ending processing early.');
return state
..encrypted = true
..skip = true
..done = true;
}
return state
..encrypted = true
..stanza = Stanza(
@ -548,7 +532,7 @@ class OmemoManager extends XmppManagerBase {
/// Retrieve all device bundles for the JID [jid].
///
/// On success, returns a list of devices. On failure, returns am OmemoError.
Future<Result<OmemoError, List<omemo.OmemoBundle>>> retrieveDeviceBundles(
Future<Result<OmemoError, List<OmemoBundle>>> retrieveDeviceBundles(
JID jid,
) async {
// TODO(Unknown): Should we query the device list first?
@ -569,7 +553,7 @@ class OmemoManager extends XmppManagerBase {
/// Retrieves a bundle from entity [jid] with the device id [deviceId].
///
/// On success, returns the device bundle. On failure, returns an OmemoError.
Future<Result<OmemoError, omemo.OmemoBundle>> retrieveDeviceBundle(
Future<Result<OmemoError, OmemoBundle>> retrieveDeviceBundle(
JID jid,
int deviceId,
) async {
@ -585,9 +569,7 @@ class OmemoManager extends XmppManagerBase {
/// nodes.
///
/// On success, returns true. On failure, returns an OmemoError.
Future<Result<OmemoError, bool>> publishBundle(
omemo.OmemoBundle bundle,
) async {
Future<Result<OmemoError, bool>> publishBundle(OmemoBundle bundle) async {
final attrs = getAttributes();
final pm = attrs.getManagerById<PubSubManager>(pubsubManager)!;
final bareJid = attrs.getFullJID().toBare();
@ -654,11 +636,6 @@ class OmemoManager extends XmppManagerBase {
await pm.subscribe(JID.fromString(jid), omemoDevicesXmlns);
}
/// Implementation for publishing our device [device].
Future<void> publishDeviceImpl(omemo.OmemoDevice device) async {
await publishBundle(await device.toBundle());
}
/// Attempts to find out if [jid] supports omemo:2.
///
/// On success, returns whether [jid] has published a device list and device bundles.

View File

@ -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';

View File

@ -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 {

View File

@ -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';

View File

@ -1,4 +1,4 @@
import 'package:collection/collection.dart';
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/managers/base.dart';
import 'package:moxxmpp/src/managers/data.dart';
import 'package:moxxmpp/src/managers/handlers.dart';
@ -114,7 +114,8 @@ class StatelessFileSharingData implements StanzaHandlerExtension {
}
StatelessFileSharingUrlSource? getFirstUrlSource() {
return sources.firstWhereOrNull(
return firstWhereOrNull(
sources,
(StatelessFileSharingSource source) =>
source is StatelessFileSharingUrlSource,
) as StatelessFileSharingUrlSource?;

View File

@ -1,5 +1,5 @@
import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/stringxml.dart';
import 'package:moxxmpp/src/xeps/xep_0300.dart';
@ -54,7 +54,8 @@ class StatelessFileSharingEncryptedSource extends StatelessFileSharingSource {
final sources = element.firstTag('sources', xmlns: sfsXmlns)!.children;
// Find the first URL source
final source = sources.firstWhereOrNull(
final source = firstWhereOrNull(
sources,
(XMLNode child) =>
child.tag == 'url-data' && child.attributes['xmlns'] == urlDataXmlns,
)!;

View File

@ -1,5 +1,4 @@
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';
@ -10,6 +9,7 @@ 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';

View File

@ -18,10 +18,10 @@ dependencies:
meta: ^1.7.0
moxlib:
hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: ^0.2.0
version: ^0.1.5
omemo_dart:
hosted: https://git.polynom.me/api/packages/PapaTutuWawa/pub
version: ^0.5.0
version: ^0.4.3
random_string: ^2.3.1
saslprep: ^1.0.2
synchronized: ^3.0.0+2

View File

@ -30,6 +30,7 @@ void main() {
await Future<void>.delayed(const Duration(seconds: 1));
expect(queue.queue.length, 2);
expect(queue.isRunning, false);
});
test('Test sending', () async {
@ -57,6 +58,7 @@ void main() {
await Future<void>.delayed(const Duration(seconds: 1));
expect(queue.queue.length, 0);
expect(queue.isRunning, false);
});
test('Test partial sending and resuming', () async {
@ -87,10 +89,12 @@ void main() {
await Future<void>.delayed(const Duration(seconds: 1));
expect(queue.queue.length, 1);
expect(queue.isRunning, false);
canRun = true;
await queue.restart();
await Future<void>.delayed(const Duration(seconds: 1));
expect(queue.queue.length, 0);
expect(queue.isRunning, false);
});
}

View File

@ -1,8 +1,6 @@
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';

View File

@ -1,4 +1,3 @@
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/moxxmpp.dart';
import 'package:test/test.dart';

View File

@ -1,4 +1,3 @@
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/moxxmpp.dart';
import 'package:test/test.dart';

View File

@ -1,8 +1,6 @@
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';