Clean up reply.

This commit is contained in:
Black Hat
2019-07-21 13:01:33 +08:00
parent f0735981cd
commit 992cbaca87
5 changed files with 23 additions and 27 deletions

View File

@@ -64,6 +64,8 @@ if (Qt5_POSITION_INDEPENDENT_CODE)
SET(CMAKE_POSITION_INDEPENDENT_CODE ON) SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif() endif()
set(QML_IMPORT_PATH ${CMAKE_SOURCE_DIR}/qml ${CMAKE_BINARY_DIR}/imports CACHE string "" FORCE)
if(WIN32) if(WIN32)
enable_language(RC) enable_language(RC)
include(CMakeDetermineRCCompiler) include(CMakeDetermineRCCompiler)

View File

@@ -15,7 +15,7 @@ ColumnLayout {
readonly property bool avatarVisible: !sentByMe && showAuthor readonly property bool avatarVisible: !sentByMe && showAuthor
readonly property bool sentByMe: author === currentRoom.localUser readonly property bool sentByMe: author === currentRoom.localUser
readonly property bool darkBackground: !sentByMe readonly property bool darkBackground: !sentByMe
readonly property bool replyVisible: replyEventId || false readonly property bool replyVisible: reply || false
signal saveFileAs() signal saveFileAs()
signal openExternally() signal openExternally()
@@ -144,15 +144,15 @@ ColumnLayout {
Layout.preferredHeight: 28 Layout.preferredHeight: 28
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
source: replyVisible ? replyAuthor.avatarMediaId : "" source: replyVisible ? reply.author.avatarMediaId : ""
hint: replyVisible ? replyAuthor.displayName : "H" hint: replyVisible ? reply.author.displayName : "H"
RippleEffect { RippleEffect {
anchors.fill: parent anchors.fill: parent
circular: true circular: true
onClicked: userDetailDialog.createObject(ApplicationWindow.overlay, {"room": currentRoom, "user": replyAuthor}).open() onClicked: userDetailDialog.createObject(ApplicationWindow.overlay, {"room": currentRoom, "user": reply.author}).open()
} }
} }
@@ -160,7 +160,7 @@ ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
color: !sentByMe ? MPalette.foreground : "white" color: !sentByMe ? MPalette.foreground : "white"
text: "<style>a{color: " + color + ";} .user-pill{}</style>" + (replyDisplay || "") text: "<style>a{color: " + color + ";} .user-pill{}</style>" + (replyVisible ? reply.display : "")
wrapMode: Label.Wrap wrapMode: Label.Wrap
textFormat: Label.RichText textFormat: Label.RichText
@@ -168,13 +168,13 @@ ColumnLayout {
} }
background: Rectangle { background: Rectangle {
color: replyAuthor && sentByMe ? replyAuthor.color : MPalette.background color: replyVisible && sentByMe ? reply.author.color : MPalette.background
radius: 18 radius: 18
AutoMouseArea { AutoMouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: goToEvent(replyEventId) onClicked: goToEvent(reply.eventId)
} }
} }
} }

View File

@@ -30,9 +30,7 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const {
roles[LongOperationRole] = "progressInfo"; roles[LongOperationRole] = "progressInfo";
roles[AnnotationRole] = "annotation"; roles[AnnotationRole] = "annotation";
roles[EventResolvedTypeRole] = "eventResolvedType"; roles[EventResolvedTypeRole] = "eventResolvedType";
roles[ReplyEventIdRole] = "replyEventId"; roles[ReplyRole] = "reply";
roles[ReplyAuthorRole] = "replyAuthor";
roles[ReplyDisplayRole] = "replyDisplay";
roles[UserMarkerRole] = "userMarker"; roles[UserMarkerRole] = "userMarker";
roles[ShowAuthorRole] = "showAuthor"; roles[ShowAuthorRole] = "showAuthor";
roles[ShowSectionRole] = "showSection"; roles[ShowSectionRole] = "showSection";
@@ -404,8 +402,7 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
return variantList; return variantList;
} }
if (role == ReplyEventIdRole || role == ReplyDisplayRole || if (role == ReplyRole) {
role == ReplyAuthorRole) {
const QString& replyEventId = evt.contentJson()["m.relates_to"] const QString& replyEventId = evt.contentJson()["m.relates_to"]
.toObject()["m.in_reply_to"] .toObject()["m.in_reply_to"]
.toObject()["event_id"] .toObject()["event_id"]
@@ -416,16 +413,13 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
if (replyIt == m_currentRoom->timelineEdge()) if (replyIt == m_currentRoom->timelineEdge())
return {}; return {};
const auto& replyEvt = **replyIt; const auto& replyEvt = **replyIt;
switch (role) {
case ReplyEventIdRole: return QVariantMap{
return replyEventId; {"eventId", replyEventId},
case ReplyDisplayRole: {"display", utils::cleanHTML(utils::removeReply(
return utils::cleanHTML(utils::removeReply( m_currentRoom->eventToString(replyEvt, Qt::RichText)))},
m_currentRoom->eventToString(replyEvt, Qt::RichText))); {"author", QVariant::fromValue(m_currentRoom->user(replyEvt.senderId()))}
case ReplyAuthorRole: };
return QVariant::fromValue(m_currentRoom->user(replyEvt.senderId()));
}
return {};
} }
if (role == ShowAuthorRole) { if (role == ShowAuthorRole) {

View File

@@ -26,14 +26,14 @@ class MessageEventModel : public QAbstractListModel {
LongOperationRole, LongOperationRole,
AnnotationRole, AnnotationRole,
UserMarkerRole, UserMarkerRole,
// For reply
ReplyEventIdRole, ReplyRole,
ReplyAuthorRole,
ReplyDisplayRole,
ShowAuthorRole, ShowAuthorRole,
ShowSectionRole, ShowSectionRole,
BubbleShapeRole, BubbleShapeRole,
// For debugging // For debugging
EventResolvedTypeRole, EventResolvedTypeRole,
}; };