hotfix(ActivityCenter): Fix AC timestamps and binding loop for previousMessageIndex

Close #8434
This commit is contained in:
MishkaRogachev 2022-11-23 18:50:00 +04:00 committed by Mikhail Rogachev
parent 213924f6e9
commit 726ae26128
6 changed files with 32 additions and 53 deletions

View File

@ -12,6 +12,7 @@ type
NotificationType
Message
Timestamp
PreviousTimestamp
Read
Dismissed
Accepted
@ -72,8 +73,8 @@ QtObject:
return
let activityNotificationItem = self.activityCenterNotifications[index.row]
let communityItemRole = role.NotifRoles
case communityItemRole:
let notificationItemRole = role.NotifRoles
case notificationItemRole:
of NotifRoles.Id: result = newQVariant(activityNotificationItem.id)
of NotifRoles.ChatId: result = newQVariant(activityNotificationItem.chatId)
of NotifRoles.CommunityId: result = newQVariant(activityNotificationItem.communityId)
@ -84,32 +85,16 @@ QtObject:
of NotifRoles.NotificationType: result = newQVariant(activityNotificationItem.notificationType.int)
of NotifRoles.Message: result = newQVariant(activityNotificationItem.messageItem)
of NotifRoles.Timestamp: result = newQVariant(activityNotificationItem.timestamp)
of NotifRoles.PreviousTimestamp: result = newQVariant(if index.row > 0:
self.activityCenterNotifications[index.row - 1].timestamp
else:
0)
of NotifRoles.Read: result = newQVariant(activityNotificationItem.read.bool)
of NotifRoles.Dismissed: result = newQVariant(activityNotificationItem.dismissed.bool)
of NotifRoles.Accepted: result = newQVariant(activityNotificationItem.accepted.bool)
of NotifRoles.RepliedMessage: result = newQVariant(activityNotificationItem.repliedMessageItem)
of NotifRoles.ChatType: result = newQVariant(activityNotificationItem.chatType.int)
proc getNotificationData(self: Model, index: int, data: string): string {.slot.} =
if index < 0 or index >= self.activityCenterNotifications.len: return ("")
let notif = self.activityCenterNotifications[index]
case data:
of "id": result = notif.id
of "chatId": result = notif.chatId
of "communityId": result = notif.communityId
of "membershipStatus": result = $(notif.membershipStatus.int)
of "sectionId": result = notif.sectionId
of "name": result = notif.name
of "author": result = notif.author
of "notificationType": result = $(notif.notificationType.int)
of "timestamp": result = $(notif.timestamp)
of "read": result = $(notif.read)
of "dismissed": result = $(notif.dismissed)
of "accepted": result = $(notif.accepted)
of "chatType": result = $(notif.chatType)
else: result = ("")
method roleNames(self: Model): Table[int, string] =
{
NotifRoles.Id.int:"id",
@ -122,6 +107,7 @@ QtObject:
NotifRoles.NotificationType.int: "notificationType",
NotifRoles.Message.int: "message",
NotifRoles.Timestamp.int: "timestamp",
NotifRoles.PreviousTimestamp.int: "previousTimestamp",
NotifRoles.Read.int: "read",
NotifRoles.Dismissed.int: "dismissed",
NotifRoles.Accepted.int: "accepted",
@ -176,15 +162,19 @@ QtObject:
self.endResetModel()
proc addActivityNotificationItemToList*(self: Model, activityCenterNotification: Item, addToCount: bool = true) =
self.beginInsertRows(newQModelIndex(), self.activityCenterNotifications.len, self.activityCenterNotifications.len)
self.activityCenterNotifications.add(activityCenterNotification)
self.beginInsertRows(newQModelIndex(), 0, 0)
self.activityCenterNotifications.insert(activityCenterNotification, 0)
self.endInsertRows()
self.unreadCountChanged()
if self.activityCenterNotifications.len > 1:
let topLeft = self.createIndex(0, 0, nil)
let bottomRight = self.createIndex(1, 0, nil)
self.dataChanged(topLeft, bottomRight, @[NotifRoles.Timestamp.int, NotifRoles.PreviousTimestamp.int])
proc addActivityNotificationItemsToList*(self: Model, activityCenterNotifications: seq[Item]) =
if (self.activityCenterNotifications.len == 0):
if self.activityCenterNotifications.len == 0:
self.setNewData(activityCenterNotifications)
else:
for activityCenterNotification in activityCenterNotifications:

View File

@ -113,12 +113,6 @@ QtObject:
self.model.removeNotifications(notificationIds)
proc addActivityCenterNotification*(self: View, activityCenterNotifications: seq[Item]) =
# TODO this should be handled by the chat or community module
# if self.channelView.activeChannel.id == activityCenterNotification.chatId:
# activityCenterNotification.read = true
# let communityId = self.status.chat.getCommunityIdForChat(activityCenterNotification.chatId)
# if communityId != "":
# self.communities.joinedCommunityList.decrementMentions(communityId, activityCenterNotification.chatId)
self.model.addActivityNotificationItemsToList(activityCenterNotifications)
proc switchTo*(self: View, sectionId: string, chatId: string, messageId: string) {.slot.} =

View File

@ -1,12 +1,12 @@
import QtQuick 2.14
import StatusQ.Core 0.1
import StatusQ.Core.Utils 0.1
import StatusQ.Core.Theme 0.1
StatusBaseText {
id: root
property int previousMessageIndex: -1
property double previousMessageTimestamp
property double messageTimestamp
@ -15,13 +15,10 @@ StatusBaseText {
horizontalAlignment: Text.AlignHCenter
text: {
if (previousMessageIndex === -1)
return "";
const currentMsgDate = new Date(messageTimestamp)
const prevMsgDate = new Date(previousMessageTimestamp)
const currentMsgDate = new Date(messageTimestamp);
const prevMsgDate = new Date(previousMessageTimestamp);
if (!!prevMsgDate && currentMsgDate.getDay() === prevMsgDate.getDay())
if (prevMsgDate > 0 && currentMsgDate.getDay() === prevMsgDate.getDay())
return "";
const now = new Date();
@ -29,7 +26,7 @@ StatusBaseText {
return qsTr("Today");
const yesterday = new Date();
yesterday.setDate(now.getDate()-1);
yesterday.setDate(now.getDate() - 1);
if (yesterday.getFullYear() == currentMsgDate.getFullYear() && yesterday.getMonth() == currentMsgDate.getMonth() && yesterday.getDate() == currentMsgDate.getDate())
return qsTr("Yesterday");

View File

@ -187,10 +187,10 @@ Popup {
ActivityNotificationMention {
width: listView.availableWidth
filteredIndex: index
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
onCloseActivityCenter: root.close()
}
}
@ -199,10 +199,10 @@ Popup {
ActivityNotificationReply {
width: listView.availableWidth
filteredIndex: index
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
onCloseActivityCenter: root.close()
}
}
@ -211,10 +211,10 @@ Popup {
ActivityNotificationContactRequest {
width: listView.availableWidth
filteredIndex: index
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
onCloseActivityCenter: root.close()
}
}
@ -223,10 +223,10 @@ Popup {
ActivityNotificationCommunityInvitation {
width: listView.availableWidth
filteredIndex: index
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
onCloseActivityCenter: root.close()
}
}
@ -235,10 +235,10 @@ Popup {
ActivityNotificationCommunityMembershipRequest {
width: listView.availableWidth
filteredIndex: index
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
onCloseActivityCenter: root.close()
}
}
@ -247,10 +247,10 @@ Popup {
ActivityNotificationCommunityRequest {
width: listView.availableWidth
filteredIndex: index
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
onCloseActivityCenter: root.close()
}
}
@ -259,10 +259,10 @@ Popup {
ActivityNotificationCommunityKicked {
width: listView.availableWidth
filteredIndex: index
store: root.store
activityCenterStore: root.activityCenterStore
notification: model
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
onCloseActivityCenter: root.close()
}
}

View File

@ -11,6 +11,7 @@ import utils 1.0
Item {
id: root
property int filteredIndex: 0
property var notification
property var store
property var activityCenterStore
@ -18,7 +19,6 @@ Item {
property alias bodyComponent: bodyLoader.sourceComponent
property alias badgeComponent: badgeLoader.sourceComponent
property alias ctaComponent: ctaLoader.sourceComponent
property alias previousNotificationIndex: dateGroupLabel.previousMessageIndex
signal closeActivityCenter()
@ -32,8 +32,7 @@ Item {
anchors.right: parent.right
anchors.left: parent.left
messageTimestamp: notification.timestamp
previousMessageTimestamp: root.activityCenterStore.activityCenterList.getNotificationData(
previousNotificationIndex, "timestamp")
previousMessageTimestamp: filteredIndex === 0 || !notification.previousTimestamp ? 0 : notification.previousTimestamp
visible: text !== ""
}

View File

@ -378,8 +378,7 @@ Loader {
Layout.topMargin: 16
Layout.bottomMargin: 16
messageTimestamp: root.messageTimestamp
previousMessageIndex: root.prevMessageIndex
previousMessageTimestamp: root.prevMsgTimestamp
previousMessageTimestamp: root.prevMessageIndex === -1 ? 0 : root.prevMsgTimestamp
visible: text !== ""
}