Move showAuthor role to MessageModel, so it's available for all models

This fixes features like the search model, where no message delegates
could be created because it's missing showAuthor.
This commit is contained in:
Joshua Goins
2025-01-11 18:05:21 -05:00
committed by James Graham
parent a67ce75924
commit 1d532a1fc1
4 changed files with 7 additions and 3 deletions

View File

@@ -92,7 +92,7 @@ QVariant MessageFilterModel::data(const QModelIndex &index, int role) const
return authorList(mapToSource(index).row()); return authorList(mapToSource(index).row());
} else if (role == ExcessAuthorsRole) { } else if (role == ExcessAuthorsRole) {
return excessAuthors(mapToSource(index).row()); return excessAuthors(mapToSource(index).row());
} else if (role == ShowAuthorRole) { } else if (role == MessageModel::ShowAuthorRole) {
return showAuthor(index); return showAuthor(index);
} }
return QSortFilterProxyModel::data(index, role); return QSortFilterProxyModel::data(index, role);
@@ -105,7 +105,6 @@ QHash<int, QByteArray> MessageFilterModel::roleNames() const
roles[StateEventsRole] = "stateEvents"; roles[StateEventsRole] = "stateEvents";
roles[AuthorListRole] = "authorList"; roles[AuthorListRole] = "authorList";
roles[ExcessAuthorsRole] = "excessAuthors"; roles[ExcessAuthorsRole] = "excessAuthors";
roles[ShowAuthorRole] = "showAuthor";
return roles; return roles;
} }

View File

@@ -34,7 +34,6 @@ public:
StateEventsRole, /**< List of state events in the aggregated state. */ StateEventsRole, /**< List of state events in the aggregated state. */
AuthorListRole, /**< List of the first 5 unique authors of the aggregated state event. */ AuthorListRole, /**< List of the first 5 unique authors of the aggregated state event. */
ExcessAuthorsRole, /**< The number of unique authors beyond the first 5. */ ExcessAuthorsRole, /**< The number of unique authors beyond the first 5. */
ShowAuthorRole, /**< Whether the author of a message should be shown. */
LastRole, // Keep this last LastRole, // Keep this last
}; };

View File

@@ -300,6 +300,10 @@ QVariant MessageModel::data(const QModelIndex &idx, int role) const
&& event.value().get().senderId() == m_room->localMember().id(); && event.value().get().senderId() == m_room->localMember().id();
} }
if (role == ShowAuthorRole) {
return true;
}
return {}; return {};
} }
@@ -329,6 +333,7 @@ QHash<int, QByteArray> MessageModel::roleNames() const
roles[ContentModelRole] = "contentModel"; roles[ContentModelRole] = "contentModel";
roles[MediaInfoRole] = "mediaInfo"; roles[MediaInfoRole] = "mediaInfo";
roles[IsEditableRole] = "isEditable"; roles[IsEditableRole] = "isEditable";
roles[ShowAuthorRole] = "showAuthor";
return roles; return roles;
} }

View File

@@ -84,6 +84,7 @@ public:
IsRedactedRole, /**< Whether an event has been deleted. */ IsRedactedRole, /**< Whether an event has been deleted. */
IsPendingRole, /**< Whether an event is waiting to be accepted by the server. */ IsPendingRole, /**< Whether an event is waiting to be accepted by the server. */
IsEditableRole, /**< Whether the event can be edited by the user. */ IsEditableRole, /**< Whether the event can be edited by the user. */
ShowAuthorRole, /**< Whether the author of a message should be shown. */
LastRole, // Keep this last LastRole, // Keep this last
}; };
Q_ENUM(EventRoles) Q_ENUM(EventRoles)