feat: add show more button to activity center

Fixes #2670
This commit is contained in:
Jonathan Rainville 2021-06-08 14:05:49 -04:00
parent 414b39d7e0
commit 0b00a426ae
4 changed files with 41 additions and 17 deletions

View File

@ -516,7 +516,7 @@ QtObject:
self.messageList[msg.chatId].changeMessagePinned(msg.id, true, msg.pinnedBy)
proc pushActivityCenterNotifications*(self:ChatsView, activityCenterNotifications: seq[ActivityCenterNotification]) =
self.activityNotificationList.setNewData(activityCenterNotifications)
self.activityNotificationList.addActivityNotificationItemsToList(activityCenterNotifications)
self.activityNotificationsChanged()
proc addActivityCenterNotification*(self:ChatsView, activityCenterNotifications: seq[ActivityCenterNotification]) =

View File

@ -48,6 +48,15 @@ QtObject:
read = unreadCount
notify = unreadCountChanged
proc hasMoreToShowChanged*(self: ActivityNotificationList) {.signal.}
proc hasMoreToShow*(self: ActivityNotificationList): bool {.slot.} =
self.status.chat.activityCenterCursor != ""
QtProperty[bool] hasMoreToShow:
read = hasMoreToShow
notify = hasMoreToShowChanged
method rowCount*(self: ActivityNotificationList, index: QModelIndex = nil): int = self.activityCenterNotifications.len
method data(self: ActivityNotificationList, index: QModelIndex, role: int): QVariant =
@ -97,6 +106,10 @@ QtObject:
NotifRoles.Accepted.int: "accepted"
}.toTable
proc loadMoreNotifications(self: ActivityNotificationList) {.slot.} =
self.status.chat.activityCenterNotifications(false)
self.hasMoreToShowChanged()
proc markAllActivityCenterNotificationsRead(self: ActivityNotificationList): string {.slot.} =
let error = self.status.chat.markAllActivityCenterNotificationsRead()
if (error != ""):
@ -135,15 +148,23 @@ QtObject:
self.endResetModel()
self.nbUnreadNotifications = self.status.chat.unreadActivityCenterNotificationsCount()
self.unreadCountChanged()
proc addActivityNotificationItemToList*(self: ActivityNotificationList, activityCenterNotification: ActivityCenterNotification) =
proc addActivityNotificationItemToList*(self: ActivityNotificationList, activityCenterNotification: ActivityCenterNotification, addToCount: bool = true) =
self.beginInsertRows(newQModelIndex(), self.activityCenterNotifications.len, self.activityCenterNotifications.len)
self.activityCenterNotifications.add(self.toActivityCenterNotificationViewItem(activityCenterNotification))
self.endInsertRows()
if (not activityCenterNotification.read):
self.nbUnreadNotifications = self.nbUnreadNotifications + 1
if (addToCount and not activityCenterNotification.read):
self.nbUnreadNotifications = self.nbUnreadNotifications + 1
proc addActivityNotificationItemsToList*(self: ActivityNotificationList, activityCenterNotifications: seq[ActivityCenterNotification]) =
if (self.activityCenterNotifications.len == 0):
self.setNewData(activityCenterNotifications)
else:
for activityCenterNotification in activityCenterNotifications:
self.addActivityNotificationItemToList(activityCenterNotification, false)
self.nbUnreadNotifications = self.status.chat.unreadActivityCenterNotificationsCount()
self.unreadCountChanged()
self.hasMoreToShowChanged()

View File

@ -552,7 +552,6 @@ proc activityCenterNotifications*(self: ChatModel, initialLoad: bool = true) =
self.events.emit("activityCenterNotificationsLoaded", ActivityCenterNotificationsArgs(activityCenterNotifications: activityCenterNotificationsTuple[1]))
proc activityCenterNotifications*(self: ChatModel, cursor: string = "", activityCenterNotifications: seq[ActivityCenterNotification]) =
self.activityCenterCursor = cursor

View File

@ -212,15 +212,19 @@ Popup {
}
}
// StyledText {
// text: "Today"
// anchors.left: parent.left
// anchors.leftMargin: Style.current.padding
// font.pixelSize: 15
// bottomPadding: 4
// topPadding: Style.current.halfPadding
// color: Style.current.secondaryText
// }
Item {
visible: chatsModel.activityNotificationList.hasMoreToShow
width: parent.width
height: visible ? showMoreBtn.height + showMoreBtn.anchors.topMargin : 0
StatusButton {
id: showMoreBtn
text: qsTr("Show more")
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: Style.current.smallPadding
onClicked: chatsModel.activityNotificationList.loadMoreNotifications()
}
}
}
}
}