Add support for non-message room events
This commit is contained in:
@@ -7,11 +7,18 @@ Row {
|
||||
spacing: standardSpacing / 2
|
||||
layoutDirection: isOwn ? Qt.RightToLeft : Qt.LeftToRight
|
||||
|
||||
function textHueForName(name) { // TODO: move
|
||||
return Qt.hsla(avatar.hueFromName(name),
|
||||
HStyle.displayName.saturation,
|
||||
HStyle.displayName.lightness,
|
||||
1)
|
||||
}
|
||||
|
||||
HAvatar {
|
||||
id: avatar
|
||||
hidden: combine
|
||||
name: senderInfo.displayName || stripUserId(model.senderId)
|
||||
dimension: 48
|
||||
dimension: model.showNameLine ? 48 : 28
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
@@ -33,16 +40,13 @@ Row {
|
||||
anchors.fill: parent
|
||||
|
||||
HLabel {
|
||||
height: combine ? 0 : implicitHeight
|
||||
width: parent.width
|
||||
height: model.showNameLine && ! combine ? implicitHeight : 0
|
||||
visible: height > 0
|
||||
|
||||
id: nameLabel
|
||||
text: senderInfo.displayName || model.senderId
|
||||
color: Qt.hsla(avatar.hueFromName(avatar.name),
|
||||
HStyle.displayName.saturation,
|
||||
HStyle.displayName.lightness,
|
||||
1)
|
||||
color: textHueForName(avatar.name)
|
||||
elide: Text.ElideRight
|
||||
maximumLineCount: 1
|
||||
horizontalAlignment: isOwn ? Text.AlignRight : Text.AlignLeft
|
||||
@@ -53,10 +57,49 @@ Row {
|
||||
}
|
||||
|
||||
HRichLabel {
|
||||
function escapeHtml(text) { // TODO: move this
|
||||
return text.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace('"', """)
|
||||
.replace("'", "'")
|
||||
}
|
||||
|
||||
function translate(text) {
|
||||
if (model.translatable == false) { return text }
|
||||
|
||||
text = text.replace(
|
||||
"%S",
|
||||
"<font color='" + nameLabel.color + "'>" +
|
||||
escapeHtml(senderInfo.displayName || model.senderId) +
|
||||
"</font>"
|
||||
)
|
||||
|
||||
var name = models.users.getUser(
|
||||
chatPage.userId, model.targetUserId
|
||||
).displayName
|
||||
var sid = avatar.stripUserId(model.targetUserId || "")
|
||||
|
||||
text = text.replace(
|
||||
"%T",
|
||||
"<font color='" + textHueForName(name || sid) + "'>" +
|
||||
escapeHtml(name || model.targetUserId) +
|
||||
"</font>"
|
||||
)
|
||||
|
||||
text = qsTr(text)
|
||||
if (model.translatable == true) { return text }
|
||||
|
||||
// Else, model.translatable should be an array of args
|
||||
for (var i = 0; model.translatable.length; i++) {
|
||||
text = text.arg(model.translatable[i])
|
||||
}
|
||||
}
|
||||
|
||||
width: parent.width
|
||||
|
||||
id: contentLabel
|
||||
text: model.content +
|
||||
text: translate(model.content) +
|
||||
" <font size=" + HStyle.fontSize.small +
|
||||
"px color=" + HStyle.chat.message.date + ">" +
|
||||
Qt.formatDateTime(model.date, "hh:mm:ss") +
|
||||
@@ -64,8 +107,6 @@ Row {
|
||||
(model.isLocalEcho ?
|
||||
" <font size=" + HStyle.fontSize.small +
|
||||
"px>⏳</font>" : "")
|
||||
textFormat: model.type == "text" ?
|
||||
Text.PlainText : Text.RichText
|
||||
color: HStyle.chat.message.body
|
||||
wrapMode: Text.Wrap
|
||||
|
||||
|
@@ -14,10 +14,6 @@ Column {
|
||||
roomEventListView.model.get(index + 1) : null
|
||||
}
|
||||
|
||||
function getIsMessage(type) {
|
||||
return true
|
||||
}
|
||||
|
||||
property var previousItem: getPreviousItem()
|
||||
signal reloadPreviousItem()
|
||||
onReloadPreviousItem: previousItem = getPreviousItem()
|
||||
@@ -26,18 +22,14 @@ Column {
|
||||
Component.onCompleted:
|
||||
senderInfo = models.users.getUser(chatPage.userId, senderId)
|
||||
|
||||
//readonly property bool isMessage: ! model.type.match(/^event.*/)
|
||||
readonly property bool isMessage: getIsMessage(model.type)
|
||||
|
||||
readonly property bool isOwn: chatPage.userId === senderId
|
||||
|
||||
readonly property bool isFirstEvent: model.type == "eventCreate"
|
||||
readonly property bool isFirstEvent: model.event_type == "RoomCreateEvent"
|
||||
|
||||
readonly property bool combine:
|
||||
previousItem &&
|
||||
! talkBreak &&
|
||||
! dayBreak &&
|
||||
getIsMessage(previousItem.type) === isMessage &&
|
||||
previousItem.senderId === senderId &&
|
||||
minsBetween(previousItem.date, model.date) <= 5
|
||||
|
||||
@@ -75,14 +67,13 @@ Column {
|
||||
width: roomEventDelegate.width
|
||||
}
|
||||
|
||||
Item {
|
||||
Item { // TODO: put this in Daybreak.qml?
|
||||
visible: dayBreak
|
||||
width: parent.width
|
||||
height: topPadding
|
||||
}
|
||||
|
||||
Loader {
|
||||
source: isMessage ? "MessageContent.qml" : "EventContent.qml"
|
||||
MessageContent {
|
||||
anchors.right: isOwn ? parent.right : undefined
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user