From ca85c94fe52fa361df7dc48ee7a26c0600e59452 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sun, 1 Jan 2023 16:38:54 +0100 Subject: [PATCH] fix: Fix wrong XML serialisation --- .../lib/src/xeps/xep_0384/xep_0384.dart | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) 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 77a7cf3..3a86782 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart @@ -41,9 +41,6 @@ const _doNotEncryptList = [ ]; abstract class BaseOmemoManager extends XmppManagerBase { - // Mapping whether we already tried to subscribe to the JID's devices node - final Map _subscriptionMap = {}; - @override 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) { @@ -317,17 +314,11 @@ abstract class BaseOmemoManager extends XmppManagerBase { if (stanza.to == null) { // We cannot encrypt in this case. + logger.finest('Not encrypting since stanza.to is null'); return state; } final toJid = JID.fromString(stanza.to!).toBare(); - if (_subscriptionMap[toJid] != true) { - unawaited( - subscribeToDeviceList(toJid), - ); - _subscriptionMap[toJid] = true; - } - if (!(await shouldEncryptStanza(toJid, stanza))) { logger.finest('shouldEncryptStanza returned false for message to $toJid. Not encrypting.'); return state; @@ -345,6 +336,7 @@ abstract class BaseOmemoManager extends XmppManagerBase { } } + logger.finest('Beginning encryption'); final om = await getOmemoManager(); final result = await om.onOutgoingStanza( OmemoOutgoingStanza( @@ -352,6 +344,7 @@ abstract class BaseOmemoManager extends XmppManagerBase { _buildEnvelope(toEncrypt, toJid.toString()), ), ); + logger.finest('Encryption done'); final encrypted = _buildEncryptedElement( result, @@ -572,13 +565,9 @@ abstract class BaseOmemoManager extends XmppManagerBase { } /// Subscribes to the device list PubSub node of [jid]. - Future subscribeToDeviceList(JID jid) async { + Future subscribeToDeviceListImpl(String jid) async { final pm = getAttributes().getManagerById(pubsubManager)!; - final result = await pm.subscribe(jid.toString(), omemoDevicesXmlns); - - if (!result.isType()) { - _subscriptionMap[jid] = true; - } + await pm.subscribe(jid, omemoDevicesXmlns); } /// Attempts to find out if [jid] supports omemo:2.