2020-07-15 21:04:14 +00:00
|
|
|
import QtQuick 2.3
|
2021-10-01 15:58:36 +00:00
|
|
|
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared 1.0
|
|
|
|
import shared.panels 1.0
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2020-07-15 21:04:14 +00:00
|
|
|
|
|
|
|
StyledText {
|
2021-06-15 19:34:36 +00:00
|
|
|
property bool isActivityCenterMessage: false
|
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-15 19:34:36 +00:00
|
|
|
anchors.horizontalCenter: isActivityCenterMessage ? undefined : parent.horizontalCenter
|
2021-06-11 17:41:59 +00:00
|
|
|
anchors.top: parent.top
|
2021-06-15 19:34:36 +00:00
|
|
|
anchors.topMargin: visible ? (isActivityCenterMessage ? Style.current.halfPadding : 20) : 0
|
2021-06-11 17:41:59 +00:00
|
|
|
anchors.left: parent.left
|
2021-06-15 19:34:36 +00:00
|
|
|
anchors.leftMargin: isActivityCenterMessage ? Style.current.padding : 0
|
2021-06-11 17:41:59 +00:00
|
|
|
|
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()) {
|
2022-04-04 11:26:30 +00:00
|
|
|
return qsTr("Today")
|
2021-04-06 14:59:59 +00:00
|
|
|
} else if (yesterday.toDateString() === currentMsgDate.toDateString()) {
|
2022-04-04 11:26:30 +00:00
|
|
|
return qsTr("Yesterday")
|
2021-04-06 14:59:59 +00:00
|
|
|
} else {
|
|
|
|
const monthNames = [
|
2022-04-04 11:26:30 +00:00
|
|
|
qsTr("January"),
|
|
|
|
qsTr("February"),
|
|
|
|
qsTr("March"),
|
|
|
|
qsTr("April"),
|
|
|
|
qsTr("May"),
|
|
|
|
qsTr("June"),
|
|
|
|
qsTr("July"),
|
|
|
|
qsTr("August"),
|
|
|
|
qsTr("September"),
|
|
|
|
qsTr("October"),
|
|
|
|
qsTr("November"),
|
|
|
|
qsTr("December")
|
2021-04-06 14:59:59 +00:00
|
|
|
];
|
|
|
|
return monthNames[currentMsgDate.getMonth()] + ", " + currentMsgDate.getDate()
|
|
|
|
}
|
2020-07-15 21:04:14 +00:00
|
|
|
}
|
|
|
|
visible: text !== ""
|
|
|
|
}
|