perf(chatScroll): Optimise timestamps

The date parsing is time consuming and it needs to be used with care in the delegate

perf(chatScroll): Fix StatusDateGroupLabel comment - standaloneMonthName

perf(chatScroll): fix comments on Optimise timestamps

perf(chatScroll): Optimise timestamps - bring back comment

perf(chatScroll): fix activity notification
This commit is contained in:
Alex Jbanca 2023-01-10 13:36:03 +02:00 committed by Alex Jbanca
parent bf1d59c0ad
commit 719e0a34f6
8 changed files with 29 additions and 30 deletions

View File

@ -18,17 +18,20 @@ StatusBaseText {
if (messageTimestamp === 0)
return ""
const currentMsgDate = new Date(messageTimestamp)
const prevMsgDate = new Date(previousMessageTimestamp)
if (prevMsgDate > 0 && currentMsgDate.getDay() <= prevMsgDate.getDay())
const msInADay = 86400000
const lastMessageInDays = Math.floor(previousMessageTimestamp / msInADay)
const currentMessageInDays = Math.floor(messageTimestamp / msInADay)
if(previousMessageTimestamp > 0 && currentMessageInDays <= lastMessageInDays)
return ""
const now = new Date();
let date = new Date()
const currentYear = date.getFullYear()
date.setTime(messageTimestamp)
// FIXME Qt6: replace with Intl.DateTimeFormat
const monthName = Qt.locale().standaloneMonthName(currentMsgDate.getMonth(), Locale.LongFormat)
if (now.getFullYear() > currentMsgDate.getFullYear())
return "%1 %2, %3".arg(monthName).arg(currentMsgDate.getDate()).arg(currentMsgDate.getFullYear())
return "%1, %2".arg(monthName).arg(currentMsgDate.getDate())
const monthName = Qt.locale().standaloneMonthName(date.getMonth(), Locale.LongFormat)
if (currentYear > date.getFullYear())
return "%1 %2, %3".arg(monthName).arg(date.getDate()).arg(date.getFullYear())
return "%1, %2".arg(monthName).arg(date.getDate())
}
}

View File

@ -63,9 +63,6 @@ Control {
property StatusMessageDetails messageDetails: StatusMessageDetails {}
property StatusMessageDetails replyDetails: StatusMessageDetails {}
property string timestampString: LocaleUtils.formatTime(timestamp, Locale.ShortFormat)
property string timestampTooltipString: LocaleUtils.formatDateTime(timestamp)
signal clicked(var sender, var mouse)
signal profilePictureClicked(var sender, var mouse)
signal senderNameClicked(var sender, var mouse)
@ -250,8 +247,7 @@ Control {
resendError: root.messageDetails.amISender && !editMode ? root.resendError : ""
onClicked: root.senderNameClicked(sender, mouse)
onResendClicked: root.resendClicked()
timestamp.text: root.timestampString
timestamp.tooltip.text: root.timestampTooltipString
timestamp: root.timestamp
displayNameClickable: root.profileClickable
}
}
@ -331,6 +327,7 @@ Control {
active: root.messageDetails.contentType === StatusMessage.ContentType.Invitation && !editMode
visible: active
}
Loader {
Layout.fillWidth: true
Layout.rightMargin: 16

View File

@ -15,9 +15,7 @@ Item {
property StatusMessageSenderDetails sender: StatusMessageSenderDetails { }
property alias displayNameLabel: primaryDisplayName
property alias secondaryNameLabel: secondaryDisplayName
property alias tertiaryDetailsLabel: tertiaryDetailText
property alias timestamp: timestampText
property double timestamp: 0
property string tertiaryDetail: sender.id
property string resendText: qsTr("Resend")
@ -110,6 +108,7 @@ Item {
StatusTimeStampLabel {
verticalAlignment: Text.AlignVCenter
id: timestampText
timestamp: root.timestamp
}
StatusBaseText {
verticalAlignment: Text.AlignVCenter

View File

@ -5,11 +5,13 @@ import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
StatusBaseText {
property alias tooltip: tooltip
id: root
property double timestamp: 0
color: Theme.palette.baseColor1
font.pixelSize: 10
visible: !!text
text: LocaleUtils.formatTime(timestamp, Locale.ShortFormat)
StatusToolTip {
id: tooltip
visible: hhandler.hovered && !!text
@ -17,5 +19,10 @@ StatusBaseText {
}
HoverHandler {
id: hhandler
onHoveredChanged: {
if(hhandler.hovered && timestamp) {
tooltip.text = LocaleUtils.formatDateTime(timestamp)
}
}
}
}

View File

@ -17,8 +17,7 @@ StatusDialog {
id: root
property StatusMessageDetails messageDetails
property string timestampString
property string timestampTooltipString
property double timestamp: 0
signal accepted
signal declined
@ -58,8 +57,7 @@ StatusDialog {
amISender: root.messageDetails.amISender
messageOriginInfo: root.messageDetails.messageOriginInfo
tertiaryDetail: Utils.getElidedCompressedPk(sender.id)
timestamp.text: root.timestampString
timestamp.tooltip.text: root.timestampTooltipString
timestamp: root.timestamp
}
RowLayout {

View File

@ -72,8 +72,7 @@ ActivityNotificationMessage {
onDetailsClicked: {
Global.openPopup(reviewContactRequestPopupComponent, {
messageDetails: root.messageDetails,
timestampString: root.timestampString,
timestampTooltipString: root.timestampTooltipString
timestamp: notification ? notification.timestamp : 0
})
}
}

View File

@ -75,7 +75,7 @@ ActivityNotificationBase {
width: parent.width
maximumLineCount: root.maximumLineCount
messageDetails: root.messageDetails
timestamp: notification ? notification.timestamp : ""
timestamp: notification ? notification.timestamp : 0
messageSubheaderComponent: root.messageSubheaderComponent
messageBadgeComponent: root.messageBadgeComponent
onOpenProfilePopup: root.openProfilePopup()

View File

@ -25,9 +25,6 @@ RowLayout {
}
}
readonly property string timestampString: timestamp ? LocaleUtils.formatTime(timestamp, Locale.ShortFormat) : ""
readonly property string timestampTooltipString: timestamp ? LocaleUtils.formatDateTime(timestamp) : ""
signal openProfilePopup()
spacing: 8
@ -64,8 +61,7 @@ RowLayout {
amISender: root.messageDetails.amISender
messageOriginInfo: root.messageDetails.messageOriginInfo
tertiaryDetail: Utils.getElidedCompressedPk(sender.id)
timestamp.text: root.timestampString
timestamp.tooltip.text: root.timestampTooltipString
timestamp: root.timestamp
onClicked: root.openProfilePopup()
}