2020-07-15 21:04:14 +00:00
|
|
|
import QtQuick 2.3
|
|
|
|
import "../../../../../shared"
|
|
|
|
import "../../../../../imports"
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: dateGroupLbl
|
|
|
|
font.pixelSize: 13
|
|
|
|
color: Style.current.darkGrey
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
text: {
|
|
|
|
if (prevMessageIndex == -1) return ""; // identifier
|
|
|
|
|
|
|
|
let now = new Date()
|
|
|
|
let yesterday = new Date()
|
|
|
|
yesterday.setDate(now.getDate()-1)
|
|
|
|
|
|
|
|
let prevMsgTimestamp = chatsModel.messageList.getMessageData(prevMessageIndex, "timestamp")
|
|
|
|
var currentMsgDate = new Date(parseInt(timestamp, 10));
|
|
|
|
var prevMsgDate = prevMsgTimestamp === "" ? new Date(0) : new Date(parseInt(prevMsgTimestamp, 10));
|
|
|
|
if(currentMsgDate.getDay() !== prevMsgDate.getDay()){
|
|
|
|
if (now.toDateString() === currentMsgDate.toDateString()) {
|
2020-07-16 15:20:29 +00:00
|
|
|
//% "Today"
|
|
|
|
return qsTrId("today")
|
2020-07-15 21:04:14 +00:00
|
|
|
} else if (yesterday.toDateString() === currentMsgDate.toDateString()) {
|
|
|
|
//% "Yesterday"
|
|
|
|
return qsTrId("yesterday")
|
|
|
|
} else {
|
|
|
|
const monthNames = [
|
2020-07-16 15:20:29 +00:00
|
|
|
//% "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")
|
2020-07-15 21:04:14 +00:00
|
|
|
];
|
2020-07-23 15:40:33 +00:00
|
|
|
return monthNames[currentMsgDate.getMonth()] + ", " + currentMsgDate.getDate()
|
2020-07-15 21:04:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
visible: text !== ""
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: this.visible ? 20 : 0
|
|
|
|
}
|