some thoughts on detecting condition for enablining or showing the button for encryption in chat window

This commit is contained in:
Blue 2023-03-15 21:17:44 +03:00
parent 21b40a9ccb
commit 283e9ebc4d
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
11 changed files with 269 additions and 17 deletions

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -64,6 +64,9 @@ public:
void requestOwnBundles();
void getDevices(const QString& jid, std::list<Shared::KeyInfo>& out) const;
public slots:
void onOmemoDeviceAdded(const QString& jid, uint32_t id);
private slots:
void onBundlesReceived(const QString& jid);
void onOwnBundlesReceived();

View File

@ -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

140
shared/trustsummary.cpp Normal file
View File

@ -0,0 +1,140 @@
// Squawk messenger.
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
//
// 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 <http://www.gnu.org/licenses/>.
#include "trustsummary.h"
const std::set<Shared::TrustLevel> Shared::TrustSummary::trustedLevels({
Shared::TrustLevel::authenticated,
Shared::TrustLevel::automaticallyTrusted,
Shared::TrustLevel::manuallyTrusted
});
const std::set<Shared::TrustLevel> 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<const TrustLevel, uint8_t>& 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<const TrustLevel, uint8_t>& pair : itr->second) {
if (untrustedLevels.count(pair.first) > 0)
return true;
}
return false;
}

51
shared/trustsummary.h Normal file
View File

@ -0,0 +1,51 @@
// Squawk messenger.
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
//
// 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 <http://www.gnu.org/licenses/>.
#ifndef SHARED_TRUSTSUMMARY_H
#define SHARED_TRUSTSUMMARY_H
#include <map>
#include <set>
#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<TrustLevel, uint8_t> Amounts;
typedef std::map<EncryptionProtocol, Amounts> Data;
Data data;
static const std::set<TrustLevel> trustedLevels;
static const std::set<TrustLevel> untrustedLevels;
};
}
#endif // SHARED_TRUSTSUMMARY_H

View File

@ -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)

View File

@ -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);

View File

@ -315,6 +315,31 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="encryptionButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="unlock"/>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="attachButton">
<property name="text">

View File

@ -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}
)