feat: Propagate errors and encrypt to self if carbons are enabled

This commit is contained in:
PapaTutuWawa 2023-01-02 13:52:06 +01:00
parent 62001c1e29
commit 22aa07c4ba
2 changed files with 25 additions and 6 deletions

View File

@ -13,11 +13,10 @@ import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
import 'package:moxxmpp/src/xeps/xep_0297.dart'; import 'package:moxxmpp/src/xeps/xep_0297.dart';
class CarbonsManager extends XmppManagerBase { class CarbonsManager extends XmppManagerBase {
CarbonsManager() : super();
CarbonsManager() : _isEnabled = false, _supported = false, _gotSupported = false, super(); bool _isEnabled = false;
bool _isEnabled; bool _supported = false;
bool _supported; bool _gotSupported = false;
bool _gotSupported;
@override @override
String getId() => carbonsManager; String getId() => carbonsManager;
@ -159,6 +158,9 @@ class CarbonsManager extends XmppManagerBase {
return true; return true;
} }
/// True if Message Carbons are enabled. False, if not.
bool get isEnabled => _isEnabled;
@visibleForTesting @visibleForTesting
void forceEnable() { void forceEnable() {
_isEnabled = true; _isEnabled = true;

View File

@ -16,6 +16,7 @@ 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_0030/xep_0030.dart';
import 'package:moxxmpp/src/xeps/xep_0060/errors.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_0060/xep_0060.dart';
import 'package:moxxmpp/src/xeps/xep_0280.dart';
import 'package:moxxmpp/src/xeps/xep_0334.dart'; import 'package:moxxmpp/src/xeps/xep_0334.dart';
import 'package:moxxmpp/src/xeps/xep_0380.dart'; import 'package:moxxmpp/src/xeps/xep_0380.dart';
import 'package:moxxmpp/src/xeps/xep_0384/crypto.dart'; import 'package:moxxmpp/src/xeps/xep_0384/crypto.dart';
@ -337,15 +338,31 @@ abstract class BaseOmemoManager extends XmppManagerBase {
} }
logger.finest('Beginning encryption'); logger.finest('Beginning encryption');
final carbonsEnabled = getAttributes()
.getManagerById<CarbonsManager>(carbonsManager)?.isEnabled ?? false;
final om = await getOmemoManager(); final om = await getOmemoManager();
final result = await om.onOutgoingStanza( final result = await om.onOutgoingStanza(
OmemoOutgoingStanza( OmemoOutgoingStanza(
[toJid.toString()], [
toJid.toString(),
if (carbonsEnabled)
getAttributes().getFullJID().toBare().toString(),
],
_buildEnvelope(toEncrypt, toJid.toString()), _buildEnvelope(toEncrypt, toJid.toString()),
), ),
); );
logger.finest('Encryption done'); logger.finest('Encryption done');
if (!result.isSuccess(2)) {
final other = Map<String, dynamic>.from(state.other);
other['encryption_error_jids'] = result.jidEncryptionErrors;
other['encryption_error_devices'] = result.deviceEncryptionErrors;
return state.copyWith(
other: other,
cancel: true,
);
}
final encrypted = _buildEncryptedElement( final encrypted = _buildEncryptedElement(
result, result,
toJid.toString(), toJid.toString(),