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:
@@ -55,7 +55,6 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
|
|||||||
roles[ShowReadMarkersRole] = "showReadMarkers";
|
roles[ShowReadMarkersRole] = "showReadMarkers";
|
||||||
roles[ReactionRole] = "reaction";
|
roles[ReactionRole] = "reaction";
|
||||||
roles[ShowReactionsRole] = "showReactions";
|
roles[ShowReactionsRole] = "showReactions";
|
||||||
roles[SourceRole] = "jsonSource";
|
|
||||||
roles[AuthorIdRole] = "authorId";
|
roles[AuthorIdRole] = "authorId";
|
||||||
roles[VerifiedRole] = "verified";
|
roles[VerifiedRole] = "verified";
|
||||||
roles[AuthorDisplayNameRole] = "authorDisplayName";
|
roles[AuthorDisplayNameRole] = "authorDisplayName";
|
||||||
@@ -467,10 +466,6 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
|
|||||||
return eventHandler.getPlainBody();
|
return eventHandler.getPlainBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == SourceRole) {
|
|
||||||
return QJsonDocument(evt.fullJson()).toJson();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (role == DelegateTypeRole) {
|
if (role == DelegateTypeRole) {
|
||||||
return eventHandler.getDelegateType();
|
return eventHandler.getDelegateType();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ public:
|
|||||||
ShowReadMarkersRole, /**< Whether there are any other user read markers to be shown. */
|
ShowReadMarkersRole, /**< Whether there are any other user read markers to be shown. */
|
||||||
ReactionRole, /**< List model for this event. */
|
ReactionRole, /**< List model for this event. */
|
||||||
ShowReactionsRole, /**< Whether there are any reactions to be shown. */
|
ShowReactionsRole, /**< Whether there are any reactions to be shown. */
|
||||||
SourceRole, /**< The full message source JSON. */
|
|
||||||
|
|
||||||
AuthorIdRole, /**< Matrix ID of the message author. */
|
AuthorIdRole, /**< Matrix ID of the message author. */
|
||||||
|
|
||||||
|
|||||||
@@ -184,7 +184,6 @@ QHash<int, QByteArray> SearchModel::roleNames() const
|
|||||||
{MimeTypeRole, "mimeType"},
|
{MimeTypeRole, "mimeType"},
|
||||||
{ShowLinkPreviewRole, "showLinkPreview"},
|
{ShowLinkPreviewRole, "showLinkPreview"},
|
||||||
{LinkPreviewRole, "linkPreview"},
|
{LinkPreviewRole, "linkPreview"},
|
||||||
{SourceRole, "jsonSource"},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ public:
|
|||||||
MimeTypeRole,
|
MimeTypeRole,
|
||||||
ShowLinkPreviewRole,
|
ShowLinkPreviewRole,
|
||||||
LinkPreviewRole,
|
LinkPreviewRole,
|
||||||
SourceRole,
|
|
||||||
};
|
};
|
||||||
Q_ENUM(Roles)
|
Q_ENUM(Roles)
|
||||||
explicit SearchModel(QObject *parent = nullptr);
|
explicit SearchModel(QObject *parent = nullptr);
|
||||||
|
|||||||
@@ -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
|
QString NeoChatRoom::chatBoxText() const
|
||||||
{
|
{
|
||||||
return m_chatBoxText;
|
return m_chatBoxText;
|
||||||
|
|||||||
@@ -551,6 +551,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
Q_INVOKABLE void reportEvent(const QString &eventId, const QString &reason);
|
Q_INVOKABLE void reportEvent(const QString &eventId, const QString &reason);
|
||||||
|
|
||||||
|
Q_INVOKABLE QByteArray getEventJsonSource(const QString &eventId);
|
||||||
|
|
||||||
[[nodiscard]] bool readMarkerLoaded() const;
|
[[nodiscard]] bool readMarkerLoaded() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ Components.AlbumMaximizeComponent {
|
|||||||
|
|
||||||
readonly property var currentProgressInfo: model.data(model.index(content.currentIndex, 0), MessageEventModel.ProgressInfoRole)
|
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 {
|
downloadAction: Components.DownloadAction {
|
||||||
id: downloadAction
|
id: downloadAction
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
@@ -85,7 +83,6 @@ Components.AlbumMaximizeComponent {
|
|||||||
const contextMenu = fileDelegateContextMenu.createObject(parent, {
|
const contextMenu = fileDelegateContextMenu.createObject(parent, {
|
||||||
author: root.currentAuthor,
|
author: root.currentAuthor,
|
||||||
eventId: root.currentEventId,
|
eventId: root.currentEventId,
|
||||||
source: root.currentJsonSource,
|
|
||||||
file: parent,
|
file: parent,
|
||||||
progressInfo: root.currentProgressInfo,
|
progressInfo: root.currentProgressInfo,
|
||||||
plainText: root.currentPlainText
|
plainText: root.currentPlainText
|
||||||
|
|||||||
@@ -212,11 +212,6 @@ ColumnLayout {
|
|||||||
*/
|
*/
|
||||||
required property bool verified
|
required property bool verified
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The full message source JSON.
|
|
||||||
*/
|
|
||||||
required property var jsonSource
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The x position of the message bubble.
|
* @brief The x position of the message bubble.
|
||||||
*
|
*
|
||||||
@@ -609,7 +604,6 @@ ColumnLayout {
|
|||||||
const contextMenu = fileDelegateContextMenu.createObject(root, {
|
const contextMenu = fileDelegateContextMenu.createObject(root, {
|
||||||
author: root.author,
|
author: root.author,
|
||||||
eventId: root.eventId,
|
eventId: root.eventId,
|
||||||
eventSource: root.jsonSource,
|
|
||||||
file: file,
|
file: file,
|
||||||
progressInfo: root.progressInfo,
|
progressInfo: root.progressInfo,
|
||||||
plainText: root.plainText,
|
plainText: root.plainText,
|
||||||
@@ -625,7 +619,6 @@ ColumnLayout {
|
|||||||
selectedText: selectedText,
|
selectedText: selectedText,
|
||||||
author: root.author,
|
author: root.author,
|
||||||
eventId: root.eventId,
|
eventId: root.eventId,
|
||||||
eventSource: root.jsonSource,
|
|
||||||
eventType: root.delegateType,
|
eventType: root.delegateType,
|
||||||
plainText: root.plainText,
|
plainText: root.plainText,
|
||||||
htmlText: root.display,
|
htmlText: root.display,
|
||||||
|
|||||||
@@ -90,15 +90,7 @@ MessageDelegateContextMenu {
|
|||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
text: i18n("View Source")
|
text: i18n("View Source")
|
||||||
icon.name: "code-context"
|
icon.name: "code-context"
|
||||||
onTriggered: {
|
onTriggered: RoomManager.viewEventSource(root.eventId)
|
||||||
applicationWindow().pageStack.pushDialogLayer('qrc:/MessageSourceSheet.qml', {
|
|
||||||
sourceText: root.eventSource
|
|
||||||
}, {
|
|
||||||
title: i18n("Message Source"),
|
|
||||||
width: Kirigami.Units.gridUnit * 25
|
|
||||||
});
|
|
||||||
root.closeFullscreen()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ Loader {
|
|||||||
required property var author
|
required property var author
|
||||||
required property string eventId
|
required property string eventId
|
||||||
property var eventType
|
property var eventType
|
||||||
required property string eventSource
|
|
||||||
property string selectedText: ""
|
property string selectedText: ""
|
||||||
required property string plainText
|
required property string plainText
|
||||||
property string htmlText: undefined
|
property string htmlText: undefined
|
||||||
@@ -87,14 +86,7 @@ Loader {
|
|||||||
visible: Config.developerTools
|
visible: Config.developerTools
|
||||||
text: i18n("View Source")
|
text: i18n("View Source")
|
||||||
icon.name: "code-context"
|
icon.name: "code-context"
|
||||||
onTriggered: {
|
onTriggered: RoomManager.viewEventSource(root.eventId)
|
||||||
applicationWindow().pageStack.pushDialogLayer('qrc:/MessageSourceSheet.qml', {
|
|
||||||
sourceText: root.eventSource
|
|
||||||
}, {
|
|
||||||
title: i18n("Message Source"),
|
|
||||||
width: Kirigami.Units.gridUnit * 25
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
text: i18n("Copy Link")
|
text: i18n("Copy Link")
|
||||||
|
|||||||
@@ -199,6 +199,15 @@ Kirigami.Page {
|
|||||||
function onShowUserDetail(user) {
|
function onShowUserDetail(user) {
|
||||||
root.showUserDetail(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) {
|
function showUserDetail(user) {
|
||||||
|
|||||||
@@ -103,6 +103,11 @@ void RoomManager::maximizeMedia(int index)
|
|||||||
Q_EMIT showMaximizedMedia(index);
|
Q_EMIT showMaximizedMedia(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RoomManager::viewEventSource(const QString &eventId)
|
||||||
|
{
|
||||||
|
Q_EMIT showEventSource(eventId);
|
||||||
|
}
|
||||||
|
|
||||||
bool RoomManager::hasOpenRoom() const
|
bool RoomManager::hasOpenRoom() const
|
||||||
{
|
{
|
||||||
return m_currentRoom != nullptr;
|
return m_currentRoom != nullptr;
|
||||||
|
|||||||
@@ -195,6 +195,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
Q_INVOKABLE void maximizeMedia(int index);
|
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.
|
* @brief Call this when the current used connection is dropped.
|
||||||
*/
|
*/
|
||||||
@@ -261,6 +266,11 @@ Q_SIGNALS:
|
|||||||
*/
|
*/
|
||||||
void showMaximizedMedia(int index);
|
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.
|
* @brief Show the direct chat confirmation dialog.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user