From 283e9ebc4d72e02242f7dc0af46a648771dc63e9 Mon Sep 17 00:00:00 2001 From: blue Date: Wed, 15 Mar 2023 21:17:44 +0300 Subject: [PATCH] some thoughts on detecting condition for enablining or showing the button for encryption in chat window --- CHANGELOG.md | 5 +- core/account.cpp | 2 + core/handlers/omemohandler.cpp | 4 + core/handlers/omemohandler.h | 3 + shared/CMakeLists.txt | 2 + shared/trustsummary.cpp | 140 ++++++++++++++++++++++++++ shared/trustsummary.h | 51 ++++++++++ ui/widgets/CMakeLists.txt | 34 +++++-- ui/widgets/conversation.cpp | 2 + ui/widgets/conversation.ui | 25 +++++ ui/widgets/messageline/CMakeLists.txt | 18 +++- 11 files changed, 269 insertions(+), 17 deletions(-) create mode 100644 shared/trustsummary.cpp create mode 100644 shared/trustsummary.h diff --git a/CHANGELOG.md b/CHANGELOG.md index a36da73..f554982 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,12 @@ - all of the expandable roster items now get saved between launches - settings file on the disk is not rewritten every roster element expansion or collapse - removed unnecessary own vcard request at sturtup (used to do it to discover my own avatar) +- vcard window now is Info system and it can display more information ### New features -- Now you can enable tray icon from settings! +- now you can enable tray icon from settings! +- there is a job queue now, this allowes to spread a bit the spam on the server at connection time +- squawk now querries clients of it's peers, you can see what programs other people use ## Squawk 0.2.2 (May 05, 2022) ### Bug fixes diff --git a/core/account.cpp b/core/account.cpp index 9740029..165dfd8 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -120,6 +120,8 @@ Account::Account(const QString& p_login, const QString& p_server, const QString& QObject::connect(delay, &DelayManager::Manager::requestBundles, oh, &OmemoHandler::requestBundles); QObject::connect(delay, &DelayManager::Manager::requestOwnBundles, oh, &OmemoHandler::requestOwnBundles); + QObject::connect(om, &QXmppOmemoManager::deviceAdded, oh, &OmemoHandler::onOmemoDeviceAdded); + client.addExtension(tm); client.addExtension(om); om->setSecurityPolicy(QXmpp::Toakafa); diff --git a/core/handlers/omemohandler.cpp b/core/handlers/omemohandler.cpp index 79eded9..4bccc4b 100644 --- a/core/handlers/omemohandler.cpp +++ b/core/handlers/omemohandler.cpp @@ -214,6 +214,10 @@ void Core::OmemoHandler::onOwnBundlesReceived() { acc->delay->receivedOwnBundles(keys); } +void Core::OmemoHandler::onOmemoDeviceAdded(const QString& jid, uint32_t id) { + qDebug() << "OMEMO device added for" << jid; +} + QDataStream & operator >> (QDataStream& in, QXmppOmemoStorage::Device& device) { in >> device.label; diff --git a/core/handlers/omemohandler.h b/core/handlers/omemohandler.h index 0d1021b..b0db613 100644 --- a/core/handlers/omemohandler.h +++ b/core/handlers/omemohandler.h @@ -64,6 +64,9 @@ public: void requestOwnBundles(); void getDevices(const QString& jid, std::list& out) const; +public slots: + void onOmemoDeviceAdded(const QString& jid, uint32_t id); + private slots: void onBundlesReceived(const QString& jid); void onOwnBundlesReceived(); diff --git a/shared/CMakeLists.txt b/shared/CMakeLists.txt index 5db96f0..4bcc12f 100644 --- a/shared/CMakeLists.txt +++ b/shared/CMakeLists.txt @@ -14,6 +14,7 @@ set(SOURCE_FILES keyinfo.cpp info.cpp clientid.cpp + trustsummary.cpp ) set(HEADER_FILES @@ -35,6 +36,7 @@ set(HEADER_FILES keyinfo.h info.h clientid.h + trustsummary.h ) target_sources(squawk PRIVATE diff --git a/shared/trustsummary.cpp b/shared/trustsummary.cpp new file mode 100644 index 0000000..658538c --- /dev/null +++ b/shared/trustsummary.cpp @@ -0,0 +1,140 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "trustsummary.h" + +const std::set Shared::TrustSummary::trustedLevels({ + Shared::TrustLevel::authenticated, + Shared::TrustLevel::automaticallyTrusted, + Shared::TrustLevel::manuallyTrusted +}); +const std::set Shared::TrustSummary::untrustedLevels({ + Shared::TrustLevel::undecided, + Shared::TrustLevel::automaticallyDistrusted, + Shared::TrustLevel::manuallyDistrusted +}); + +Shared::TrustSummary::TrustSummary(): + data() +{} + +void Shared::TrustSummary::set(Shared::EncryptionProtocol protocol, Shared::TrustLevel level, uint8_t amount) { + Data::iterator itr = data.find(protocol); + if (itr == data.end()) { + if (amount == 0) + return; + + itr = data.insert(std::make_pair(protocol, Amounts())).first; + } + + Amounts& am = itr->second; + Amounts::iterator aitr = am.find(level); + if (aitr == am.end()) { + if (amount == 0) + return; + + am.emplace(level, amount); + return; + } + if (amount == 0) { + if (am.size() == 1) + data.erase(itr); + else + am.erase(aitr); + + return; + } + aitr->second = amount; +} + +uint8_t Shared::TrustSummary::amount(Shared::EncryptionProtocol protocol, Shared::TrustLevel level) const { + Data::const_iterator itr = data.find(protocol); + if (itr == data.end()) + return 0; + + const Amounts& am = itr->second; + Amounts::const_iterator aitr = am.find(level); + if (aitr == am.end()) + return 0; + + return aitr->second; +} + +uint8_t Shared::TrustSummary::increment(Shared::EncryptionProtocol protocol, Shared::TrustLevel level) { + Data::iterator itr = data.find(protocol); + if (itr == data.end()) + itr = data.insert(std::make_pair(protocol, Amounts())).first; + + Amounts& am = itr->second; + Amounts::iterator aitr = am.find(level); + if (aitr == am.end()) { + am.emplace(level, 1); + return 1; + } + uint8_t& value = aitr->second; + return ++value; +} + +uint8_t Shared::TrustSummary::decrement(Shared::EncryptionProtocol protocol, Shared::TrustLevel level) { + Data::iterator itr = data.find(protocol); + if (itr == data.end()) + return 0; //should never happen, shall I better throw an exception? + + Amounts& am = itr->second; + Amounts::iterator aitr = am.find(level); + if (aitr == am.end()) + return 0; //should never happen, shall I better throw an exception? + + uint8_t& value = aitr->second; + uint8_t result = --value; + if (value == 0) { + if (am.size() == 1) + data.erase(itr); + else + am.erase(aitr); + } + return result; +} + +bool Shared::TrustSummary::hasKeys(Shared::EncryptionProtocol protocol) const { + return data.count(protocol) > 0; +} + +bool Shared::TrustSummary::hasTrustedKeys(Shared::EncryptionProtocol protocol) const { + Data::const_iterator itr = data.find(protocol); + if (itr == data.end()) + return false; + + for (const std::pair& pair : itr->second) { + if (trustedLevels.count(pair.first) > 0) + return true; + } + + return false; +} + +bool Shared::TrustSummary::hasUntrustedKeys(Shared::EncryptionProtocol protocol) const { + Data::const_iterator itr = data.find(protocol); + if (itr == data.end()) + return false; + + for (const std::pair& pair : itr->second) { + if (untrustedLevels.count(pair.first) > 0) + return true; + } + + return false; +} diff --git a/shared/trustsummary.h b/shared/trustsummary.h new file mode 100644 index 0000000..3283c10 --- /dev/null +++ b/shared/trustsummary.h @@ -0,0 +1,51 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef SHARED_TRUSTSUMMARY_H +#define SHARED_TRUSTSUMMARY_H + +#include +#include + +#include "enums.h" + +namespace Shared { + +class TrustSummary { +public: + TrustSummary(); + + void set(EncryptionProtocol protocol, TrustLevel level, uint8_t amount); + uint8_t increment(EncryptionProtocol protocol, TrustLevel level); + uint8_t decrement(EncryptionProtocol protocol, TrustLevel level); + + uint8_t amount(EncryptionProtocol protocol, TrustLevel level) const; + bool hasKeys(EncryptionProtocol protocol) const; + bool hasTrustedKeys(EncryptionProtocol protocol) const; + bool hasUntrustedKeys(EncryptionProtocol protocol) const; + +private: + typedef std::map Amounts; + typedef std::map Data; + + Data data; + static const std::set trustedLevels; + static const std::set untrustedLevels; +}; + +} + +#endif // SHARED_TRUSTSUMMARY_H diff --git a/ui/widgets/CMakeLists.txt b/ui/widgets/CMakeLists.txt index 2099db1..e8d846b 100644 --- a/ui/widgets/CMakeLists.txt +++ b/ui/widgets/CMakeLists.txt @@ -1,21 +1,33 @@ -target_sources(squawk PRIVATE +set(SOURCE_FILES chat.cpp - chat.h conversation.cpp - conversation.h - conversation.ui joinconference.cpp - joinconference.h - joinconference.ui newcontact.cpp - newcontact.h - newcontact.ui room.cpp - room.h about.cpp - about.h +) + +set(UI_FILES + conversation.ui + joinconference.ui + newcontact.ui about.ui - ) +) + +set(HEADER_FILES + chat.h + conversation.h + joinconference.h + newcontact.h + room.h + about.h +) + +target_sources(squawk PRIVATE + ${SOURCE_FILES} + ${UI_FILES} + ${HEADER_FILES} +) add_subdirectory(info) add_subdirectory(messageline) diff --git a/ui/widgets/conversation.cpp b/ui/widgets/conversation.cpp index 61d3163..c11449f 100644 --- a/ui/widgets/conversation.cpp +++ b/ui/widgets/conversation.cpp @@ -100,6 +100,8 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el, connect(m_ui->currentActionBadge, &Badge::close, this, &Conversation::clear); m_ui->currentActionBadge->setVisible(false); + m_ui->encryptionButton->setVisible(false); + //line->setAutoFillBackground(false); //if (testAttribute(Qt::WA_TranslucentBackground)) { //m_ui->scrollArea->setAutoFillBackground(false); diff --git a/ui/widgets/conversation.ui b/ui/widgets/conversation.ui index 1f8b483..c73de45 100644 --- a/ui/widgets/conversation.ui +++ b/ui/widgets/conversation.ui @@ -315,6 +315,31 @@ + + + + false + + + + + + + + + true + + + false + + + false + + + true + + + diff --git a/ui/widgets/messageline/CMakeLists.txt b/ui/widgets/messageline/CMakeLists.txt index 7a850da..7ded76b 100644 --- a/ui/widgets/messageline/CMakeLists.txt +++ b/ui/widgets/messageline/CMakeLists.txt @@ -1,10 +1,18 @@ -target_sources(squawk PRIVATE +set(SOURCE_FILES messagedelegate.cpp - messagedelegate.h preview.cpp - preview.h messagefeed.cpp - messagefeed.h feedview.cpp +) + +set(HEADER_FILES + messagedelegate.h + preview.h + messagefeed.h feedview.h - ) +) + +target_sources(squawk PRIVATE + ${SOURCE_FILES} + ${HEADER_FILES} +)