diff --git a/src/linkpreviewer.cpp b/src/linkpreviewer.cpp index 1fe5ef9bc..7b85ea6ff 100644 --- a/src/linkpreviewer.cpp +++ b/src/linkpreviewer.cpp @@ -9,7 +9,6 @@ #include -#include "neochatconfig.h" #include "utils.h" using namespace Quotient; @@ -22,7 +21,6 @@ LinkPreviewer::LinkPreviewer(const QUrl &url, QObject *parent) Q_ASSERT(dynamic_cast(this->parent())); connect(this, &LinkPreviewer::urlChanged, this, &LinkPreviewer::emptyChanged); - connect(NeoChatConfig::self(), &NeoChatConfig::ShowLinkPreviewChanged, this, &LinkPreviewer::loadUrlPreview); loadUrlPreview(); } diff --git a/src/models/messagecontentmodel.cpp b/src/models/messagecontentmodel.cpp index 245924668..62d398591 100644 --- a/src/models/messagecontentmodel.cpp +++ b/src/models/messagecontentmodel.cpp @@ -132,9 +132,6 @@ void MessageContentModel::initializeModel() connect(m_room, &NeoChatRoom::urlPreviewEnabledChanged, this, [this]() { resetContent(); }); - connect(NeoChatConfig::self(), &NeoChatConfig::ShowLinkPreviewChanged, this, [this]() { - resetContent(); - }); connect(m_room, &Room::memberNameUpdated, this, [this](RoomMember member) { if (m_room != nullptr) { if (senderId().isEmpty() || senderId() == member.id()) { diff --git a/src/neochatconfig.kcfg b/src/neochatconfig.kcfg index e706d0f7e..a2727812e 100644 --- a/src/neochatconfig.kcfg +++ b/src/neochatconfig.kcfg @@ -104,6 +104,7 @@ + true diff --git a/src/neochatconnection.cpp b/src/neochatconnection.cpp index 1e7803f11..007d7e2f5 100644 --- a/src/neochatconnection.cpp +++ b/src/neochatconnection.cpp @@ -145,6 +145,10 @@ void NeoChatConnection::connectSignals() connect(NeoChatConfig::self(), &NeoChatConfig::PreferUsingEncryptionChanged, this, [] { setDirectChatEncryptionDefault(NeoChatConfig::preferUsingEncryption()); }); + setGlobalUrlPreviewEnabled(NeoChatConfig::showLinkPreview()); + connect(NeoChatConfig::self(), &NeoChatConfig::ShowLinkPreviewChanged, this, [this]() { + setGlobalUrlPreviewEnabled(NeoChatConfig::showLinkPreview()); + }); } int NeoChatConnection::badgeNotificationCount() const @@ -167,6 +171,25 @@ void NeoChatConnection::refreshBadgeNotificationCount() } } +bool NeoChatConnection::globalUrlPreviewEnabled() +{ + return m_globalUrlPreviewEnabled; +} + +void NeoChatConnection::setGlobalUrlPreviewEnabled(bool newState) +{ + if (m_globalUrlPreviewEnabled == newState) { + return; + } + + m_globalUrlPreviewEnabled = newState; + if (!m_globalUrlPreviewEnabled) { + m_linkPreviewers.clear(); + } + NeoChatConfig::setShowLinkPreview(m_globalUrlPreviewEnabled); + Q_EMIT globalUrlPreviewEnabledChanged(); +} + void NeoChatConnection::logout(bool serverSideLogout) { SettingsGroup(u"Accounts"_s).remove(userId()); @@ -505,7 +528,7 @@ QString NeoChatConnection::accountDataJsonString(const QString &type) const LinkPreviewer *NeoChatConnection::previewerForLink(const QUrl &link) { - if (!NeoChatConfig::showLinkPreview()) { + if (!m_globalUrlPreviewEnabled) { return nullptr; } diff --git a/src/neochatconnection.h b/src/neochatconnection.h index 68c34d352..51d6f0430 100644 --- a/src/neochatconnection.h +++ b/src/neochatconnection.h @@ -32,6 +32,11 @@ class NeoChatConnection : public Quotient::Connection */ Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) + /** + * @brief Whether URL previews are enabled globally. + */ + Q_PROPERTY(bool globalUrlPreviewEnabled READ globalUrlPreviewEnabled WRITE setGlobalUrlPreviewEnabled NOTIFY globalUrlPreviewEnabledChanged) + /** * @brief The model with the account's 3PIDs. */ @@ -182,6 +187,9 @@ public: int badgeNotificationCount() const; void refreshBadgeNotificationCount(); + bool globalUrlPreviewEnabled(); + void setGlobalUrlPreviewEnabled(bool newState); + bool directChatInvites() const; // note: this is intentionally a copied QString because @@ -196,6 +204,7 @@ public: LinkPreviewer *previewerForLink(const QUrl &link); Q_SIGNALS: + void globalUrlPreviewEnabledChanged(); void labelChanged(); void identityServerChanged(); void directChatNotificationsChanged(); @@ -230,6 +239,7 @@ private: void connectSignals(); int m_badgeNotificationCount = 0; + bool m_globalUrlPreviewEnabled = true; QCache m_linkPreviewers; diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 936c61703..c2ed653d0 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -43,6 +43,7 @@ #include "events/pollevent.h" #include "filetransferpseudojob.h" #include "neochatconfig.h" +#include "neochatconnection.h" #include "neochatroommember.h" #include "roomlastmessageprovider.h" #include "spacehierarchycache.h" @@ -155,6 +156,10 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS Q_EMIT childrenHaveHighlightNotificationsChanged(); } }); + + const auto neochatconnection = static_cast(connection); + Q_ASSERT(neochatconnection); + connect(neochatconnection, &NeoChatConnection::globalUrlPreviewEnabledChanged, this, &NeoChatRoom::urlPreviewEnabledChanged); } bool NeoChatRoom::visible() const @@ -675,6 +680,9 @@ void NeoChatRoom::setDefaultUrlPreviewState(const bool &defaultUrlPreviewState) bool NeoChatRoom::urlPreviewEnabled() const { + if (!static_cast(connection())->globalUrlPreviewEnabled()) { + return false; + } if (hasAccountData("org.matrix.room.preview_urls"_L1)) { return !accountData("org.matrix.room.preview_urls"_L1)->contentJson()["disable"_L1].toBool(); } else { diff --git a/src/settings/RoomGeneralPage.qml b/src/settings/RoomGeneralPage.qml index 66435f111..0ec324b99 100644 --- a/src/settings/RoomGeneralPage.qml +++ b/src/settings/RoomGeneralPage.qml @@ -267,6 +267,7 @@ FormCard.FormCardPage { } } FormCard.FormCheckDelegate { + enabled: root.connection.globalUrlPreviewEnabled text: i18n("Enable URL previews") // Most users won't see the above setting so tell them the default. description: room.defaultUrlPreviewState ? i18n("URL previews are enabled by default in this room") : i18n("URL previews are disabled by default in this room") @@ -276,6 +277,19 @@ FormCard.FormCardPage { } } } + Kirigami.InlineMessage { + Layout.fillWidth: true + Layout.maximumWidth: Kirigami.Units.gridUnit * 30 + Layout.topMargin: Kirigami.Units.largeSpacing + Layout.alignment: Qt.AlignHCenter + text: i18nc("As in the user has switched off showing previews of hyperlinks in timeline messages", "URL previews are currently disabled for your account") + type: Kirigami.MessageType.Information + visible: !root.connection.globalUrlPreviewEnabled + actions: Kirigami.Action { + text: i18n("Enable") + onTriggered: root.connection.globalUrlPreviewEnabled = true + } + } FormCard.FormHeader { title: i18n("Official Parent Spaces") }