2020-07-15 21:04:14 +00:00
|
|
|
import QtQuick 2.3
|
|
|
|
import "../../../../../shared"
|
|
|
|
import "../../../../../imports"
|
|
|
|
|
|
|
|
StyledText {
|
2021-06-11 17:41:59 +00:00
|
|
|
property int previousMessageIndex: -1
|
|
|
|
property string previousMessageTimestamp
|
|
|
|
property string messageTimestamp
|
|
|
|
|
2020-07-15 21:04:14 +00:00
|
|
|
id: dateGroupLbl
|
|
|
|
font.pixelSize: 13
|
2021-04-06 14:59:59 +00:00
|
|
|
color: Style.current.secondaryText
|
2020-07-15 21:04:14 +00:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
2021-06-11 17:41:59 +00:00
|
|
|
anchors.horizontalCenter: activityCenterMessage ? undefined : parent.horizontalCenter
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: visible ? (activityCenterMessage ? Style.current.halfPadding : 20) : 0
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: activityCenterMessage ? Style.current.padding : 0
|
|
|
|
|
2020-07-15 21:04:14 +00:00
|
|
|
text: {
|
2021-06-11 17:41:59 +00:00
|
|
|
if (previousMessageIndex === -1) return ""; // identifier
|
2020-07-15 21:04:14 +00:00
|
|
|
|
|
|
|
let now = new Date()
|
|
|
|
let yesterday = new Date()
|
|
|
|
yesterday.setDate(now.getDate()-1)
|
|
|
|
|
2021-06-11 19:50:52 +00:00
|
|
|
let currentMsgDate = new Date(parseInt(messageTimestamp, 10));
|
|
|
|
let prevMsgDate = previousMessageTimestamp === "" ? undefined : new Date(parseInt(previousMessageTimestamp, 10));
|
2021-04-06 14:59:59 +00:00
|
|
|
|
2021-06-11 19:50:52 +00:00
|
|
|
if (!!prevMsgDate && currentMsgDate.getDay() === prevMsgDate.getDay()) {
|
2021-04-06 14:59:59 +00:00
|
|
|
return ""
|
2020-07-15 21:04:14 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 14:59:59 +00:00
|
|
|
if (now.toDateString() === currentMsgDate.toDateString()) {
|
|
|
|
//% "Today"
|
|
|
|
return qsTrId("today")
|
|
|
|
} else if (yesterday.toDateString() === currentMsgDate.toDateString()) {
|
|
|
|
//% "Yesterday"
|
|
|
|
return qsTrId("yesterday")
|
|
|
|
} else {
|
|
|
|
const monthNames = [
|
|
|
|
//% "January"
|
|
|
|
qsTrId("january"),
|
|
|
|
//% "February"
|
|
|
|
qsTrId("february"),
|
|
|
|
//% "March"
|
|
|
|
qsTrId("march"),
|
|
|
|
//% "April"
|
|
|
|
qsTrId("april"),
|
|
|
|
//% "May"
|
|
|
|
qsTrId("may"),
|
|
|
|
//% "June"
|
|
|
|
qsTrId("june"),
|
|
|
|
//% "July"
|
|
|
|
qsTrId("july"),
|
|
|
|
//% "August"
|
|
|
|
qsTrId("august"),
|
|
|
|
//% "September"
|
|
|
|
qsTrId("september"),
|
|
|
|
//% "October"
|
|
|
|
qsTrId("october"),
|
|
|
|
//% "November"
|
|
|
|
qsTrId("november"),
|
|
|
|
//% "December"
|
|
|
|
qsTrId("december")
|
|
|
|
];
|
|
|
|
return monthNames[currentMsgDate.getMonth()] + ", " + currentMsgDate.getDate()
|
|
|
|
}
|
2020-07-15 21:04:14 +00:00
|
|
|
}
|
|
|
|
visible: text !== ""
|
|
|
|
}
|