From a4c280a4f927df7de5445d19419fa77f2b603f27 Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Tue, 21 Apr 2020 21:42:17 -0400 Subject: [PATCH 1/8] Add ability to toggle sidebar messages for encrypted rooms --- src/UserSettingsPage.cpp | 10 +++++++++- src/UserSettingsPage.h | 9 +++++++++ src/Utils.h | 1 - src/timeline/TimelineModel.cpp | 7 ++++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index b4f4cb45..537054c7 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -63,6 +63,7 @@ UserSettings::load() theme_ = settings.value("user/theme", defaultTheme_).toString(); font_ = settings.value("user/font_family", "default").toString(); avatarCircles_ = settings.value("user/avatar_circles", true).toBool(); + decryptSidebar_ = settings.value("user/decrypt_sidebar", true).toBool(); emojiFont_ = settings.value("user/emoji_font_family", "default").toString(); baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble(); @@ -167,7 +168,7 @@ UserSettings::save() settings.endGroup(); settings.setValue("avatar_circles", avatarCircles_); - + settings.setValue("decrypt_sidebar", decryptSidebar_); settings.setValue("font_size", baseFontSize_); settings.setValue("typing_notifications", isTypingNotificationsEnabled_); settings.setValue("minor_events", sortByImportance_); @@ -230,6 +231,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge trayToggle_ = new Toggle{this}; startInTrayToggle_ = new Toggle{this}; avatarCircles_ = new Toggle{this}; + decryptSidebar_ = new Toggle(this); groupViewToggle_ = new Toggle{this}; timelineButtonsToggle_ = new Toggle{this}; typingNotifications_ = new Toggle{this}; @@ -335,6 +337,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge formLayout_->addRow(new HorizontalLine{this}); boxWrap(tr("Circular Avatars"), avatarCircles_); boxWrap(tr("Group's sidebar"), groupViewToggle_); + boxWrap(tr("Decrypt messages in sidebar"), decryptSidebar_); boxWrap(tr("Show buttons in timeline"), timelineButtonsToggle_); boxWrap(tr("Typing notifications"), typingNotifications_); boxWrap(tr("Sort rooms by unreads"), sortByImportance_); @@ -427,6 +430,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge settings_->setGroupView(!isDisabled); }); + connect(decryptSidebar_, &Toggle::toggled, this, [this](bool isDisabled) { + settings_->setDecryptSidebar(!isDisabled); + }); + connect(avatarCircles_, &Toggle::toggled, this, [this](bool isDisabled) { settings_->setAvatarCircles(!isDisabled); }); @@ -479,6 +486,7 @@ UserSettingsPage::showEvent(QShowEvent *) trayToggle_->setState(!settings_->isTrayEnabled()); startInTrayToggle_->setState(!settings_->isStartInTrayEnabled()); groupViewToggle_->setState(!settings_->isGroupViewEnabled()); + decryptSidebar_->setState(!settings_->isDecryptSidebarEnabled()); avatarCircles_->setState(!settings_->isAvatarCirclesEnabled()); typingNotifications_->setState(!settings_->isTypingNotificationsEnabled()); sortByImportance_->setState(!settings_->isSortByImportanceEnabled()); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index 1c20214e..aff2525a 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -111,11 +111,18 @@ public: save(); } + void setDecryptSidebar(bool state) + { + decryptSidebar_ = state; + save(); + } + QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; } bool isTrayEnabled() const { return isTrayEnabled_; } bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; } bool isGroupViewEnabled() const { return isGroupViewEnabled_; } bool isAvatarCirclesEnabled() const { return avatarCircles_; } + bool isDecryptSidebarEnabled() const { return decryptSidebar_; } bool isMarkdownEnabled() const { return isMarkdownEnabled_; } bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; } bool isSortByImportanceEnabled() const { return sortByImportance_; } @@ -147,6 +154,7 @@ private: bool isReadReceiptsEnabled_; bool hasDesktopNotifications_; bool avatarCircles_; + bool decryptSidebar_; double baseFontSize_; QString font_; QString emojiFont_; @@ -199,6 +207,7 @@ private: Toggle *markdownEnabled_; Toggle *desktopNotifications_; Toggle *avatarCircles_; + Toggle *decryptSidebar_; QLabel *deviceFingerprintValue_; QLabel *deviceIdValue_; diff --git a/src/Utils.h b/src/Utils.h index a3854dd8..663d5a38 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -306,5 +306,4 @@ centerWidget(QWidget *widget, QWidget *parent); void restoreCombobox(QComboBox *combo, const QString &value); - } diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index bb793945..439a7786 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "ChatPage.h" @@ -504,11 +505,15 @@ isMessage(const mtx::events::Event &) void TimelineModel::updateLastMessage() { + // Get the user setting to show decrypted messages in side bar + bool decrypt = QSettings().value("user/decrypt_sidebar", true).toBool(); for (auto it = eventOrder.begin(); it != eventOrder.end(); ++it) { auto event = events.value(*it); if (auto e = std::get_if>( &event)) { - event = decryptEvent(*e).event; + if (decrypt) { + event = decryptEvent(*e).event; + } } if (!std::visit([](const auto &e) -> bool { return isMessage(e); }, event)) From b298f01d92eac2f7af6fce28cbe5256411e6c386 Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Wed, 22 Apr 2020 19:52:30 -0400 Subject: [PATCH 2/8] Add signal/slot for decryption changes in last patch --- src/ChatPage.h | 1 + src/MainWindow.cpp | 4 ++++ src/Olm.cpp | 2 +- src/UserSettingsPage.cpp | 1 + src/UserSettingsPage.h | 1 + src/timeline/TimelineModel.cpp | 7 +++++++ src/timeline/TimelineModel.h | 2 +- src/timeline/TimelineViewManager.cpp | 17 +++++++++++++++++ src/timeline/TimelineViewManager.h | 1 + 9 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/ChatPage.h b/src/ChatPage.h index 5182ab99..46630692 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -153,6 +153,7 @@ signals: void updateGroupsInfo(const mtx::responses::JoinedGroups &groups); void themeChanged(); + void decryptSidebarChanged(); private slots: void showUnreadMessageNotification(int count); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index fb64f0fe..c6abdca2 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -117,6 +117,10 @@ MainWindow::MainWindow(QWidget *parent) userSettingsPage_, SIGNAL(trayOptionChanged(bool)), trayIcon_, SLOT(setVisible(bool))); connect( userSettingsPage_, &UserSettingsPage::themeChanged, chat_page_, &ChatPage::themeChanged); + connect(userSettingsPage_, + &UserSettingsPage::decryptSidebarChanged, + chat_page_, + &ChatPage::decryptSidebarChanged); connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, diff --git a/src/Olm.cpp b/src/Olm.cpp index 78b16be7..c8e4c13c 100644 --- a/src/Olm.cpp +++ b/src/Olm.cpp @@ -184,7 +184,7 @@ encrypt_group_message(const std::string &room_id, const std::string &device_id, data.relates_to = relation; auto message_index = olm_outbound_group_session_message_index(res.session); - nhlog::crypto()->info("next message_index {}", message_index); + nhlog::crypto()->debug("next message_index {}", message_index); // We need to re-pickle the session after we send a message to save the new message_index. cache::updateOutboundMegolmSession(room_id, message_index); diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 537054c7..4db883f5 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -432,6 +432,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge connect(decryptSidebar_, &Toggle::toggled, this, [this](bool isDisabled) { settings_->setDecryptSidebar(!isDisabled); + emit decryptSidebarChanged(); }); connect(avatarCircles_, &Toggle::toggled, this, [this](bool isDisabled) { diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index aff2525a..6b9834ea 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -183,6 +183,7 @@ signals: void moveBack(); void trayOptionChanged(bool value); void themeChanged(); + void decryptSidebarChanged(); private slots: void importSessionKeys(); diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 439a7786..3e2c32fa 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -502,6 +502,13 @@ isMessage(const mtx::events::Event &) return false; } +template +auto +isMessage(const mtx::events::EncryptedEvent &) +{ + return true; +} + void TimelineModel::updateLastMessage() { diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 84e9ec26..98b183f6 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -189,6 +189,7 @@ public: Q_INVOKABLE void cacheMedia(QString eventId); Q_INVOKABLE bool saveMedia(QString eventId) const; + void updateLastMessage(); void addEvents(const mtx::responses::Timeline &events); template void sendMessage(const T &msg); @@ -257,7 +258,6 @@ private: const std::string &user_id, const mtx::responses::ClaimKeys &res, mtx::http::RequestErr err); - void updateLastMessage(); void readEvent(const std::string &id); QHash events; diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 0a339825..4562dd67 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -16,6 +16,19 @@ Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents) +void +TimelineViewManager::updateEncryptedDescriptions() +{ + QHash>::iterator i; + for (i = models.begin(); i != models.end(); ++i) { + auto ptr = i.value(); + + if (!ptr.isNull()) { + ptr->updateLastMessage(); + } + } +} + void TimelineViewManager::updateColorPalette() { @@ -83,6 +96,10 @@ TimelineViewManager::TimelineViewManager(QSharedPointer userSettin &ChatPage::themeChanged, this, &TimelineViewManager::updateColorPalette); + connect(dynamic_cast(parent), + &ChatPage::decryptSidebarChanged, + this, + &TimelineViewManager::updateEncryptedDescriptions); } void diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h index 122e4aec..45a603af 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h @@ -84,6 +84,7 @@ public slots: const QString &url, const QString &mime, uint64_t dsize); + void updateEncryptedDescriptions(); private: #ifdef USE_QUICK_VIEW From 4720d2b562e97afde19138258e84b0d491137d95 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 23 Apr 2020 02:13:20 +0200 Subject: [PATCH 3/8] Update translations --- resources/langs/nheko_de.ts | 19 ++++++++++++------- resources/langs/nheko_el.ts | 19 ++++++++++++------- resources/langs/nheko_en.ts | 19 ++++++++++++------- resources/langs/nheko_fi.ts | 19 ++++++++++++------- resources/langs/nheko_fr.ts | 19 ++++++++++++------- resources/langs/nheko_ja.ts | 19 ++++++++++++------- resources/langs/nheko_nl.ts | 19 ++++++++++++------- resources/langs/nheko_pl.ts | 19 ++++++++++++------- resources/langs/nheko_ru.ts | 19 ++++++++++++------- resources/langs/nheko_zh_CN.ts | 19 ++++++++++++------- 10 files changed, 120 insertions(+), 70 deletions(-) diff --git a/resources/langs/nheko_de.ts b/resources/langs/nheko_de.ts index 259b5c86..a97c3fb3 100644 --- a/resources/langs/nheko_de.ts +++ b/resources/langs/nheko_de.ts @@ -471,7 +471,7 @@ 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) -- @@ -779,7 +779,7 @@ UserSettingsPage - + Minimize to tray Ins Benachrichtigungsfeld minimieren @@ -800,6 +800,11 @@ + Decrypt messages in sidebar + Entschlüssele Nachrichten in der Raumliste + + + Show buttons in timeline @@ -859,7 +864,7 @@ Gerätefingerabdruck - + Session Keys Sitzungsschlüssel @@ -879,22 +884,22 @@ VERSCHLÜSSELUNG - + GENERAL ALLGEMEINES - + INTERFACE - + Emoji Font Family Emojischriftart - + Open Sessions File Öffne Sessions Datei diff --git a/resources/langs/nheko_el.ts b/resources/langs/nheko_el.ts index 4ce7e6e4..1f4c355c 100644 --- a/resources/langs/nheko_el.ts +++ b/resources/langs/nheko_el.ts @@ -471,7 +471,7 @@ 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. @@ -779,7 +779,7 @@ UserSettingsPage - + Minimize to tray Ελαχιστοποίηση @@ -800,6 +800,11 @@ + Decrypt messages in sidebar + + + + Show buttons in timeline @@ -859,7 +864,7 @@ - + Session Keys @@ -879,22 +884,22 @@ - + GENERAL ΓΕΝΙΚΑ - + INTERFACE - + Emoji Font Family - + Open Sessions File diff --git a/resources/langs/nheko_en.ts b/resources/langs/nheko_en.ts index f7b3b093..52eb4a4c 100644 --- a/resources/langs/nheko_en.ts +++ b/resources/langs/nheko_en.ts @@ -471,7 +471,7 @@ 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) -- @@ -779,7 +779,7 @@ UserSettingsPage - + Minimize to tray Minimize to tray @@ -800,6 +800,11 @@ + Decrypt messages in sidebar + + + + Show buttons in timeline Show buttons in timeline @@ -859,7 +864,7 @@ Device Fingerprint - + Session Keys Session Keys @@ -879,22 +884,22 @@ ENCRYPTION - + GENERAL GENERAL - + INTERFACE INTERFACE - + Emoji Font Family Emoji Font Family - + Open Sessions File Open Sessions File diff --git a/resources/langs/nheko_fi.ts b/resources/langs/nheko_fi.ts index eab4771b..3ab797d8 100644 --- a/resources/langs/nheko_fi.ts +++ b/resources/langs/nheko_fi.ts @@ -471,7 +471,7 @@ 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) -- @@ -779,7 +779,7 @@ UserSettingsPage - + Minimize to tray Pienennä ilmoitusalueelle @@ -800,6 +800,11 @@ + Decrypt messages in sidebar + + + + Show buttons in timeline @@ -859,7 +864,7 @@ Laitteen sormenjälki - + Session Keys Istunnon avaimet @@ -879,22 +884,22 @@ SALAUS - + GENERAL YLEISET ASETUKSET - + INTERFACE - + Emoji Font Family - + Open Sessions File Avaa Istuntoavaintiedosto diff --git a/resources/langs/nheko_fr.ts b/resources/langs/nheko_fr.ts index 472f8c7f..f90ff8c0 100644 --- a/resources/langs/nheko_fr.ts +++ b/resources/langs/nheko_fr.ts @@ -472,7 +472,7 @@ 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. @@ -780,7 +780,7 @@ UserSettingsPage - + Minimize to tray Réduire à la barre des tâches @@ -801,6 +801,11 @@ + Decrypt messages in sidebar + + + + Show buttons in timeline @@ -860,7 +865,7 @@ - + Session Keys @@ -880,22 +885,22 @@ - + GENERAL GÉNÉRAL - + INTERFACE - + Emoji Font Family - + Open Sessions File diff --git a/resources/langs/nheko_ja.ts b/resources/langs/nheko_ja.ts index d3194b42..884ca357 100644 --- a/resources/langs/nheko_ja.ts +++ b/resources/langs/nheko_ja.ts @@ -471,7 +471,7 @@ 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. -- 復号エラー (データベースと通信できませんでした) -- @@ -778,7 +778,7 @@ UserSettingsPage - + Minimize to tray トレイへ最小化 @@ -799,6 +799,11 @@ + Decrypt messages in sidebar + + + + Show buttons in timeline @@ -858,7 +863,7 @@ デバイスの指紋 - + Session Keys セッション鍵 @@ -878,22 +883,22 @@ 暗号化 - + GENERAL 全般 - + INTERFACE - + Emoji Font Family - + Open Sessions File セッションファイルを開く diff --git a/resources/langs/nheko_nl.ts b/resources/langs/nheko_nl.ts index cb4f68e8..88b25e7f 100644 --- a/resources/langs/nheko_nl.ts +++ b/resources/langs/nheko_nl.ts @@ -471,7 +471,7 @@ 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. @@ -779,7 +779,7 @@ UserSettingsPage - + Minimize to tray Minimaliseren naar systeemvak @@ -800,6 +800,11 @@ + Decrypt messages in sidebar + + + + Show buttons in timeline @@ -859,7 +864,7 @@ - + Session Keys @@ -879,22 +884,22 @@ - + GENERAL ALGEMEEN - + INTERFACE - + Emoji Font Family - + Open Sessions File diff --git a/resources/langs/nheko_pl.ts b/resources/langs/nheko_pl.ts index 9fb3bae6..749e172b 100644 --- a/resources/langs/nheko_pl.ts +++ b/resources/langs/nheko_pl.ts @@ -471,7 +471,7 @@ 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. @@ -780,7 +780,7 @@ UserSettingsPage - + Minimize to tray Zminimalizuj do paska zadań @@ -801,6 +801,11 @@ + Decrypt messages in sidebar + + + + Show buttons in timeline @@ -860,7 +865,7 @@ Odcisk palca urządzenia - + Session Keys @@ -880,22 +885,22 @@ SZYFROWANIE - + GENERAL OGÓLNE - + INTERFACE - + Emoji Font Family - + Open Sessions File diff --git a/resources/langs/nheko_ru.ts b/resources/langs/nheko_ru.ts index f48fccf3..05240613 100644 --- a/resources/langs/nheko_ru.ts +++ b/resources/langs/nheko_ru.ts @@ -471,7 +471,7 @@ 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. @@ -780,7 +780,7 @@ UserSettingsPage - + Minimize to tray Сворачивать в системную панель @@ -801,6 +801,11 @@ + Decrypt messages in sidebar + + + + Show buttons in timeline @@ -860,7 +865,7 @@ Отпечаток устройства - + Session Keys Ключи сеанса @@ -880,22 +885,22 @@ ШИФРОВАНИЕ - + GENERAL ГЛАВНОЕ - + INTERFACE - + Emoji Font Family - + Open Sessions File Открыть файл сеансов diff --git a/resources/langs/nheko_zh_CN.ts b/resources/langs/nheko_zh_CN.ts index 63b67734..b6fe6d1d 100644 --- a/resources/langs/nheko_zh_CN.ts +++ b/resources/langs/nheko_zh_CN.ts @@ -471,7 +471,7 @@ 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. @@ -778,7 +778,7 @@ UserSettingsPage - + Minimize to tray 最小化至托盘 @@ -799,6 +799,11 @@ + Decrypt messages in sidebar + + + + Show buttons in timeline @@ -858,7 +863,7 @@ 设备指纹 - + Session Keys 会话密钥 @@ -878,22 +883,22 @@ 加密 - + GENERAL 通用 - + INTERFACE - + Emoji Font Family - + Open Sessions File 打开会话文件 From d5e1475a5c9d9701d191456a577083a650941f92 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 23 Apr 2020 02:29:41 +0200 Subject: [PATCH 4/8] Fix encrypted messages not showing a user in the sidebar --- CHANGELOG.md | 1 + src/Utils.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdd4363c..779d5df6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - 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 +- Fix encrypted messages not showing a user in the sidebar ## [0.7.0] -- 2020-04-19 diff --git a/src/Utils.cpp b/src/Utils.cpp index 33b75894..46472401 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -179,8 +179,9 @@ utils::getMessageDescription(const TimelineEvent &event, const auto ts = QDateTime::fromMSecsSinceEpoch(msg->origin_server_ts); DescInfo info; - info.userid = sender; - info.body = QString(" %1").arg(messageDescription()); + info.userid = sender; + info.body = QString(" %1").arg( + messageDescription(username, "", sender == localUser)); info.timestamp = utils::descriptiveTime(ts); info.event_id = QString::fromStdString(msg->event_id); info.datetime = ts; From b00e624fb0a988d69175c0126f98c96a00b9244f Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 23 Apr 2020 15:28:46 +0200 Subject: [PATCH 5/8] Fix own messages not showing as encrypted --- src/timeline/TimelineModel.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 3e2c32fa..ff1f324e 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -477,14 +477,14 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline) std::vector ids = internalAddEvents(timeline.events); - if (ids.empty()) - return; + if (!ids.empty()) { + beginInsertRows(QModelIndex(), 0, static_cast(ids.size() - 1)); + this->eventOrder.insert(this->eventOrder.begin(), ids.rbegin(), ids.rend()); + endInsertRows(); + } - beginInsertRows(QModelIndex(), 0, static_cast(ids.size() - 1)); - this->eventOrder.insert(this->eventOrder.begin(), ids.rbegin(), ids.rend()); - endInsertRows(); - - updateLastMessage(); + if (!timeline.events.empty()) + updateLastMessage(); } template From 994edb836c0e812933cabf5e0b57f2f8aaaba9a7 Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Thu, 23 Apr 2020 19:05:44 -0400 Subject: [PATCH 6/8] Change how decrypt value is retrieved from settings --- .gitignore | 4 +++- src/timeline/TimelineModel.cpp | 6 ++++++ src/timeline/TimelineModel.h | 3 ++- src/timeline/TimelineViewManager.cpp | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 6d178679..5f6725db 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ cscope* /.ccls-cache /.exrc .gdb_history +.hunter # GTAGS GTAGS @@ -70,7 +71,8 @@ install_manifest.txt .LSOverride # Icon must end with two \r -Icon +Icon + # Thumbnails ._* diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index ff1f324e..75819532 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -514,6 +514,12 @@ TimelineModel::updateLastMessage() { // Get the user setting to show decrypted messages in side bar bool decrypt = QSettings().value("user/decrypt_sidebar", true).toBool(); + updateLastMessage(decrypt); +} + +void +TimelineModel::updateLastMessage(bool decrypt) +{ for (auto it = eventOrder.begin(); it != eventOrder.end(); ++it) { auto event = events.value(*it); if (auto e = std::get_if>( diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 98b183f6..135b31ff 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -189,7 +189,7 @@ public: Q_INVOKABLE void cacheMedia(QString eventId); Q_INVOKABLE bool saveMedia(QString eventId) const; - void updateLastMessage(); + void updateLastMessage(bool); void addEvents(const mtx::responses::Timeline &events); template void sendMessage(const T &msg); @@ -259,6 +259,7 @@ private: const mtx::responses::ClaimKeys &res, mtx::http::RequestErr err); void readEvent(const std::string &id); + void updateLastMessage(); QHash events; QSet read; diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 4562dd67..3c870e36 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -19,12 +19,13 @@ Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents) void TimelineViewManager::updateEncryptedDescriptions() { + auto decrypt = settings->isDecryptSidebarEnabled(); QHash>::iterator i; for (i = models.begin(); i != models.end(); ++i) { auto ptr = i.value(); if (!ptr.isNull()) { - ptr->updateLastMessage(); + ptr->updateLastMessage(decrypt); } } } From 18557023d9e58343585a72a38bd468841b76cdaf Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Thu, 23 Apr 2020 19:06:42 -0400 Subject: [PATCH 7/8] Fix CHANGELOG typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59e6351f..d9670fa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ - 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 Binding restoreMode flooding logs on Qt 5.14.2+ - Fix with some qml styles hidden menu items leave empty space - Fix encrypted messages not showing a user in the sidebar - Fix hangs when generating colors with some system theme color schemes (#172) From 58933654391c699951b322a153bcc3a85bf40552 Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Thu, 23 Apr 2020 19:21:20 -0400 Subject: [PATCH 8/8] Change decrypt setting again --- src/timeline/TimelineModel.cpp | 10 +--------- src/timeline/TimelineModel.h | 5 +++-- src/timeline/TimelineViewManager.cpp | 5 ++++- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 75819532..e3a1a781 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -511,20 +511,12 @@ isMessage(const mtx::events::EncryptedEvent &) void TimelineModel::updateLastMessage() -{ - // Get the user setting to show decrypted messages in side bar - bool decrypt = QSettings().value("user/decrypt_sidebar", true).toBool(); - updateLastMessage(decrypt); -} - -void -TimelineModel::updateLastMessage(bool decrypt) { for (auto it = eventOrder.begin(); it != eventOrder.end(); ++it) { auto event = events.value(*it); if (auto e = std::get_if>( &event)) { - if (decrypt) { + if (decryptDescription) { event = decryptEvent(*e).event; } } diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 135b31ff..ae468c09 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -189,7 +189,7 @@ public: Q_INVOKABLE void cacheMedia(QString eventId); Q_INVOKABLE bool saveMedia(QString eventId) const; - void updateLastMessage(bool); + void updateLastMessage(); void addEvents(const mtx::responses::Timeline &events); template void sendMessage(const T &msg); @@ -224,6 +224,7 @@ public slots: emit replyChanged(reply_); } } + void setDecryptDescription(bool decrypt) { decryptDescription = decrypt; } private slots: // Add old events at the top of the timeline. @@ -259,7 +260,6 @@ private: const mtx::responses::ClaimKeys &res, mtx::http::RequestErr err); void readEvent(const std::string &id); - void updateLastMessage(); QHash events; QSet read; @@ -271,6 +271,7 @@ private: bool isInitialSync = true; bool paginationInProgress = false; + bool decryptDescription = true; QString currentId; QString reply_; diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 3c870e36..b9565be8 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -25,7 +25,8 @@ TimelineViewManager::updateEncryptedDescriptions() auto ptr = i.value(); if (!ptr.isNull()) { - ptr->updateLastMessage(decrypt); + ptr->setDecryptDescription(decrypt); + ptr->updateLastMessage(); } } } @@ -132,6 +133,8 @@ TimelineViewManager::addRoom(const QString &room_id) { if (!models.contains(room_id)) { QSharedPointer newRoom(new TimelineModel(this, room_id)); + newRoom->setDecryptDescription(settings->isDecryptSidebarEnabled()); + connect(newRoom.data(), &TimelineModel::newEncryptedImage, imgProvider,