fix(@desktop/timeline): render message age instead of message time

This commit is contained in:
Andrei Smirnov 2021-07-15 17:20:17 +03:00 committed by Iuri Matias
parent 9d4fa890b4
commit 1cc8d768b8
4 changed files with 23 additions and 4 deletions

View File

@ -4,11 +4,11 @@ import "../../../../../shared/status"
import "../../../../../imports"
StyledText {
property bool formatDateTime: false
property bool formatAge: false
id: chatTime
visible: isMessage
color: Style.current.secondaryText
text: formatDateTime ? Utils.formatDateTime(timestamp, globalSettings.locale) : Utils.formatTime(timestamp, globalSettings.locale)
text: formatAge ? Utils.formatAgeFromTime(timestamp) : Utils.formatTime(timestamp)
font.pixelSize: Style.current.asideTextFontSize
StatusToolTip {

View File

@ -49,7 +49,7 @@ MouseArea {
ChatTime {
id: chatTime
formatDateTime: true
formatAge: true
visible: chatName.visible
anchors.verticalCenter: chatName.verticalCenter
anchors.left: chatName.right

View File

@ -96,7 +96,7 @@ ScrollView {
anchors.top: statusUpdateInput.bottom
anchors.topMargin: 40
anchors.horizontalCenter: parent.horizontalCenter
visible: chatsModel.messageView.messageList.rowCount() === 0
visible: chatLogView.count === 0
}
ListView {

View File

@ -244,6 +244,25 @@ QtObject {
return (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes)
}
function formatAgeFromTime(timestamp) {
const now = new Date()
const messageDate = new Date(Math.floor(timestamp))
const diffMs = now - messageDate
const diffMin = Math.floor(diffMs / 60000)
if (diffMin < 1) {
return qsTr("NOW")
}
const diffHour = Math.floor(diffMin / 60)
if (diffHour < 1) {
return qsTr("%1M").arg(diffMin)
}
const diffDay = Math.floor(diffHour / 24)
if (diffDay < 1) {
return qsTr("%1H").arg(diffHour)
}
return qsTr("%1D").arg(diffDay)
}
function formatShortDateStr(longStr) {
const dmKeys = {
// Days