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 isStatusUpdate: false
property int statusAgeEpoch: 0
property int replyMessageIndex: chatsModel.messageView.messageList.getMessageIndex(responseTo);
property string repliedMessageAuthor: replyMessageIndex > -1 ? chatsModel.messageView.messageList.getMessageData(replyMessageIndex, "userName") : "";
@ -428,6 +429,7 @@ Item {
Component {
id: statusUpdateComponent
StatusUpdate {
statusAgeEpoch: root.statusAgeEpoch
clickMessage: root.clickMessage
container: root
}

View File

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

View File

@ -10,6 +10,7 @@ MouseArea {
property var clickMessage: function () {}
property bool hovered: containsMouse
property var container
property int statusAgeEpoch: 0
anchors.top: parent.top
anchors.topMargin: 0
@ -49,7 +50,9 @@ MouseArea {
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
anchors.verticalCenter: chatName.verticalCenter
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 {
id: messageListDelegate
lessThan: [
@ -151,6 +160,7 @@ ScrollView {
messageId: model.messageId
emojiReactions: model.emojiReactions
isStatusUpdate: true
statusAgeEpoch: ageUpdateTimer.epoch
// 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
prevMessageIndex: {

View File

@ -244,7 +244,8 @@ QtObject {
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 messageDate = new Date(Math.floor(timestamp))
const diffMs = now - messageDate