fix: date label not showing correctly

Fixes #2184
This commit is contained in:
Jonathan Rainville 2021-04-06 10:59:59 -04:00 committed by Iuri Matias
parent e68333fb07
commit 10fd90a152
4 changed files with 46 additions and 45 deletions

View File

@ -298,8 +298,8 @@ ScrollView {
prevMessageIndex: { prevMessageIndex: {
// This is used in order to have access to the previous message and determine the timestamp // This is used in order to have access to the previous message and determine the timestamp
// we can't rely on the index because the sequence of messages is not ordered on the nim side // we can't rely on the index because the sequence of messages is not ordered on the nim side
if(msgDelegate.DelegateModel.itemsIndex > 0){ if (msgDelegate.DelegateModel.itemsIndex < messageListDelegate.items.count - 1) {
return messageListDelegate.items.get(msgDelegate.DelegateModel.itemsIndex - 1).model.index return messageListDelegate.items.get(msgDelegate.DelegateModel.itemsIndex + 1).model.index
} }
return -1; return -1;
} }

View File

@ -14,6 +14,7 @@ Item {
property bool isCurrentUser: false property bool isCurrentUser: false
property bool isHovered: false property bool isHovered: false
property bool isMessageActive: false property bool isMessageActive: false
property bool headerRepeatCondition: (authorCurrentMsg !== authorPrevMsg || shouldRepeatHeader || dateGroupLbl.visible)
id: root id: root
@ -72,7 +73,7 @@ Item {
UserImage { UserImage {
id: chatImage id: chatImage
active: isMessage && authorCurrentMsg != authorPrevMsg active: isMessage && headerRepeatCondition
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: Style.current.padding anchors.leftMargin: Style.current.padding
anchors.top: parent.top anchors.top: parent.top
@ -81,6 +82,7 @@ Item {
UsernameLabel { UsernameLabel {
id: chatName id: chatName
visible: isMessage && headerRepeatCondition
anchors.leftMargin: root.chatHorizontalPadding anchors.leftMargin: root.chatHorizontalPadding
anchors.top: chatImage.top anchors.top: chatImage.top
anchors.left: chatImage.right anchors.left: chatImage.right
@ -88,7 +90,7 @@ Item {
ChatTime { ChatTime {
id: chatTime id: chatTime
visible: authorCurrentMsg != authorPrevMsg visible: headerRepeatCondition
anchors.verticalCenter: chatName.verticalCenter anchors.verticalCenter: chatName.verticalCenter
anchors.left: chatName.right anchors.left: chatName.right
anchors.leftMargin: 4 anchors.leftMargin: 4

View File

@ -5,7 +5,7 @@ import "../../../../../imports"
StyledText { StyledText {
id: dateGroupLbl id: dateGroupLbl
font.pixelSize: 13 font.pixelSize: 13
color: Style.current.darkGrey color: Style.current.secondaryText
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
text: { text: {
@ -15,49 +15,48 @@ StyledText {
let yesterday = new Date() let yesterday = new Date()
yesterday.setDate(now.getDate()-1) yesterday.setDate(now.getDate()-1)
let prevMsgTimestamp = chatsModel.messageList.getMessageData(prevMessageIndex, "timestamp")
var currentMsgDate = new Date(parseInt(timestamp, 10)); var currentMsgDate = new Date(parseInt(timestamp, 10));
var prevMsgDate = prevMsgTimestamp === "" ? new Date(0) : new Date(parseInt(prevMsgTimestamp, 10)); var prevMsgDate = prevMsgTimestamp === "" ? new Date(0) : new Date(parseInt(prevMsgTimestamp, 10));
if(currentMsgDate.getDay() !== prevMsgDate.getDay()){
if (now.toDateString() === currentMsgDate.toDateString()) { if (currentMsgDate.getDay() === prevMsgDate.getDay()) {
//% "Today" return ""
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()
}
} else {
return "";
} }
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()
}
} }
visible: text !== "" visible: text !== ""
anchors.top: parent.top anchors.top: parent.top

View File

@ -22,7 +22,7 @@ Item {
UserImage { UserImage {
id: chatImage id: chatImage
visible: chatsModel.activeChannel.chatType !== Constants.chatTypeOneToOne && isMessage && headerRepeatCondition && !root.isCurrentUser active: chatsModel.activeChannel.chatType !== Constants.chatTypeOneToOne && isMessage && headerRepeatCondition && !root.isCurrentUser
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: Style.current.padding anchors.leftMargin: Style.current.padding
anchors.top: dateGroupLbl.visible ? dateGroupLbl.bottom : parent.top anchors.top: dateGroupLbl.visible ? dateGroupLbl.bottom : parent.top