Skip to content

Commit

Permalink
fix: timestamp shows yesterday for a message received 3 days ago
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
caybro committed Feb 12, 2024
1 parent 4b24497 commit bd13078
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
19 changes: 18 additions & 1 deletion ui/StatusQ/src/StatusQ/Components/StatusTimeStampLabel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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
property string formattedLabel: showFullTimestamp ? LocaleUtils.formatDateTime(root.timestamp) : LocaleUtils.formatRelativeTimestamp(root.timestamp)

readonly property var _conn: Connections {
target: StatusSharedUpdateTimer
enabled: root.visible && root.timestamp && !root.showFullTimestamp
function onTriggered() {
const newFormattedLabel = LocaleUtils.formatRelativeTimestamp(root.timestamp)
if (newFormattedLabel !== d.formattedLabel) {
d.formattedLabel = newFormattedLabel
}
}
}
}

StatusToolTip {
id: tooltip
visible: hhandler.hovered && !!text
Expand Down
17 changes: 17 additions & 0 deletions ui/StatusQ/src/StatusQ/Core/StatusSharedUpdateTimer.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pragma Singleton

import QtQml 2.15

QtObject {
id: root

signal triggered

readonly property Timer d: Timer {
interval: 1000
running: Qt.application.state === Qt.ApplicationActive
repeat: true
triggeredOnStart: true
onTriggered: root.triggered()
}
}
1 change: 1 addition & 0 deletions ui/StatusQ/src/StatusQ/Core/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ StatusModalHeaderSettings 0.1 StatusModalHeaderSettings.qml
StatusProfileImageSettings 0.1 StatusProfileImageSettings.qml
StatusRollArea 0.1 StatusRollArea.qml
StatusScrollView 0.1 StatusScrollView.qml
StatusSharedUpdateTimer 0.1 StatusSharedUpdateTimer.qml
StatusTooltipSettings 0.1 StatusTooltipSettings.qml
singleton LocaleUtils 0.1 LocaleUtils.qml
1 change: 1 addition & 0 deletions ui/StatusQ/src/statusq.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit bd13078

Please sign in to comment.