fix: timestamp shows yesterday for a message received 3 days ago

- introduce one global update timer, to be used in various components
for date/time sensitive updates (StatusSharedUpdateTimer)
- this timer runs only when the app is/becomes active
- use the timer's `triggered()` signal to update the timestamp label
when needed; ie. if it's to display a relative timestamp and it's
currently visible

Fixes #11460
This commit is contained in:
Lukáš Tinkl 2024-02-12 12:43:14 +01:00 committed by Lukáš Tinkl
parent a463c335ae
commit f7781525ff
4 changed files with 53 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import QtQuick 2.14
import QtQuick 2.15
import QtQml 2.15
import StatusQ.Controls 0.1
import StatusQ.Core 0.1
@ -12,7 +13,24 @@ StatusBaseText {
color: Theme.palette.baseColor1
font.pixelSize: 10
visible: !!text
text: showFullTimestamp ? LocaleUtils.formatDateTime(timestamp) : LocaleUtils.formatRelativeTimestamp(timestamp)
text: d.formattedLabel
QtObject {
id: d
// initial value
property string formattedLabel: root.showFullTimestamp ? LocaleUtils.formatDateTime(root.timestamp) : LocaleUtils.formatRelativeTimestamp(root.timestamp)
// updates
Binding on formattedLabel {
when: !root.showFullTimestamp && root.timestamp && root.visible
value: {
StatusSharedUpdateTimer.secondsActive
return LocaleUtils.formatRelativeTimestamp(root.timestamp)
}
restoreMode: Binding.RestoreBinding
}
}
StatusToolTip {
id: tooltip
visible: hhandler.hovered && !!text
@ -22,8 +40,8 @@ StatusBaseText {
id: hhandler
enabled: !root.showFullTimestamp
onHoveredChanged: {
if(hhandler.hovered && timestamp) {
tooltip.text = LocaleUtils.formatDateTime(timestamp)
if(hhandler.hovered && root.timestamp) {
tooltip.text = LocaleUtils.formatDateTime(root.timestamp)
}
}
}

View File

@ -0,0 +1,29 @@
pragma Singleton
import QtQml 2.15
QtObject {
id: root
readonly property alias secondsActive: d.secondsActive
signal triggered()
readonly property Timer d: Timer {
id: d
property int secondsActive: 0
interval: 1000
running: Qt.application.state === Qt.ApplicationActive
repeat: true
onTriggered: {
d.secondsActive++
root.triggered()
}
onRunningChanged: {
if (running) {
d.secondsActive++
root.triggered()
}
}
}
}

View File

@ -13,5 +13,6 @@ StatusModalHeaderSettings 0.1 StatusModalHeaderSettings.qml
StatusProfileImageSettings 0.1 StatusProfileImageSettings.qml
StatusRollArea 0.1 StatusRollArea.qml
StatusScrollView 0.1 StatusScrollView.qml
singleton StatusSharedUpdateTimer 0.1 StatusSharedUpdateTimer.qml
StatusTooltipSettings 0.1 StatusTooltipSettings.qml
singleton LocaleUtils 0.1 LocaleUtils.qml

View File

@ -170,6 +170,7 @@
<file>StatusQ/Core/StatusModalHeaderSettings.qml</file>
<file>StatusQ/Core/StatusProfileImageSettings.qml</file>
<file>StatusQ/Core/StatusRollArea.qml</file>
<file>StatusQ/Core/StatusSharedUpdateTimer.qml</file>
<file>StatusQ/Core/StatusScrollView.qml</file>
<file>StatusQ/Core/StatusTooltipSettings.qml</file>
<file>StatusQ/Core/Theme/StatusColors.qml</file>