cant believe it, first ever encrypted messages!

This commit is contained in:
Blue 2023-11-05 16:29:44 -03:00
parent a7d1a28f29
commit 637eb702a8
Signed by: blue
GPG key ID: 9B203B252A63EE38
10 changed files with 190 additions and 69 deletions

View file

@ -31,10 +31,12 @@ Chat::Chat(Models::Account* acc, Models::Contact* p_contact, QWidget* parent):
setAvatar(p_contact->getAvatarPath());
connect(contact, &Models::Contact::childChanged, this, &Chat::onContactChanged);
#ifdef WITH_OMEMO
if (p_contact->hasKeys(Shared::EncryptionProtocol::omemo2)) {
m_ui->encryptionButton->setVisible(true);
//if ()
updateEncryptionState();
}
#endif
}
Chat::~Chat()
@ -56,9 +58,14 @@ void Chat::onContactChanged(Models::Item* item, int row, int col) {
case 7:
setAvatar(contact->getAvatarPath());
break;
#ifdef WITH_OMEMO
case 8:
m_ui->encryptionButton->setVisible(contact->hasKeys(Shared::EncryptionProtocol::omemo2));
break;
case 9:
updateEncryptionState();
break;
#endif
}
}
}
@ -69,12 +76,25 @@ void Chat::updateState() {
statusIcon->setToolTip(Shared::Global::getName(av));
}
void Chat::updateEncryptionState() {
m_ui->encryptionButton->setEnabled(true);
if (contact->getEncryption() == Shared::EncryptionProtocol::omemo2)
m_ui->encryptionButton->setIcon(Shared::icon("lock"));
else
m_ui->encryptionButton->setIcon(Shared::icon("unlock"));
}
Shared::Message Chat::createMessage() const {
Shared::Message msg = Conversation::createMessage();
msg.setType(Shared::Message::chat);
msg.setFrom(account->getFullJid());
msg.setToJid(palJid);
msg.setToResource(activePalResource);
#ifdef WITH_OMEMO
if (contact->getEncryption() == Shared::EncryptionProtocol::omemo2)
msg.setEncryption(Shared::EncryptionProtocol::omemo2);
#endif
return msg;
}
@ -87,3 +107,11 @@ void Chat::onMessage(const Shared::Message& data){
setPalResource(res);
}
}
void Chat::onEncryptionButtonClicked() {
m_ui->encryptionButton->setEnabled(false);
if (contact->getEncryption() == Shared::EncryptionProtocol::omemo2)
emit setEncryption(Shared::EncryptionProtocol::none);
else
emit setEncryption(Shared::EncryptionProtocol::omemo2);
}

View file

@ -37,6 +37,7 @@ public:
protected slots:
void onContactChanged(Models::Item* item, int row, int col);
void onEncryptionButtonClicked() override;
protected:
Shared::Message createMessage() const override;
@ -44,6 +45,7 @@ protected:
private:
void updateState();
void updateEncryptionState();
private:
Models::Contact* contact;

View file

@ -91,6 +91,7 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
connect(m_ui->clearButton, &QPushButton::clicked, this, &Conversation::clear);
connect(m_ui->messageEditor->document()->documentLayout(), &QAbstractTextDocumentLayout::documentSizeChanged,
this, &Conversation::onTextEditDocSizeChanged);
connect(m_ui->encryptionButton, &QPushButton::clicked, this, &Conversation::onEncryptionButtonClicked);
m_ui->messageEditor->installEventFilter(&ker);
@ -345,6 +346,8 @@ void Conversation::clear() {
m_ui->messageEditor->clear();
}
void Conversation::onEncryptionButtonClicked() {}
void Conversation::setAvatar(const QString& path) {
QPixmap pixmap;
if (path.size() == 0) {

View file

@ -119,6 +119,7 @@ protected slots:
void onFeedContext(const QPoint &pos);
void onMessageEditorContext(const QPoint &pos);
void onMessageEditRequested(const QString& id);
virtual void onEncryptionButtonClicked();
public:
const bool isMuc;

View file

@ -230,6 +230,7 @@ std::set<Models::MessageFeed::MessageRoles> Models::MessageFeed::detectChanges(c
}
void Models::MessageFeed::removeMessage(const QString& id) {
SHARED_UNUSED(id);
//todo;
}