From 2128e786c2d3084f623ef4cd6fb9eacf3a3ac458 Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Tue, 14 Mar 2023 21:33:58 +0100 Subject: OmemoManager: Fix and extend method documentation --- src/omemo/QXmppOmemoManager.cpp | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'src/omemo/QXmppOmemoManager.cpp') diff --git a/src/omemo/QXmppOmemoManager.cpp b/src/omemo/QXmppOmemoManager.cpp index a3ad12bb..f1b6cf95 100644 --- a/src/omemo/QXmppOmemoManager.cpp +++ b/src/omemo/QXmppOmemoManager.cpp @@ -675,11 +675,13 @@ QXmppOmemoOwnDevice Manager::ownDevice() /// Returns all locally stored devices except the own device. /// -/// Only devices that have been received after subscribing the corresponding -/// device lists on the server are stored locally. +/// Only devices that have been received after subscribing the corresponding device lists on the +/// server are stored locally. /// Thus, only those are returned. -/// Call \c QXmppOmemoManager::subscribeToDeviceLists() for contacts without -/// presence subscription before. +/// Call \c QXmppOmemoManager::subscribeToDeviceLists() for contacts without presence subscription +/// before. +/// +/// You must build sessions before you can get devices with corresponding keys. /// /// /\return all devices except the own device /// @@ -691,11 +693,13 @@ QXmppTask> Manager::devices() /// /// Returns locally stored devices except the own device. /// -/// Only devices that have been received after subscribing the corresponding -/// device lists on the server are stored locally. +/// Only devices that have been received after subscribing the corresponding device lists on the +/// server are stored locally. /// Thus, only those are returned. -/// Call \c QXmppOmemoManager::subscribeToDeviceLists() for contacts without -/// presence subscription before. +/// Call \c QXmppOmemoManager::subscribeToDeviceLists() for contacts without presence subscription +/// before. +/// +/// You must build sessions before you can get devices with corresponding keys. /// /// \param jids JIDs whose devices are being retrieved /// @@ -835,16 +839,15 @@ bool Manager::isNewDeviceAutoSessionBuildingEnabled() /// /// Builds sessions manually with devices for whom no sessions are available. /// -/// Usually, sessions are built during sending a first message to a device or -/// after a first message is received from a device. +/// Usually, sessions are built during sending a first message to a device or after a first message +/// is received from a device. /// This can be called in order to speed up the sending of a message. -/// If this method is called before sending the first message, all sessions can -/// be built and when the first message is sent, the message has only be -/// encrypted. -/// Especially chats with multiple devices, that can decrease the noticeable -/// time a user has to wait for sending a message. -/// Additionally, the keys are automatically retrieved from the server which is -/// helpful in order to get them when calling \c QXmppOmemoManager::devices(). +/// If this method is called before sending the first message, all sessions can be built and when +/// the first message is being sent, the message only needs to be encrypted. +/// Especially for chats with multiple devices, that can decrease the noticeable time a user has to +/// wait for sending a message. +/// Additionally, the keys are automatically retrieved from the server which is helpful in order to +/// get them when calling \c QXmppOmemoManager::devices(). /// /// The user must be logged in while calling this. /// -- cgit v1.2.3 From 7cdc35101d6aa7fb777555001c501a012c94df92 Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Wed, 22 Mar 2023 09:42:32 +0100 Subject: OmemoManager: Emit trustLevelsChanged() only when OMEMO keys have changed --- src/omemo/QXmppOmemoManager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/omemo/QXmppOmemoManager.cpp') diff --git a/src/omemo/QXmppOmemoManager.cpp b/src/omemo/QXmppOmemoManager.cpp index f1b6cf95..d555cb88 100644 --- a/src/omemo/QXmppOmemoManager.cpp +++ b/src/omemo/QXmppOmemoManager.cpp @@ -1243,7 +1243,9 @@ void Manager::setClient(QXmppClient *client) connect(d->trustManager, &QXmppTrustManager::trustLevelsChanged, this, [=](const QHash> &modifiedKeys) { const auto &modifiedOmemoKeys = modifiedKeys.value(ns_omemo_2); - Q_EMIT trustLevelsChanged(modifiedOmemoKeys); + if (!modifiedOmemoKeys.isEmpty()) { + Q_EMIT trustLevelsChanged(modifiedOmemoKeys); + } for (auto itr = modifiedOmemoKeys.cbegin(); itr != modifiedOmemoKeys.cend(); ++itr) { const auto &keyOwnerJid = itr.key(); -- cgit v1.2.3 From 40680cdc07a0afc5ca2a3fcf1da466d0a909f5c1 Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Wed, 5 Apr 2023 19:48:24 +0200 Subject: OmemoManager: Fix emitting 'deviceChanged()' --- src/omemo/QXmppOmemoManager.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/omemo/QXmppOmemoManager.cpp') diff --git a/src/omemo/QXmppOmemoManager.cpp b/src/omemo/QXmppOmemoManager.cpp index d555cb88..43ac3f1b 100644 --- a/src/omemo/QXmppOmemoManager.cpp +++ b/src/omemo/QXmppOmemoManager.cpp @@ -1243,6 +1243,7 @@ void Manager::setClient(QXmppClient *client) connect(d->trustManager, &QXmppTrustManager::trustLevelsChanged, this, [=](const QHash> &modifiedKeys) { const auto &modifiedOmemoKeys = modifiedKeys.value(ns_omemo_2); + if (!modifiedOmemoKeys.isEmpty()) { Q_EMIT trustLevelsChanged(modifiedOmemoKeys); } @@ -1253,9 +1254,9 @@ void Manager::setClient(QXmppClient *client) // Emit 'deviceChanged()' only if there is a device with the key. const auto &devices = d->devices.value(keyOwnerJid); - for (auto itr = devices.cbegin(); itr != devices.cend(); ++itr) { - if (itr->keyId == keyId) { - Q_EMIT deviceChanged(keyOwnerJid, itr.key()); + for (auto devicesItr = devices.cbegin(); devicesItr != devices.cend(); ++devicesItr) { + if (devicesItr->keyId == keyId) { + Q_EMIT deviceChanged(keyOwnerJid, devicesItr.key()); return; } } -- cgit v1.2.3 From 9d08a60b851804bb818868b82b8ec43c784d29aa Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Wed, 5 Apr 2023 20:06:25 +0200 Subject: OmemoManager: Emit 'deviceChanged()' for all changed devices --- src/omemo/QXmppOmemoManager.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/omemo/QXmppOmemoManager.cpp') diff --git a/src/omemo/QXmppOmemoManager.cpp b/src/omemo/QXmppOmemoManager.cpp index 43ac3f1b..f9172d3b 100644 --- a/src/omemo/QXmppOmemoManager.cpp +++ b/src/omemo/QXmppOmemoManager.cpp @@ -1248,19 +1248,25 @@ void Manager::setClient(QXmppClient *client) Q_EMIT trustLevelsChanged(modifiedOmemoKeys); } + QMultiHash modifiedDevices; + for (auto itr = modifiedOmemoKeys.cbegin(); itr != modifiedOmemoKeys.cend(); ++itr) { const auto &keyOwnerJid = itr.key(); const auto &keyId = itr.value(); - // Emit 'deviceChanged()' only if there is a device with the key. + // Ensure to emit 'deviceChanged()' later only if there is a device with the key. const auto &devices = d->devices.value(keyOwnerJid); for (auto devicesItr = devices.cbegin(); devicesItr != devices.cend(); ++devicesItr) { if (devicesItr->keyId == keyId) { - Q_EMIT deviceChanged(keyOwnerJid, devicesItr.key()); - return; + modifiedDevices.insert(keyOwnerJid, devicesItr.key()); + break; } } } + + for (auto modifiedDevicesItr = modifiedDevices.cbegin(); modifiedDevicesItr != modifiedDevices.cend(); ++modifiedDevicesItr) { + Q_EMIT deviceChanged(modifiedDevicesItr.key(), modifiedDevicesItr.value()); + } }); } -- cgit v1.2.3