diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ChatPage.h | 1 | ||||
-rw-r--r-- | src/MainWindow.cpp | 4 | ||||
-rw-r--r-- | src/Olm.cpp | 2 | ||||
-rw-r--r-- | src/UserSettingsPage.cpp | 11 | ||||
-rw-r--r-- | src/UserSettingsPage.h | 10 | ||||
-rw-r--r-- | src/Utils.cpp | 5 | ||||
-rw-r--r-- | src/Utils.h | 1 | ||||
-rw-r--r-- | src/timeline/TimelineModel.cpp | 26 | ||||
-rw-r--r-- | src/timeline/TimelineModel.h | 4 | ||||
-rw-r--r-- | src/timeline/TimelineViewManager.cpp | 21 | ||||
-rw-r--r-- | src/timeline/TimelineViewManager.h | 1 |
11 files changed, 72 insertions, 14 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 b4f4cb45..4db883f5 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<UserSettings> 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<UserSettings> 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,11 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge settings_->setGroupView(!isDisabled); }); + connect(decryptSidebar_, &Toggle::toggled, this, [this](bool isDisabled) { + settings_->setDecryptSidebar(!isDisabled); + emit decryptSidebarChanged(); + }); + connect(avatarCircles_, &Toggle::toggled, this, [this](bool isDisabled) { settings_->setAvatarCircles(!isDisabled); }); @@ -479,6 +487,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..6b9834ea 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_; @@ -175,6 +183,7 @@ signals: void moveBack(); void trayOptionChanged(bool value); void themeChanged(); + void decryptSidebarChanged(); private slots: void importSessionKeys(); @@ -199,6 +208,7 @@ private: Toggle *markdownEnabled_; Toggle *desktopNotifications_; Toggle *avatarCircles_; + Toggle *decryptSidebar_; QLabel *deviceFingerprintValue_; QLabel *deviceIdValue_; diff --git a/src/Utils.cpp b/src/Utils.cpp index 62a1a3c8..cd615c24 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<Encrypted>()); + info.userid = sender; + info.body = QString(" %1").arg( + messageDescription<Encrypted>(username, "", sender == localUser)); info.timestamp = utils::descriptiveTime(ts); info.event_id = QString::fromStdString(msg->event_id); info.datetime = ts; 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..e3a1a781 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -8,6 +8,7 @@ #include <QFileDialog> #include <QMimeDatabase> #include <QRegularExpression> +#include <QSettings> #include <QStandardPaths> #include "ChatPage.h" @@ -476,14 +477,14 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline) std::vector<QString> ids = internalAddEvents(timeline.events); - if (ids.empty()) - return; - - beginInsertRows(QModelIndex(), 0, static_cast<int>(ids.size() - 1)); - this->eventOrder.insert(this->eventOrder.begin(), ids.rbegin(), ids.rend()); - endInsertRows(); + if (!ids.empty()) { + beginInsertRows(QModelIndex(), 0, static_cast<int>(ids.size() - 1)); + this->eventOrder.insert(this->eventOrder.begin(), ids.rbegin(), ids.rend()); + endInsertRows(); + } - updateLastMessage(); + if (!timeline.events.empty()) + updateLastMessage(); } template<typename T> @@ -501,6 +502,13 @@ isMessage(const mtx::events::Event<T> &) return false; } +template<typename T> +auto +isMessage(const mtx::events::EncryptedEvent<T> &) +{ + return true; +} + void TimelineModel::updateLastMessage() { @@ -508,7 +516,9 @@ TimelineModel::updateLastMessage() auto event = events.value(*it); if (auto e = std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( &event)) { - event = decryptEvent(*e).event; + if (decryptDescription) { + event = decryptEvent(*e).event; + } } if (!std::visit([](const auto &e) -> bool { return isMessage(e); }, event)) diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 84e9ec26..ae468c09 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<class T> void sendMessage(const T &msg); @@ -223,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. @@ -257,7 +259,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<QString, mtx::events::collections::TimelineEvents> events; @@ -270,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 0a339825..b9565be8 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -17,6 +17,21 @@ Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents) void +TimelineViewManager::updateEncryptedDescriptions() +{ + auto decrypt = settings->isDecryptSidebarEnabled(); + QHash<QString, QSharedPointer<TimelineModel>>::iterator i; + for (i = models.begin(); i != models.end(); ++i) { + auto ptr = i.value(); + + if (!ptr.isNull()) { + ptr->setDecryptDescription(decrypt); + ptr->updateLastMessage(); + } + } +} + +void TimelineViewManager::updateColorPalette() { userColors.clear(); @@ -83,6 +98,10 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin &ChatPage::themeChanged, this, &TimelineViewManager::updateColorPalette); + connect(dynamic_cast<ChatPage *>(parent), + &ChatPage::decryptSidebarChanged, + this, + &TimelineViewManager::updateEncryptedDescriptions); } void @@ -114,6 +133,8 @@ TimelineViewManager::addRoom(const QString &room_id) { if (!models.contains(room_id)) { QSharedPointer<TimelineModel> newRoom(new TimelineModel(this, room_id)); + newRoom->setDecryptDescription(settings->isDecryptSidebarEnabled()); + connect(newRoom.data(), &TimelineModel::newEncryptedImage, imgProvider, 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 |