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)
endif()
set(QML_IMPORT_PATH ${CMAKE_SOURCE_DIR}/qml ${CMAKE_BINARY_DIR}/imports CACHE string "" FORCE)
if(WIN32)
enable_language(RC)
include(CMakeDetermineRCCompiler)

View File

@@ -15,7 +15,7 @@ ColumnLayout {
readonly property bool avatarVisible: !sentByMe && showAuthor
readonly property bool sentByMe: author === currentRoom.localUser
readonly property bool darkBackground: !sentByMe
readonly property bool replyVisible: replyEventId || false
readonly property bool replyVisible: reply || false
signal saveFileAs()
signal openExternally()
@@ -144,15 +144,15 @@ ColumnLayout {
Layout.preferredHeight: 28
Layout.alignment: Qt.AlignTop
source: replyVisible ? replyAuthor.avatarMediaId : ""
hint: replyVisible ? replyAuthor.displayName : "H"
source: replyVisible ? reply.author.avatarMediaId : ""
hint: replyVisible ? reply.author.displayName : "H"
RippleEffect {
anchors.fill: parent
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
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
textFormat: Label.RichText
@@ -168,13 +168,13 @@ ColumnLayout {
}
background: Rectangle {
color: replyAuthor && sentByMe ? replyAuthor.color : MPalette.background
color: replyVisible && sentByMe ? reply.author.color : MPalette.background
radius: 18
AutoMouseArea {
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[AnnotationRole] = "annotation";
roles[EventResolvedTypeRole] = "eventResolvedType";
roles[ReplyEventIdRole] = "replyEventId";
roles[ReplyAuthorRole] = "replyAuthor";
roles[ReplyDisplayRole] = "replyDisplay";
roles[ReplyRole] = "reply";
roles[UserMarkerRole] = "userMarker";
roles[ShowAuthorRole] = "showAuthor";
roles[ShowSectionRole] = "showSection";
@@ -404,8 +402,7 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
return variantList;
}
if (role == ReplyEventIdRole || role == ReplyDisplayRole ||
role == ReplyAuthorRole) {
if (role == ReplyRole) {
const QString& replyEventId = evt.contentJson()["m.relates_to"]
.toObject()["m.in_reply_to"]
.toObject()["event_id"]
@@ -416,16 +413,13 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
if (replyIt == m_currentRoom->timelineEdge())
return {};
const auto& replyEvt = **replyIt;
switch (role) {
case ReplyEventIdRole:
return replyEventId;
case ReplyDisplayRole:
return utils::cleanHTML(utils::removeReply(
m_currentRoom->eventToString(replyEvt, Qt::RichText)));
case ReplyAuthorRole:
return QVariant::fromValue(m_currentRoom->user(replyEvt.senderId()));
}
return {};
return QVariantMap{
{"eventId", replyEventId},
{"display", utils::cleanHTML(utils::removeReply(
m_currentRoom->eventToString(replyEvt, Qt::RichText)))},
{"author", QVariant::fromValue(m_currentRoom->user(replyEvt.senderId()))}
};
}
if (role == ShowAuthorRole) {

View File

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