From 07dd1d2e914c42fc005602fd1e9f710e440c9529 Mon Sep 17 00:00:00 2001 From: James Graham Date: Sat, 24 Aug 2024 16:37:51 +0000 Subject: [PATCH] Make sure that the reply message is hidden if a user is ignored. This will hide the content when a user ignores and re show it if unignored in the same session. Note: If the client is restarted the rely will be blanked as the server refuses to send the message. However if unignoring a restart is currently required to get the full timeline back. This can't be trivially fixed as it takes a bit of time for the server to deal with the unblock and allow the message to be downloaded. With no signals available to jump off we'd just have to poll the endpoint which considering this is not going to happen often seems like a bad idea for minimal gain. Closes network/neochat#657 --- src/models/messagecontentmodel.cpp | 36 ++++++++++++++++++++++++++++-- src/models/messagecontentmodel.h | 1 + src/neochatroom.cpp | 5 +++++ src/neochatroom.h | 1 + 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/models/messagecontentmodel.cpp b/src/models/messagecontentmodel.cpp index f579a7bf3..1647e04fd 100644 --- a/src/models/messagecontentmodel.cpp +++ b/src/models/messagecontentmodel.cpp @@ -10,9 +10,10 @@ #include #include #include +#include #include -#include +#include #ifndef Q_OS_ANDROID #include @@ -62,6 +63,7 @@ void MessageContentModel::initializeModel() Quotient::connectUntil(m_room.get(), &NeoChatRoom::extraEventLoaded, this, [this](const QString &eventId) { if (m_room != nullptr) { if (eventId == m_eventId) { + m_notFound = false; intiializeEvent(m_room->getEvent(eventId)); updateReplyModel(); resetModel(); @@ -70,6 +72,16 @@ void MessageContentModel::initializeModel() } return false; }); + Quotient::connectUntil(m_room.get(), &NeoChatRoom::extraEventNotFound, this, [this](const QString &eventId) { + if (m_room != nullptr) { + if (eventId == m_eventId) { + m_notFound = true; + resetModel(); + return true; + } + } + return false; + }); if (m_event == nullptr) { m_room->getEvent(m_eventId); @@ -203,7 +215,7 @@ void MessageContentModel::setShowAuthor(bool showAuthor) } m_showAuthor = showAuthor; - if (m_event != nullptr) { + if (m_event != nullptr && m_room->connection()->ignoredUsers().contains(m_event->senderId())) { if (showAuthor) { beginInsertRows({}, 0, 0); m_components.prepend(MessageComponent{MessageComponentType::Author, QString(), {}}); @@ -233,6 +245,20 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const const auto component = m_components[index.row()]; if (role == DisplayRole) { + if (m_notFound || (m_event && m_room->connection()->ignoredUsers().contains(m_event->senderId()))) { + Kirigami::Platform::PlatformTheme *theme = + static_cast(qmlAttachedPropertiesObject(this, true)); + + QString disabledTextColor; + if (theme != nullptr) { + disabledTextColor = theme->disabledTextColor().name(); + } else { + disabledTextColor = QStringLiteral("#000000"); + } + return QString(QStringLiteral("").arg(disabledTextColor) + + i18nc("@info", "This message was either not found, you do not have permission to view it, or it was sent by an ignored user") + + QStringLiteral("")); + } if (component.type == MessageComponentType::Loading && m_isReply) { return i18n("Loading reply"); } @@ -354,6 +380,12 @@ void MessageContentModel::resetModel() beginResetModel(); m_components.clear(); + if ((m_event && m_room->connection()->ignoredUsers().contains(m_event->senderId())) || m_notFound) { + m_components += MessageComponent{MessageComponentType::Text, QString(), {}}; + endResetModel(); + return; + } + if (m_event == nullptr) { m_components += MessageComponent{MessageComponentType::Loading, QString(), {}}; endResetModel(); diff --git a/src/models/messagecontentmodel.h b/src/models/messagecontentmodel.h index 827c00b3c..70f7c9bb8 100644 --- a/src/models/messagecontentmodel.h +++ b/src/models/messagecontentmodel.h @@ -125,6 +125,7 @@ private: bool m_isPending; bool m_showAuthor = true; bool m_isReply; + bool m_notFound = false; void initializeModel(); void intiializeEvent(const QString &eventId); diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 42facf326..89aedbfa1 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -1778,6 +1778,11 @@ void NeoChatRoom::downloadEventFromServer(const QString &eventId) m_extraEvents.push_back(std::move(event)); Q_EMIT extraEventLoaded(eventId); }); + connect(job, &BaseJob::failure, this, [this, job, eventId] { + if (job->error() == BaseJob::NotFound) { + Q_EMIT extraEventNotFound(eventId); + } + }); } const RoomEvent *NeoChatRoom::getEvent(const QString &eventId) const diff --git a/src/neochatroom.h b/src/neochatroom.h index 987a83e61..695f5f03b 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -655,6 +655,7 @@ Q_SIGNALS: void urlPreviewEnabledChanged(); void maxRoomVersionChanged(); void extraEventLoaded(const QString &eventId); + void extraEventNotFound(const QString &eventId); public Q_SLOTS: /**