hotfix(ActivityCenter): Fix AC timestamps and binding loop for previousMessageIndex
Close #8434
This commit is contained in:
parent
213924f6e9
commit
726ae26128
|
@ -12,6 +12,7 @@ type
|
||||||
NotificationType
|
NotificationType
|
||||||
Message
|
Message
|
||||||
Timestamp
|
Timestamp
|
||||||
|
PreviousTimestamp
|
||||||
Read
|
Read
|
||||||
Dismissed
|
Dismissed
|
||||||
Accepted
|
Accepted
|
||||||
|
@ -72,8 +73,8 @@ QtObject:
|
||||||
return
|
return
|
||||||
|
|
||||||
let activityNotificationItem = self.activityCenterNotifications[index.row]
|
let activityNotificationItem = self.activityCenterNotifications[index.row]
|
||||||
let communityItemRole = role.NotifRoles
|
let notificationItemRole = role.NotifRoles
|
||||||
case communityItemRole:
|
case notificationItemRole:
|
||||||
of NotifRoles.Id: result = newQVariant(activityNotificationItem.id)
|
of NotifRoles.Id: result = newQVariant(activityNotificationItem.id)
|
||||||
of NotifRoles.ChatId: result = newQVariant(activityNotificationItem.chatId)
|
of NotifRoles.ChatId: result = newQVariant(activityNotificationItem.chatId)
|
||||||
of NotifRoles.CommunityId: result = newQVariant(activityNotificationItem.communityId)
|
of NotifRoles.CommunityId: result = newQVariant(activityNotificationItem.communityId)
|
||||||
|
@ -84,32 +85,16 @@ QtObject:
|
||||||
of NotifRoles.NotificationType: result = newQVariant(activityNotificationItem.notificationType.int)
|
of NotifRoles.NotificationType: result = newQVariant(activityNotificationItem.notificationType.int)
|
||||||
of NotifRoles.Message: result = newQVariant(activityNotificationItem.messageItem)
|
of NotifRoles.Message: result = newQVariant(activityNotificationItem.messageItem)
|
||||||
of NotifRoles.Timestamp: result = newQVariant(activityNotificationItem.timestamp)
|
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.Read: result = newQVariant(activityNotificationItem.read.bool)
|
||||||
of NotifRoles.Dismissed: result = newQVariant(activityNotificationItem.dismissed.bool)
|
of NotifRoles.Dismissed: result = newQVariant(activityNotificationItem.dismissed.bool)
|
||||||
of NotifRoles.Accepted: result = newQVariant(activityNotificationItem.accepted.bool)
|
of NotifRoles.Accepted: result = newQVariant(activityNotificationItem.accepted.bool)
|
||||||
of NotifRoles.RepliedMessage: result = newQVariant(activityNotificationItem.repliedMessageItem)
|
of NotifRoles.RepliedMessage: result = newQVariant(activityNotificationItem.repliedMessageItem)
|
||||||
of NotifRoles.ChatType: result = newQVariant(activityNotificationItem.chatType.int)
|
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] =
|
method roleNames(self: Model): Table[int, string] =
|
||||||
{
|
{
|
||||||
NotifRoles.Id.int:"id",
|
NotifRoles.Id.int:"id",
|
||||||
|
@ -122,6 +107,7 @@ QtObject:
|
||||||
NotifRoles.NotificationType.int: "notificationType",
|
NotifRoles.NotificationType.int: "notificationType",
|
||||||
NotifRoles.Message.int: "message",
|
NotifRoles.Message.int: "message",
|
||||||
NotifRoles.Timestamp.int: "timestamp",
|
NotifRoles.Timestamp.int: "timestamp",
|
||||||
|
NotifRoles.PreviousTimestamp.int: "previousTimestamp",
|
||||||
NotifRoles.Read.int: "read",
|
NotifRoles.Read.int: "read",
|
||||||
NotifRoles.Dismissed.int: "dismissed",
|
NotifRoles.Dismissed.int: "dismissed",
|
||||||
NotifRoles.Accepted.int: "accepted",
|
NotifRoles.Accepted.int: "accepted",
|
||||||
|
@ -176,15 +162,19 @@ QtObject:
|
||||||
self.endResetModel()
|
self.endResetModel()
|
||||||
|
|
||||||
proc addActivityNotificationItemToList*(self: Model, activityCenterNotification: Item, addToCount: bool = true) =
|
proc addActivityNotificationItemToList*(self: Model, activityCenterNotification: Item, addToCount: bool = true) =
|
||||||
self.beginInsertRows(newQModelIndex(), self.activityCenterNotifications.len, self.activityCenterNotifications.len)
|
self.beginInsertRows(newQModelIndex(), 0, 0)
|
||||||
|
self.activityCenterNotifications.insert(activityCenterNotification, 0)
|
||||||
self.activityCenterNotifications.add(activityCenterNotification)
|
|
||||||
|
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
|
|
||||||
self.unreadCountChanged()
|
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]) =
|
proc addActivityNotificationItemsToList*(self: Model, activityCenterNotifications: seq[Item]) =
|
||||||
if (self.activityCenterNotifications.len == 0):
|
if self.activityCenterNotifications.len == 0:
|
||||||
self.setNewData(activityCenterNotifications)
|
self.setNewData(activityCenterNotifications)
|
||||||
else:
|
else:
|
||||||
for activityCenterNotification in activityCenterNotifications:
|
for activityCenterNotification in activityCenterNotifications:
|
||||||
|
|
|
@ -113,12 +113,6 @@ QtObject:
|
||||||
self.model.removeNotifications(notificationIds)
|
self.model.removeNotifications(notificationIds)
|
||||||
|
|
||||||
proc addActivityCenterNotification*(self: View, activityCenterNotifications: seq[Item]) =
|
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)
|
self.model.addActivityNotificationItemsToList(activityCenterNotifications)
|
||||||
|
|
||||||
proc switchTo*(self: View, sectionId: string, chatId: string, messageId: string) {.slot.} =
|
proc switchTo*(self: View, sectionId: string, chatId: string, messageId: string) {.slot.} =
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import QtQuick 2.14
|
import QtQuick 2.14
|
||||||
|
|
||||||
import StatusQ.Core 0.1
|
import StatusQ.Core 0.1
|
||||||
|
import StatusQ.Core.Utils 0.1
|
||||||
import StatusQ.Core.Theme 0.1
|
import StatusQ.Core.Theme 0.1
|
||||||
|
|
||||||
StatusBaseText {
|
StatusBaseText {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property int previousMessageIndex: -1
|
|
||||||
property double previousMessageTimestamp
|
property double previousMessageTimestamp
|
||||||
property double messageTimestamp
|
property double messageTimestamp
|
||||||
|
|
||||||
|
@ -15,13 +15,10 @@ StatusBaseText {
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
|
||||||
text: {
|
text: {
|
||||||
if (previousMessageIndex === -1)
|
const currentMsgDate = new Date(messageTimestamp)
|
||||||
return "";
|
const prevMsgDate = new Date(previousMessageTimestamp)
|
||||||
|
|
||||||
const currentMsgDate = new Date(messageTimestamp);
|
if (prevMsgDate > 0 && currentMsgDate.getDay() === prevMsgDate.getDay())
|
||||||
const prevMsgDate = new Date(previousMessageTimestamp);
|
|
||||||
|
|
||||||
if (!!prevMsgDate && currentMsgDate.getDay() === prevMsgDate.getDay())
|
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
@ -29,7 +26,7 @@ StatusBaseText {
|
||||||
return qsTr("Today");
|
return qsTr("Today");
|
||||||
|
|
||||||
const yesterday = new Date();
|
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())
|
if (yesterday.getFullYear() == currentMsgDate.getFullYear() && yesterday.getMonth() == currentMsgDate.getMonth() && yesterday.getDate() == currentMsgDate.getDate())
|
||||||
return qsTr("Yesterday");
|
return qsTr("Yesterday");
|
||||||
|
|
||||||
|
|
|
@ -187,10 +187,10 @@ Popup {
|
||||||
|
|
||||||
ActivityNotificationMention {
|
ActivityNotificationMention {
|
||||||
width: listView.availableWidth
|
width: listView.availableWidth
|
||||||
|
filteredIndex: index
|
||||||
store: root.store
|
store: root.store
|
||||||
activityCenterStore: root.activityCenterStore
|
activityCenterStore: root.activityCenterStore
|
||||||
notification: model
|
notification: model
|
||||||
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
|
|
||||||
onCloseActivityCenter: root.close()
|
onCloseActivityCenter: root.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,10 +199,10 @@ Popup {
|
||||||
|
|
||||||
ActivityNotificationReply {
|
ActivityNotificationReply {
|
||||||
width: listView.availableWidth
|
width: listView.availableWidth
|
||||||
|
filteredIndex: index
|
||||||
store: root.store
|
store: root.store
|
||||||
activityCenterStore: root.activityCenterStore
|
activityCenterStore: root.activityCenterStore
|
||||||
notification: model
|
notification: model
|
||||||
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
|
|
||||||
onCloseActivityCenter: root.close()
|
onCloseActivityCenter: root.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,10 +211,10 @@ Popup {
|
||||||
|
|
||||||
ActivityNotificationContactRequest {
|
ActivityNotificationContactRequest {
|
||||||
width: listView.availableWidth
|
width: listView.availableWidth
|
||||||
|
filteredIndex: index
|
||||||
store: root.store
|
store: root.store
|
||||||
activityCenterStore: root.activityCenterStore
|
activityCenterStore: root.activityCenterStore
|
||||||
notification: model
|
notification: model
|
||||||
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
|
|
||||||
onCloseActivityCenter: root.close()
|
onCloseActivityCenter: root.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,10 +223,10 @@ Popup {
|
||||||
|
|
||||||
ActivityNotificationCommunityInvitation {
|
ActivityNotificationCommunityInvitation {
|
||||||
width: listView.availableWidth
|
width: listView.availableWidth
|
||||||
|
filteredIndex: index
|
||||||
store: root.store
|
store: root.store
|
||||||
activityCenterStore: root.activityCenterStore
|
activityCenterStore: root.activityCenterStore
|
||||||
notification: model
|
notification: model
|
||||||
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
|
|
||||||
onCloseActivityCenter: root.close()
|
onCloseActivityCenter: root.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,10 +235,10 @@ Popup {
|
||||||
|
|
||||||
ActivityNotificationCommunityMembershipRequest {
|
ActivityNotificationCommunityMembershipRequest {
|
||||||
width: listView.availableWidth
|
width: listView.availableWidth
|
||||||
|
filteredIndex: index
|
||||||
store: root.store
|
store: root.store
|
||||||
activityCenterStore: root.activityCenterStore
|
activityCenterStore: root.activityCenterStore
|
||||||
notification: model
|
notification: model
|
||||||
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
|
|
||||||
onCloseActivityCenter: root.close()
|
onCloseActivityCenter: root.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,10 +247,10 @@ Popup {
|
||||||
|
|
||||||
ActivityNotificationCommunityRequest {
|
ActivityNotificationCommunityRequest {
|
||||||
width: listView.availableWidth
|
width: listView.availableWidth
|
||||||
|
filteredIndex: index
|
||||||
store: root.store
|
store: root.store
|
||||||
activityCenterStore: root.activityCenterStore
|
activityCenterStore: root.activityCenterStore
|
||||||
notification: model
|
notification: model
|
||||||
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
|
|
||||||
onCloseActivityCenter: root.close()
|
onCloseActivityCenter: root.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,10 +259,10 @@ Popup {
|
||||||
|
|
||||||
ActivityNotificationCommunityKicked {
|
ActivityNotificationCommunityKicked {
|
||||||
width: listView.availableWidth
|
width: listView.availableWidth
|
||||||
|
filteredIndex: index
|
||||||
store: root.store
|
store: root.store
|
||||||
activityCenterStore: root.activityCenterStore
|
activityCenterStore: root.activityCenterStore
|
||||||
notification: model
|
notification: model
|
||||||
previousNotificationIndex: Math.min(listView.count - 1, index + 1)
|
|
||||||
onCloseActivityCenter: root.close()
|
onCloseActivityCenter: root.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import utils 1.0
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
property int filteredIndex: 0
|
||||||
property var notification
|
property var notification
|
||||||
property var store
|
property var store
|
||||||
property var activityCenterStore
|
property var activityCenterStore
|
||||||
|
@ -18,7 +19,6 @@ Item {
|
||||||
property alias bodyComponent: bodyLoader.sourceComponent
|
property alias bodyComponent: bodyLoader.sourceComponent
|
||||||
property alias badgeComponent: badgeLoader.sourceComponent
|
property alias badgeComponent: badgeLoader.sourceComponent
|
||||||
property alias ctaComponent: ctaLoader.sourceComponent
|
property alias ctaComponent: ctaLoader.sourceComponent
|
||||||
property alias previousNotificationIndex: dateGroupLabel.previousMessageIndex
|
|
||||||
|
|
||||||
signal closeActivityCenter()
|
signal closeActivityCenter()
|
||||||
|
|
||||||
|
@ -32,8 +32,7 @@ Item {
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
messageTimestamp: notification.timestamp
|
messageTimestamp: notification.timestamp
|
||||||
previousMessageTimestamp: root.activityCenterStore.activityCenterList.getNotificationData(
|
previousMessageTimestamp: filteredIndex === 0 || !notification.previousTimestamp ? 0 : notification.previousTimestamp
|
||||||
previousNotificationIndex, "timestamp")
|
|
||||||
visible: text !== ""
|
visible: text !== ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -378,8 +378,7 @@ Loader {
|
||||||
Layout.topMargin: 16
|
Layout.topMargin: 16
|
||||||
Layout.bottomMargin: 16
|
Layout.bottomMargin: 16
|
||||||
messageTimestamp: root.messageTimestamp
|
messageTimestamp: root.messageTimestamp
|
||||||
previousMessageIndex: root.prevMessageIndex
|
previousMessageTimestamp: root.prevMessageIndex === -1 ? 0 : root.prevMsgTimestamp
|
||||||
previousMessageTimestamp: root.prevMsgTimestamp
|
|
||||||
visible: text !== ""
|
visible: text !== ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue