From 0e1bb5137bf2b13d501c243e31c8ca981fc20a1a Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 21 Apr 2020 22:32:45 +0200 Subject: [PATCH] Add menu entry to show decrypted source Also make hidden entries not consume space in Menus with some qml styles. --- CHANGELOG.md | 5 +++++ resources/langs/nheko_de.ts | 31 ++++++++++++++++++------------- resources/langs/nheko_el.ts | 29 +++++++++++++++++------------ resources/langs/nheko_en.ts | 29 +++++++++++++++++------------ resources/langs/nheko_fi.ts | 29 +++++++++++++++++------------ resources/langs/nheko_fr.ts | 29 +++++++++++++++++------------ resources/langs/nheko_ja.ts | 29 +++++++++++++++++------------ resources/langs/nheko_nl.ts | 29 +++++++++++++++++------------ resources/langs/nheko_pl.ts | 29 +++++++++++++++++------------ resources/langs/nheko_ru.ts | 29 +++++++++++++++++------------ resources/langs/nheko_zh_CN.ts | 29 +++++++++++++++++------------ resources/qml/TimelineRow.qml | 7 +++---- resources/qml/TimelineView.qml | 11 ++++++++++- src/timeline/TimelineModel.cpp | 13 +++++++++++++ src/timeline/TimelineModel.h | 1 + 15 files changed, 203 insertions(+), 126 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b88900f3..bdd4363c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,16 @@ ## [0.7.1] -- unreleased +### Features + +- Show decrypted message source (helps debugging) + ### Bugfixes - Fix display of images sent by the user (thank you, wnereiz and not-chicken for reporting) - Fix crash when trying to maximize image, that wasn't downloaded yet. - Fix Binding restorMode flooding logs on Qt 5.14.2+ +- Fix with some qml styles hidden menu items leave empty space ## [0.7.0] -- 2020-04-19 diff --git a/resources/langs/nheko_de.ts b/resources/langs/nheko_de.ts index bd65e867..259b5c86 100644 --- a/resources/langs/nheko_de.ts +++ b/resources/langs/nheko_de.ts @@ -327,12 +327,12 @@ REGISTRIEREN - + No supported registration flows! Keine unterstützten Registrierungsmethoden! - + Invalid username Ungültiger Benutzername @@ -471,30 +471,30 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. -- Entschlüsselungsfehler (Fehler bei Kommunikation mit Datenbank) -- - + -- Decryption Error (failed to retrieve megolm keys from db) -- Placeholder, when the message can't be decrypted, because the DB access failed. -- Entschlüsselungsfehler (Fehler bei Suche nach megolm Schlüsseln in Datenbank) -- - + -- Decryption Error (%1) -- Placeholder, when the message can't be decrypted. In this case, the Olm decrytion returned an error, which is passed ad %1. -- Entschlüsselungsfehler (%1) -- - + Message redaction failed: %1 Nachricht zurückziehen fehlgeschlagen: %1 - + Save image Bild speichern @@ -514,19 +514,19 @@ Datei speichern - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. -- Verschlüsseltes Event (keine Schlüssel zur Entschlüsselung gefunden) -- - + -- Encrypted Event (Unknown event type) -- Placeholder, when the message was decrypted, but we couldn't parse it, because Nheko/mtxclient don't support that event type yet. -- Verschlüsseltes Event (Unbekannter Eventtyp) -- - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -677,7 +677,7 @@ TimelineView - + Reply Antworten @@ -694,7 +694,12 @@ View raw message - Zeige rohen Nachrichteninhalt + Zeige rohen Nachrichteninhalt + + + + View decrypted raw message + Zeige rohen, entschlüsselten Nachrichteninhalt @@ -702,7 +707,7 @@ Nachricht löschen - + Save as Speichern unter... diff --git a/resources/langs/nheko_el.ts b/resources/langs/nheko_el.ts index 1a7889d5..4ce7e6e4 100644 --- a/resources/langs/nheko_el.ts +++ b/resources/langs/nheko_el.ts @@ -327,12 +327,12 @@ ΕΓΓΡΑΦΗ - + No supported registration flows! - + Invalid username Μη έγκυρο όνομα χρήστη @@ -471,30 +471,30 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. - + -- Decryption Error (failed to retrieve megolm keys from db) -- Placeholder, when the message can't be decrypted, because the DB access failed. - + -- Decryption Error (%1) -- Placeholder, when the message can't be decrypted. In this case, the Olm decrytion returned an error, which is passed ad %1. - + Message redaction failed: %1 - + Save image Αποθήκευση Εικόνας @@ -514,19 +514,19 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. - + -- Encrypted Event (Unknown event type) -- Placeholder, when the message was decrypted, but we couldn't parse it, because Nheko/mtxclient don't support that event type yet. - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -677,7 +677,7 @@ TimelineView - + Reply @@ -696,13 +696,18 @@ View raw message + + + View decrypted raw message + + Redact message - + Save as diff --git a/resources/langs/nheko_en.ts b/resources/langs/nheko_en.ts index f75068fa..f7b3b093 100644 --- a/resources/langs/nheko_en.ts +++ b/resources/langs/nheko_en.ts @@ -327,12 +327,12 @@ REGISTER - + No supported registration flows! No supported registration flows! - + Invalid username Invalid username @@ -471,30 +471,30 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. -- Decryption Error (failed to communicate with DB) -- - + -- Decryption Error (failed to retrieve megolm keys from db) -- Placeholder, when the message can't be decrypted, because the DB access failed. -- Decryption Error (failed to retrieve megolm keys from db) -- - + -- Decryption Error (%1) -- Placeholder, when the message can't be decrypted. In this case, the Olm decrytion returned an error, which is passed ad %1. -- Decryption Error (%1) -- - + Message redaction failed: %1 Message redaction failed: %1 - + Save image Save image @@ -514,19 +514,19 @@ Save file - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. -- Encrypted Event (No keys found for decryption) -- - + -- Encrypted Event (Unknown event type) -- Placeholder, when the message was decrypted, but we couldn't parse it, because Nheko/mtxclient don't support that event type yet. -- Encrypted Event (Unknown event type) -- - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -677,7 +677,7 @@ TimelineView - + Reply Reply @@ -696,13 +696,18 @@ View raw message View raw message + + + View decrypted raw message + + Redact message Redact message - + Save as Save as diff --git a/resources/langs/nheko_fi.ts b/resources/langs/nheko_fi.ts index b7230f63..eab4771b 100644 --- a/resources/langs/nheko_fi.ts +++ b/resources/langs/nheko_fi.ts @@ -327,12 +327,12 @@ REKISTERÖIDY - + No supported registration flows! - + Invalid username Epäkelpo käyttäjänimi @@ -471,30 +471,30 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. -- Virhe purkaessa salausta (tietokannan kanssa kommunikointi epäonnistui) -- - + -- Decryption Error (failed to retrieve megolm keys from db) -- Placeholder, when the message can't be decrypted, because the DB access failed. -- Virhe purkaessa salausta (megolm-avaimien hakeminen tietokannasta epäonnistui) -- - + -- Decryption Error (%1) -- Placeholder, when the message can't be decrypted. In this case, the Olm decrytion returned an error, which is passed ad %1. -- Virhe purkaessa salausta (%1) -- - + Message redaction failed: %1 Viestin poisto epäonnistui: %1 - + Save image Tallenna kuva @@ -514,19 +514,19 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. -- Salattu viesti (salauksen purkuavaimia ei löydetty) -- - + -- Encrypted Event (Unknown event type) -- Placeholder, when the message was decrypted, but we couldn't parse it, because Nheko/mtxclient don't support that event type yet. -- Salattu viesti (tuntematon viestityyppi) -- - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -677,7 +677,7 @@ TimelineView - + Reply @@ -696,13 +696,18 @@ View raw message + + + View decrypted raw message + + Redact message - + Save as diff --git a/resources/langs/nheko_fr.ts b/resources/langs/nheko_fr.ts index 0ea3540f..472f8c7f 100644 --- a/resources/langs/nheko_fr.ts +++ b/resources/langs/nheko_fr.ts @@ -328,12 +328,12 @@ S'ENREGISTRER - + No supported registration flows! - + Invalid username Nom d'utilisateur invalide @@ -472,30 +472,30 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. - + -- Decryption Error (failed to retrieve megolm keys from db) -- Placeholder, when the message can't be decrypted, because the DB access failed. - + -- Decryption Error (%1) -- Placeholder, when the message can't be decrypted. In this case, the Olm decrytion returned an error, which is passed ad %1. - + Message redaction failed: %1 - + Save image Enregistrer l'image @@ -515,19 +515,19 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. - + -- Encrypted Event (Unknown event type) -- Placeholder, when the message was decrypted, but we couldn't parse it, because Nheko/mtxclient don't support that event type yet. - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -678,7 +678,7 @@ TimelineView - + Reply @@ -697,13 +697,18 @@ View raw message + + + View decrypted raw message + + Redact message - + Save as diff --git a/resources/langs/nheko_ja.ts b/resources/langs/nheko_ja.ts index dc8d4b03..d3194b42 100644 --- a/resources/langs/nheko_ja.ts +++ b/resources/langs/nheko_ja.ts @@ -327,12 +327,12 @@ 登録 - + No supported registration flows! - + Invalid username 無効なユーザー名です @@ -471,30 +471,30 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. -- 復号エラー (データベースと通信できませんでした) -- - + -- Decryption Error (failed to retrieve megolm keys from db) -- Placeholder, when the message can't be decrypted, because the DB access failed. -- 復号エラー (データベースからmegolm鍵を取得できませんでした) -- - + -- Decryption Error (%1) -- Placeholder, when the message can't be decrypted. In this case, the Olm decrytion returned an error, which is passed ad %1. -- 復号エラー (%1) -- - + Message redaction failed: %1 メッセージを編集できませんでした: %1 - + Save image 画像を保存 @@ -514,19 +514,19 @@ ファイルを保存 - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. -- 暗号化イベント (復号鍵が見つかりません) -- - + -- Encrypted Event (Unknown event type) -- Placeholder, when the message was decrypted, but we couldn't parse it, because Nheko/mtxclient don't support that event type yet. -- 暗号化イベント (不明なイベント型です) -- - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -676,7 +676,7 @@ TimelineView - + Reply 返信 @@ -695,13 +695,18 @@ View raw message ソースを見る + + + View decrypted raw message + + Redact message メッセージを編集 - + Save as 名前を付けて保存 diff --git a/resources/langs/nheko_nl.ts b/resources/langs/nheko_nl.ts index cfd01d2f..cb4f68e8 100644 --- a/resources/langs/nheko_nl.ts +++ b/resources/langs/nheko_nl.ts @@ -327,12 +327,12 @@ REGISTREREN - + No supported registration flows! - + Invalid username Ongeldige gebruikersnaam @@ -471,30 +471,30 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. - + -- Decryption Error (failed to retrieve megolm keys from db) -- Placeholder, when the message can't be decrypted, because the DB access failed. - + -- Decryption Error (%1) -- Placeholder, when the message can't be decrypted. In this case, the Olm decrytion returned an error, which is passed ad %1. - + Message redaction failed: %1 - + Save image Afbeelding opslaan @@ -514,19 +514,19 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. - + -- Encrypted Event (Unknown event type) -- Placeholder, when the message was decrypted, but we couldn't parse it, because Nheko/mtxclient don't support that event type yet. - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -677,7 +677,7 @@ TimelineView - + Reply @@ -696,13 +696,18 @@ View raw message + + + View decrypted raw message + + Redact message - + Save as diff --git a/resources/langs/nheko_pl.ts b/resources/langs/nheko_pl.ts index 11183d23..9fb3bae6 100644 --- a/resources/langs/nheko_pl.ts +++ b/resources/langs/nheko_pl.ts @@ -327,12 +327,12 @@ ZAREJESTRUJ - + No supported registration flows! - + Invalid username Nieprawidłowa nazwa użytkownika @@ -471,30 +471,30 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. - + -- Decryption Error (failed to retrieve megolm keys from db) -- Placeholder, when the message can't be decrypted, because the DB access failed. - + -- Decryption Error (%1) -- Placeholder, when the message can't be decrypted. In this case, the Olm decrytion returned an error, which is passed ad %1. - + Message redaction failed: %1 Redagowanie wiadomości nie powiodło się: %1 - + Save image Zapisz obraz @@ -514,19 +514,19 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. - + -- Encrypted Event (Unknown event type) -- Placeholder, when the message was decrypted, but we couldn't parse it, because Nheko/mtxclient don't support that event type yet. - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -678,7 +678,7 @@ TimelineView - + Reply @@ -697,13 +697,18 @@ View raw message + + + View decrypted raw message + + Redact message - + Save as diff --git a/resources/langs/nheko_ru.ts b/resources/langs/nheko_ru.ts index 0facf794..f48fccf3 100644 --- a/resources/langs/nheko_ru.ts +++ b/resources/langs/nheko_ru.ts @@ -327,12 +327,12 @@ РЕГИСТРАЦИЯ - + No supported registration flows! - + Invalid username Некорректное имя пользователя @@ -471,30 +471,30 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. - + -- Decryption Error (failed to retrieve megolm keys from db) -- Placeholder, when the message can't be decrypted, because the DB access failed. - + -- Decryption Error (%1) -- Placeholder, when the message can't be decrypted. In this case, the Olm decrytion returned an error, which is passed ad %1. - + Message redaction failed: %1 Ошибка редактирования сообщения: %1 - + Save image Сохранить изображение @@ -514,19 +514,19 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. - + -- Encrypted Event (Unknown event type) -- Placeholder, when the message was decrypted, but we couldn't parse it, because Nheko/mtxclient don't support that event type yet. - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -678,7 +678,7 @@ TimelineView - + Reply @@ -697,13 +697,18 @@ View raw message + + + View decrypted raw message + + Redact message - + Save as diff --git a/resources/langs/nheko_zh_CN.ts b/resources/langs/nheko_zh_CN.ts index aa300707..63b67734 100644 --- a/resources/langs/nheko_zh_CN.ts +++ b/resources/langs/nheko_zh_CN.ts @@ -327,12 +327,12 @@ 注册 - + No supported registration flows! - + Invalid username 无效的用户名 @@ -471,30 +471,30 @@ TimelineModel - + -- Decryption Error (failed to communicate with DB) -- Placeholder, when the message can't be decrypted, because the DB access failed when trying to lookup the session. - + -- Decryption Error (failed to retrieve megolm keys from db) -- Placeholder, when the message can't be decrypted, because the DB access failed. - + -- Decryption Error (%1) -- Placeholder, when the message can't be decrypted. In this case, the Olm decrytion returned an error, which is passed ad %1. - + Message redaction failed: %1 删除消息失败:%1 - + Save image 保存图像 @@ -514,19 +514,19 @@ - + -- Encrypted Event (No keys found for decryption) -- Placeholder, when the message was not decrypted yet or can't be decrypted. - + -- Encrypted Event (Unknown event type) -- Placeholder, when the message was decrypted, but we couldn't parse it, because Nheko/mtxclient don't support that event type yet. - + %1 and %2 are typing. Multiple users are typing. First argument is a comma separated list of potentially multiple users. Second argument is the last user of that list. (If only one user is typing, %1 is empty. You should still use it in your string though to silence Qt warnings.) @@ -676,7 +676,7 @@ TimelineView - + Reply @@ -695,13 +695,18 @@ View raw message + + + View decrypted raw message + + Redact message - + Save as diff --git a/resources/qml/TimelineRow.qml b/resources/qml/TimelineRow.qml index e13cde28..05c69112 100644 --- a/resources/qml/TimelineRow.qml +++ b/resources/qml/TimelineRow.qml @@ -17,11 +17,11 @@ MouseArea { acceptedButtons: Qt.LeftButton | Qt.RightButton onClicked: { if (mouse.button === Qt.RightButton) - messageContextMenu.show(model.id, model.type, row) + messageContextMenu.show(model.id, model.type, model.isEncrypted, row) } onPressAndHold: { if (mouse.source === Qt.MouseEventNotSynthesized) - messageContextMenu.show(model.id, model.type, row) + messageContextMenu.show(model.id, model.type, model.isEncrypted, row) } RowLayout { @@ -97,8 +97,7 @@ MouseArea { ToolTip.visible: hovered ToolTip.text: qsTr("Options") - onClicked: messageContextMenu.show(model.id, model.type, optionsButton) - + onClicked: messageContextMenu.show(model.id, model.type, model.isEncrypted, optionsButton) } Label { diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index 86b511b2..cad341b5 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -33,14 +33,16 @@ Page { id: messageContextMenu modal: true - function show(eventId_, eventType_, showAt) { + function show(eventId_, eventType_, isEncrypted_, showAt) { eventId = eventId_ eventType = eventType_ + isEncrypted = isEncrypted_ popup(showAt) } property string eventId property int eventType + property bool isEncrypted MenuItem { text: qsTr("Reply") @@ -57,12 +59,19 @@ Page { text: qsTr("View raw message") onTriggered: chat.model.viewRawMessage(messageContextMenu.eventId) } + MenuItem { + visible: messageContextMenu.isEncrypted + height: visible ? implicitHeight : 0 + text: qsTr("View decrypted raw message") + onTriggered: chat.model.viewDecryptedRawMessage(messageContextMenu.eventId) + } MenuItem { text: qsTr("Redact message") onTriggered: chat.model.redactEvent(messageContextMenu.eventId) } MenuItem { visible: messageContextMenu.eventType == MtxEvent.ImageMessage || messageContextMenu.eventType == MtxEvent.VideoMessage || messageContextMenu.eventType == MtxEvent.AudioMessage || messageContextMenu.eventType == MtxEvent.FileMessage || messageContextMenu.eventType == MtxEvent.Sticker + height: visible ? implicitHeight : 0 text: qsTr("Save as") onTriggered: timelineManager.timeline.saveMedia(messageContextMenu.eventId) } diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 7e124f47..bb793945 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -697,7 +697,20 @@ TimelineModel::viewRawMessage(QString id) const } void +TimelineModel::viewDecryptedRawMessage(QString id) const +{ + auto event = events.value(id); + if (auto e = + std::get_if>(&event)) { + event = decryptEvent(*e).event; + } + std::string ev = utils::serialize_event(event).dump(4); + auto dialog = new dialogs::RawMessage(QString::fromStdString(ev)); + Q_UNUSED(dialog); +} + +void TimelineModel::openUserProfile(QString userid) const { MainWindow::instance()->openUserProfile(userid, room_id_); diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index bb84bcd8..84e9ec26 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -179,6 +179,7 @@ public: Q_INVOKABLE QString escapeEmoji(QString str) const; Q_INVOKABLE void viewRawMessage(QString id) const; + Q_INVOKABLE void viewDecryptedRawMessage(QString id) const; Q_INVOKABLE void openUserProfile(QString userid) const; Q_INVOKABLE void replyAction(QString id); Q_INVOKABLE void readReceiptsAction(QString id) const;