Show last event time in RoomDelegate

Also respect locale for message times
This commit is contained in:
miruka
2019-08-16 12:07:22 -04:00
parent c76ebe4fe2
commit 2bb3952225
4 changed files with 86 additions and 26 deletions

View File

@@ -70,7 +70,7 @@ Row {
// time
"&nbsp;&nbsp;<font size=" + theme.fontSize.small +
"px color=" + theme.chat.message.date + ">" +
Qt.formatDateTime(model.date, "hh:mm:ss") +
Utils.formatTime(model.date) +
"</font>" +
// local echo icon
(model.is_local_echo ?

View File

@@ -15,7 +15,7 @@ HInteractiveRectangle {
id: rowLayout
x: sidePane.currentSpacing
width: parent.width - sidePane.currentSpacing * 1.5
height: roomLabel.height + subtitleLabel.height +
height: roomName.height + subtitle.height +
sidePane.currentSpacing / 1.5
spacing: sidePane.currentSpacing
@@ -28,23 +28,53 @@ HInteractiveRectangle {
HColumnLayout {
Layout.fillWidth: true
HLabel {
id: roomLabel
color: theme.sidePane.room.name
text: model.display_name || "<i>Empty room</i>"
textFormat:
model.display_name? Text.PlainText : Text.StyledText
elide: Text.ElideRight
verticalAlignment: Qt.AlignVCenter
HRowLayout {
spacing: theme.spacing / 2
Layout.fillWidth: true
HLabel {
id: roomName
color: theme.sidePane.room.name
text: model.display_name || "<i>Empty room</i>"
textFormat:
model.display_name? Text.PlainText : Text.StyledText
elide: Text.ElideRight
verticalAlignment: Qt.AlignVCenter
Layout.fillWidth: true
}
HLabel {
readonly property var evDate:
model.last_event ? model.last_event.date : null
id: lastEventDate
font.pixelSize: theme.fontSize.small
color: theme.sidePane.room.lastEventDate
text: ! evDate ? "" :
Utils.dateIsToday(evDate) ?
Utils.formatTime(evDate, false) : // no seconds
Utils.dateIsYesterday(evDate) ? qsTr("Yesterday") :
Qt.formatDate(evDate, "dd MMM") // e.g. "24 Nov"
visible: Layout.maximumWidth > 0
Layout.maximumWidth:
text && roomDelegate.width >= 200 ? implicitWidth : 0
Behavior on Layout.maximumWidth { HNumberAnimation {} }
}
}
HRichLabel {
id: subtitleLabel
id: subtitle
color: theme.sidePane.room.subtitle
visible: Boolean(text)
textFormat: Text.StyledText
font.pixelSize: theme.fontSize.small
elide: Text.ElideRight
text: {
if (! model.last_event) { return "" }
@@ -61,10 +91,6 @@ HInteractiveRectangle {
) + ": " + ev.inline_content
}
font.pixelSize: theme.fontSize.small
elide: Text.ElideRight
Layout.fillWidth: true
}
}

View File

@@ -123,6 +123,38 @@ function minutesBetween(date1, date2) {
}
function dateIsDay(date, dayDate) {
return date.getDate() == dayDate.getDate() &&
date.getMonth() == dayDate.getMonth() &&
date.getFullYear() == dayDate.getFullYear()
}
function dateIsToday(date) {
return dateIsDay(date, new Date())
}
function dateIsYesterday(date) {
const yesterday = new Date()
yesterday.setDate(yesterday.getDate() - 1)
return dateIsDay(date, yesterday)
}
function formatTime(time, seconds=true) {
return Qt.formatTime(
time,
Qt.locale().timeFormat(
seconds ? Locale.LongFormat : Locale.NarrowFormat
).replace(/\./g, ":").replace(/ t$/, "")
// en_DK.UTF-8 locale wrongfully gives "." separators;
// remove the timezone at the end
)
}
function getItem(array, mainKey, value) {
for (let i = 0; i < array.length; i++) {
if (array[i][mainKey] === value) { return array[i] }