Display room messages and other events

This commit is contained in:
miruka
2019-04-14 12:56:30 -04:00
parent 5c8fd4500d
commit 9c66166c4f
16 changed files with 340 additions and 110 deletions

View File

@@ -10,11 +10,16 @@ Column {
return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000)
}
readonly property bool isMessage: type.startsWith("RoomMessage")
readonly property bool isUndecryptableEvent:
type === "OlmEvent" || type === "MegolmEvent"
readonly property string displayName:
Backend.getUser(chatPage.room.room_id, sender_id).display_name
Backend.getUser(dict.sender).display_name
readonly property bool isOwn:
chatPage.user.user_id === sender_id
chatPage.user_id === dict.sender
readonly property var previousData:
index > 0 ? messageListView.model.get(index - 1) : null
@@ -23,7 +28,8 @@ Column {
readonly property bool combine:
! isFirstMessage &&
previousData.sender_id == sender_id &&
previousData.isMessage === isMessage &&
previousData.dict.sender === dict.sender &&
mins_between(previousData.date_time, date_time) <= 5
readonly property bool dayBreak:
@@ -49,59 +55,7 @@ Column {
Daybreak { visible: dayBreak }
MessageContent { visible: isMessage || isUndecryptableEvent }
Row {
id: row
spacing: standardSpacing
layoutDirection: isOwn ? Qt.RightToLeft : Qt.LeftToRight
anchors.right: isOwn ? parent.right : undefined
Base.Avatar { id: avatar; invisible: combine; name: displayName }
ColumnLayout {
spacing: 0
Base.HLabel {
visible: ! combine
id: nameLabel
text: displayName
background: Rectangle {color: "#DDD"}
color: isOwn ? "teal" : "purple"
elide: Text.ElideRight
maximumLineCount: 1
Layout.preferredWidth: contentLabel.width
horizontalAlignment: isOwn ? Text.AlignRight : Text.AlignLeft
leftPadding: horizontalPadding
rightPadding: horizontalPadding
topPadding: verticalPadding
}
Base.HLabel {
id: contentLabel
//text: (isOwn ? "" : content + "&nbsp;&nbsp;") +
//"<font size=" + smallSize + "px color=gray>" +
//Qt.formatDateTime(date_time, "hh:mm:ss") +
//"</font>" +
// (isOwn ? "&nbsp;&nbsp;" + content : "")
text: content +
"&nbsp;&nbsp;<font size=" + smallSize + "px color=gray>" +
Qt.formatDateTime(date_time, "hh:mm:ss") +
"</font>"
textFormat: Text.RichText
background: Rectangle {color: "#DDD"}
wrapMode: Text.Wrap
leftPadding: horizontalPadding
rightPadding: horizontalPadding
bottomPadding: verticalPadding
Layout.minimumWidth: nameLabel.implicitWidth
Layout.maximumWidth: Math.min(
600, messageListView.width - avatar.width - row.spacing
)
}
}
}
EventContent { visible: ! (isMessage || isUndecryptableEvent) }
}