fix: Fix wrong XML serialisation

This commit is contained in:
PapaTutuWawa 2023-01-01 16:38:54 +01:00
parent 637e1e25a6
commit ca85c94fe5

View File

@ -41,9 +41,6 @@ const _doNotEncryptList = [
]; ];
abstract class BaseOmemoManager extends XmppManagerBase { abstract class BaseOmemoManager extends XmppManagerBase {
// Mapping whether we already tried to subscribe to the JID's devices node
final Map<JID, bool> _subscriptionMap = {};
@override @override
String getId() => omemoManager; String getId() => omemoManager;
@ -205,7 +202,7 @@ abstract class BaseOmemoManager extends XmppManagerBase {
], ],
); );
return payload.toString(); return payload.toXml();
} }
XMLNode _buildEncryptedElement(EncryptionResult result, String recipientJid, int deviceId) { XMLNode _buildEncryptedElement(EncryptionResult result, String recipientJid, int deviceId) {
@ -317,17 +314,11 @@ abstract class BaseOmemoManager extends XmppManagerBase {
if (stanza.to == null) { if (stanza.to == null) {
// We cannot encrypt in this case. // We cannot encrypt in this case.
logger.finest('Not encrypting since stanza.to is null');
return state; return state;
} }
final toJid = JID.fromString(stanza.to!).toBare(); final toJid = JID.fromString(stanza.to!).toBare();
if (_subscriptionMap[toJid] != true) {
unawaited(
subscribeToDeviceList(toJid),
);
_subscriptionMap[toJid] = true;
}
if (!(await shouldEncryptStanza(toJid, stanza))) { if (!(await shouldEncryptStanza(toJid, stanza))) {
logger.finest('shouldEncryptStanza returned false for message to $toJid. Not encrypting.'); logger.finest('shouldEncryptStanza returned false for message to $toJid. Not encrypting.');
return state; return state;
@ -345,6 +336,7 @@ abstract class BaseOmemoManager extends XmppManagerBase {
} }
} }
logger.finest('Beginning encryption');
final om = await getOmemoManager(); final om = await getOmemoManager();
final result = await om.onOutgoingStanza( final result = await om.onOutgoingStanza(
OmemoOutgoingStanza( OmemoOutgoingStanza(
@ -352,6 +344,7 @@ abstract class BaseOmemoManager extends XmppManagerBase {
_buildEnvelope(toEncrypt, toJid.toString()), _buildEnvelope(toEncrypt, toJid.toString()),
), ),
); );
logger.finest('Encryption done');
final encrypted = _buildEncryptedElement( final encrypted = _buildEncryptedElement(
result, result,
@ -572,13 +565,9 @@ abstract class BaseOmemoManager extends XmppManagerBase {
} }
/// Subscribes to the device list PubSub node of [jid]. /// Subscribes to the device list PubSub node of [jid].
Future<void> subscribeToDeviceList(JID jid) async { Future<void> subscribeToDeviceListImpl(String jid) async {
final pm = getAttributes().getManagerById<PubSubManager>(pubsubManager)!; final pm = getAttributes().getManagerById<PubSubManager>(pubsubManager)!;
final result = await pm.subscribe(jid.toString(), omemoDevicesXmlns); await pm.subscribe(jid, omemoDevicesXmlns);
if (!result.isType<PubSubError>()) {
_subscriptionMap[jid] = true;
}
} }
/// Attempts to find out if [jid] supports omemo:2. /// Attempts to find out if [jid] supports omemo:2.