Init rich reply.
This commit is contained in:
parent
948da868a9
commit
cc5ba20375
|
@ -93,12 +93,77 @@ ColumnLayout {
|
|||
}
|
||||
}
|
||||
|
||||
contentItem: TextEdit {
|
||||
contentItem: ColumnLayout {
|
||||
Control {
|
||||
Layout.fillWidth: true
|
||||
|
||||
visible: replyEventId || ""
|
||||
|
||||
background: MouseArea {
|
||||
onClicked: goToEvent(replyEventId)
|
||||
}
|
||||
|
||||
contentItem: RowLayout {
|
||||
spacing: 4
|
||||
|
||||
Rectangle {
|
||||
Layout.preferredWidth: 2
|
||||
Layout.fillHeight: true
|
||||
|
||||
color: "white"
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
|
||||
spacing: 0
|
||||
|
||||
Control {
|
||||
padding: 4
|
||||
|
||||
contentItem: RowLayout {
|
||||
spacing: 4
|
||||
|
||||
ImageItem {
|
||||
Layout.preferredWidth: 16
|
||||
Layout.preferredHeight: 16
|
||||
|
||||
source: replyAuthor ? replyAuthor.paintable : null
|
||||
}
|
||||
|
||||
Label {
|
||||
color: "white"
|
||||
text: replyAuthor ? replyAuthor.displayName : ""
|
||||
}
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
color: "black"
|
||||
opacity: 0.2
|
||||
radius: height / 2
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
|
||||
text: "<style>a{color: white;} .user-pill{}</style>" + (replyDisplay ? replyDisplay.replace(/<mx-reply>.*<\/mx-reply>/g, "") : "")
|
||||
|
||||
color: "white"
|
||||
|
||||
wrapMode: Label.Wrap
|
||||
textFormat: Label.RichText
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TextEdit {
|
||||
Layout.fillWidth: true
|
||||
|
||||
id: contentLabel
|
||||
|
||||
text: "<style>a{color: white;} .user-pill{}</style>" + display
|
||||
text: "<style>a{color: white;} .user-pill{}</style>" + (replyEventId ? display.replace(/<mx-reply>.*<\/mx-reply>/g, "") : display)
|
||||
|
||||
color: "white"
|
||||
|
||||
|
@ -132,3 +197,4 @@ ColumnLayout {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,9 @@ 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[UserMarkerRole] = "userMarker";
|
||||
return roles;
|
||||
}
|
||||
|
@ -372,6 +375,28 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const {
|
|||
return variantList;
|
||||
}
|
||||
|
||||
if (role == ReplyEventIdRole || role == ReplyDisplayRole ||
|
||||
role == ReplyAuthorRole) {
|
||||
const QString &replyEventId = evt.contentJson()["m.relates_to"]
|
||||
.toObject()["m.in_reply_to"]
|
||||
.toObject()["event_id"]
|
||||
.toString();
|
||||
if (replyEventId.isEmpty()) return {};
|
||||
const auto replyIt = m_currentRoom->findInTimeline(replyEventId);
|
||||
if (replyIt == m_currentRoom->timelineEdge()) return {};
|
||||
const auto& replyEvt = **replyIt;
|
||||
switch (role) {
|
||||
case ReplyEventIdRole:
|
||||
return replyEventId;
|
||||
case ReplyDisplayRole:
|
||||
return utils::eventToString(replyEvt, m_currentRoom, Qt::RichText);
|
||||
case ReplyAuthorRole:
|
||||
return QVariant::fromValue(
|
||||
m_currentRoom->user(replyEvt.senderId()));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
if (role == AboveEventTypeRole || role == AboveSectionRole ||
|
||||
role == AboveAuthorRole || role == AboveTimeRole)
|
||||
for (auto r = row + 1; r < rowCount(); ++r) {
|
||||
|
|
|
@ -30,6 +30,9 @@ class MessageEventModel : public QAbstractListModel {
|
|||
LongOperationRole,
|
||||
AnnotationRole,
|
||||
UserMarkerRole,
|
||||
ReplyEventIdRole,
|
||||
ReplyAuthorRole,
|
||||
ReplyDisplayRole,
|
||||
// For debugging
|
||||
EventResolvedTypeRole,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue