Improve the handling of switching link preivews on and off.
First make sure that the global setting is tied into the room setting, previously it was a bit of a patchwork that worked more by luck than judgement. The two levels of global and room level are properly tied together in a hierarchy. Add a message in the room when global notifcations re turned off. This has caused confusion in the past when people don't realise there are 2 levels.
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <Quotient/events/roommessageevent.h>
|
||||
|
||||
#include "neochatconfig.h"
|
||||
#include "utils.h"
|
||||
|
||||
using namespace Quotient;
|
||||
@@ -22,7 +21,6 @@ LinkPreviewer::LinkPreviewer(const QUrl &url, QObject *parent)
|
||||
Q_ASSERT(dynamic_cast<Connection *>(this->parent()));
|
||||
|
||||
connect(this, &LinkPreviewer::urlChanged, this, &LinkPreviewer::emptyChanged);
|
||||
connect(NeoChatConfig::self(), &NeoChatConfig::ShowLinkPreviewChanged, this, &LinkPreviewer::loadUrlPreview);
|
||||
|
||||
loadUrlPreview();
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -104,6 +104,7 @@
|
||||
</entry>
|
||||
<entry name="ShowLinkPreview" type="bool">
|
||||
<label>Show preview of the links in the chat messages</label>
|
||||
<default>true</default>
|
||||
</entry>
|
||||
<entry name="SystemTray" type="bool">
|
||||
<label>Close NeoChat to system tray</label>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<QUrl, LinkPreviewer> m_linkPreviewers;
|
||||
|
||||
|
||||
@@ -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<NeoChatConnection *>(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<NeoChatConnection *>(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 {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user