fix(@desktop/timeline): auto-update messages age

This commit is contained in:
Andrei Smirnov 2021-07-15 17:59:30 +03:00 committed by Iuri Matias
parent 1cc8d768b8
commit f66e64cc9c
5 changed files with 19 additions and 4 deletions

View File

@ -86,6 +86,7 @@ Item {
property bool isExpired: (outgoingStatus === "sending" && (Math.floor(timestamp) + 180000) < Date.now()) property bool isExpired: (outgoingStatus === "sending" && (Math.floor(timestamp) + 180000) < Date.now())
property bool isStatusUpdate: false property bool isStatusUpdate: false
property int statusAgeEpoch: 0
property int replyMessageIndex: chatsModel.messageView.messageList.getMessageIndex(responseTo); property int replyMessageIndex: chatsModel.messageView.messageList.getMessageIndex(responseTo);
property string repliedMessageAuthor: replyMessageIndex > -1 ? chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "userName") : ""; property string repliedMessageAuthor: replyMessageIndex > -1 ? chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "userName") : "";
@ -428,6 +429,7 @@ Item {
Component { Component {
id: statusUpdateComponent id: statusUpdateComponent
StatusUpdate { StatusUpdate {
statusAgeEpoch: root.statusAgeEpoch
clickMessage: root.clickMessage clickMessage: root.clickMessage
container: root container: root
} }

View File

@ -4,11 +4,10 @@ import "../../../../../shared/status"
import "../../../../../imports" import "../../../../../imports"
StyledText { StyledText {
property bool formatAge: false
id: chatTime id: chatTime
visible: isMessage visible: isMessage
color: Style.current.secondaryText color: Style.current.secondaryText
text: formatAge ? Utils.formatAgeFromTime(timestamp) : Utils.formatTime(timestamp) text: Utils.formatTime(timestamp)
font.pixelSize: Style.current.asideTextFontSize font.pixelSize: Style.current.asideTextFontSize
StatusToolTip { StatusToolTip {

View File

@ -10,6 +10,7 @@ MouseArea {
property var clickMessage: function () {} property var clickMessage: function () {}
property bool hovered: containsMouse property bool hovered: containsMouse
property var container property var container
property int statusAgeEpoch: 0
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: 0 anchors.topMargin: 0
@ -49,7 +50,9 @@ MouseArea {
ChatTime { ChatTime {
id: chatTime id: chatTime
formatAge: true // statusAgeEpoch is used to trigger Qt property update
// since the returned string will be the same in 99% cases, this should not trigger ChatTime re-rendering
text: Utils.formatAgeFromTime(timestamp, statusAgeEpoch)
visible: chatName.visible visible: chatName.visible
anchors.verticalCenter: chatName.verticalCenter anchors.verticalCenter: chatName.verticalCenter
anchors.left: chatName.right anchors.left: chatName.right

View File

@ -122,6 +122,15 @@ ScrollView {
} }
} }
Timer {
id: ageUpdateTimer
property int epoch: 0
running: true
repeat: true
interval: 60000 // 1 min
onTriggered: epoch = epoch + 1
}
DelegateModelGeneralized { DelegateModelGeneralized {
id: messageListDelegate id: messageListDelegate
lessThan: [ lessThan: [
@ -151,6 +160,7 @@ ScrollView {
messageId: model.messageId messageId: model.messageId
emojiReactions: model.emojiReactions emojiReactions: model.emojiReactions
isStatusUpdate: true isStatusUpdate: true
statusAgeEpoch: ageUpdateTimer.epoch
// 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
prevMessageIndex: { prevMessageIndex: {

View File

@ -244,7 +244,8 @@ QtObject {
return (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) return (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes)
} }
function formatAgeFromTime(timestamp) { function formatAgeFromTime(timestamp, epoch) {
epoch++ // pretending the parameter is not unused
const now = new Date() const now = new Date()
const messageDate = new Date(Math.floor(timestamp)) const messageDate = new Date(Math.floor(timestamp))
const diffMs = now - messageDate const diffMs = now - messageDate