EventSource Refactor

Move showing th event source to a call to RoomManager. This means the SourceRole is no longer required in the message and search models
This commit is contained in:
James Graham
2023-09-15 10:54:04 +00:00
parent ec4c156a8c
commit c04ddfde26
13 changed files with 38 additions and 36 deletions

View File

@@ -55,7 +55,6 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
roles[ShowReadMarkersRole] = "showReadMarkers";
roles[ReactionRole] = "reaction";
roles[ShowReactionsRole] = "showReactions";
roles[SourceRole] = "jsonSource";
roles[AuthorIdRole] = "authorId";
roles[VerifiedRole] = "verified";
roles[AuthorDisplayNameRole] = "authorDisplayName";
@@ -467,10 +466,6 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
return eventHandler.getPlainBody();
}
if (role == SourceRole) {
return QJsonDocument(evt.fullJson()).toJson();
}
if (role == DelegateTypeRole) {
return eventHandler.getDelegateType();
}

View File

@@ -70,7 +70,6 @@ public:
ShowReadMarkersRole, /**< Whether there are any other user read markers to be shown. */
ReactionRole, /**< List model for this event. */
ShowReactionsRole, /**< Whether there are any reactions to be shown. */
SourceRole, /**< The full message source JSON. */
AuthorIdRole, /**< Matrix ID of the message author. */

View File

@@ -184,7 +184,6 @@ QHash<int, QByteArray> SearchModel::roleNames() const
{MimeTypeRole, "mimeType"},
{ShowLinkPreviewRole, "showLinkPreview"},
{LinkPreviewRole, "linkPreview"},
{SourceRole, "jsonSource"},
};
}

View File

@@ -83,7 +83,6 @@ public:
MimeTypeRole,
ShowLinkPreviewRole,
LinkPreviewRole,
SourceRole,
};
Q_ENUM(Roles)
explicit SearchModel(QObject *parent = nullptr);

View File

@@ -1334,6 +1334,16 @@ void NeoChatRoom::reportEvent(const QString &eventId, const QString &reason)
});
}
QByteArray NeoChatRoom::getEventJsonSource(const QString &eventId)
{
auto evtIt = findInTimeline(eventId);
if (evtIt != messageEvents().rend() && is<RoomEvent>(**evtIt)) {
const auto event = evtIt->viewAs<RoomEvent>();
return QJsonDocument(event->fullJson()).toJson();
}
return {};
}
QString NeoChatRoom::chatBoxText() const
{
return m_chatBoxText;

View File

@@ -551,6 +551,8 @@ public:
*/
Q_INVOKABLE void reportEvent(const QString &eventId, const QString &reason);
Q_INVOKABLE QByteArray getEventJsonSource(const QString &eventId);
[[nodiscard]] bool readMarkerLoaded() const;
/**

View File

@@ -26,8 +26,6 @@ Components.AlbumMaximizeComponent {
readonly property var currentProgressInfo: model.data(model.index(content.currentIndex, 0), MessageEventModel.ProgressInfoRole)
readonly property var currentJsonSource: model.data(model.index(content.currentIndex, 0), MessageEventModel.SourceRole)
downloadAction: Components.DownloadAction {
id: downloadAction
onTriggered: {
@@ -85,7 +83,6 @@ Components.AlbumMaximizeComponent {
const contextMenu = fileDelegateContextMenu.createObject(parent, {
author: root.currentAuthor,
eventId: root.currentEventId,
source: root.currentJsonSource,
file: parent,
progressInfo: root.currentProgressInfo,
plainText: root.currentPlainText

View File

@@ -212,11 +212,6 @@ ColumnLayout {
*/
required property bool verified
/**
* @brief The full message source JSON.
*/
required property var jsonSource
/**
* @brief The x position of the message bubble.
*
@@ -609,7 +604,6 @@ ColumnLayout {
const contextMenu = fileDelegateContextMenu.createObject(root, {
author: root.author,
eventId: root.eventId,
eventSource: root.jsonSource,
file: file,
progressInfo: root.progressInfo,
plainText: root.plainText,
@@ -625,7 +619,6 @@ ColumnLayout {
selectedText: selectedText,
author: root.author,
eventId: root.eventId,
eventSource: root.jsonSource,
eventType: root.delegateType,
plainText: root.plainText,
htmlText: root.display,

View File

@@ -90,15 +90,7 @@ MessageDelegateContextMenu {
Kirigami.Action {
text: i18n("View Source")
icon.name: "code-context"
onTriggered: {
applicationWindow().pageStack.pushDialogLayer('qrc:/MessageSourceSheet.qml', {
sourceText: root.eventSource
}, {
title: i18n("Message Source"),
width: Kirigami.Units.gridUnit * 25
});
root.closeFullscreen()
}
onTriggered: RoomManager.viewEventSource(root.eventId)
}
]

View File

@@ -16,7 +16,6 @@ Loader {
required property var author
required property string eventId
property var eventType
required property string eventSource
property string selectedText: ""
required property string plainText
property string htmlText: undefined
@@ -87,14 +86,7 @@ Loader {
visible: Config.developerTools
text: i18n("View Source")
icon.name: "code-context"
onTriggered: {
applicationWindow().pageStack.pushDialogLayer('qrc:/MessageSourceSheet.qml', {
sourceText: root.eventSource
}, {
title: i18n("Message Source"),
width: Kirigami.Units.gridUnit * 25
});
}
onTriggered: RoomManager.viewEventSource(root.eventId)
},
Kirigami.Action {
text: i18n("Copy Link")

View File

@@ -199,6 +199,15 @@ Kirigami.Page {
function onShowUserDetail(user) {
root.showUserDetail(user)
}
function onShowEventSource(eventId) {
applicationWindow().pageStack.pushDialogLayer('qrc:/MessageSourceSheet.qml', {
sourceText: root.currentRoom.getEventJsonSource(eventId)
}, {
title: i18n("Message Source"),
width: Kirigami.Units.gridUnit * 25
});
}
}
function showUserDetail(user) {

View File

@@ -103,6 +103,11 @@ void RoomManager::maximizeMedia(int index)
Q_EMIT showMaximizedMedia(index);
}
void RoomManager::viewEventSource(const QString &eventId)
{
Q_EMIT showEventSource(eventId);
}
bool RoomManager::hasOpenRoom() const
{
return m_currentRoom != nullptr;

View File

@@ -195,6 +195,11 @@ public:
*/
Q_INVOKABLE void maximizeMedia(int index);
/**
* @brief Show the JSON source for the given event Matrix ID
*/
Q_INVOKABLE void viewEventSource(const QString &eventId);
/**
* @brief Call this when the current used connection is dropped.
*/
@@ -261,6 +266,11 @@ Q_SIGNALS:
*/
void showMaximizedMedia(int index);
/**
* @brief Request the JSON source for the given event ID is shown.
*/
void showEventSource(const QString &eventId);
/**
* @brief Show the direct chat confirmation dialog.
*