From f2678ea9506ea4ff5f380a16a9ee329313f35630 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 11 Jun 2021 12:47:53 -0400 Subject: [PATCH] Make it possible to mark individual notifications as read (#2256) * feat: make it possible to mark individual notifications as read * fix mark one notif test --- VERSION | 2 +- protocol/activity_center_persistence.go | 14 ++++++++++++++ protocol/messenger_activity_center.go | 4 ++++ protocol/persistence_test.go | 8 +++++++- services/ext/api.go | 4 ++++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 5b29a6679..7b4c1a45f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.79.11 +0.79.12 diff --git a/protocol/activity_center_persistence.go b/protocol/activity_center_persistence.go index d3f960366..a261e22fa 100644 --- a/protocol/activity_center_persistence.go +++ b/protocol/activity_center_persistence.go @@ -287,6 +287,20 @@ func (db sqlitePersistence) MarkAllActivityCenterNotificationsRead() error { return err } +func (db sqlitePersistence) MarkActivityCenterNotificationsRead(ids []types.HexBytes) error { + + idsArgs := make([]interface{}, 0, len(ids)) + for _, id := range ids { + idsArgs = append(idsArgs, id) + } + + inVector := strings.Repeat("?, ", len(ids)-1) + "?" + query := "UPDATE activity_center_notifications SET read = 1 WHERE id IN (" + inVector + ")" // nolint: gosec + _, err := db.db.Exec(query, idsArgs...) + return err + +} + func (db sqlitePersistence) UnreadActivityCenterNotificationsCount() (uint64, error) { var count uint64 err := db.db.QueryRow(`SELECT COUNT(1) FROM activity_center_notifications WHERE NOT read`).Scan(&count) diff --git a/protocol/messenger_activity_center.go b/protocol/messenger_activity_center.go index d5b868479..fe4791bd8 100644 --- a/protocol/messenger_activity_center.go +++ b/protocol/messenger_activity_center.go @@ -12,6 +12,10 @@ func (m *Messenger) MarkAllActivityCenterNotificationsRead() error { return m.persistence.MarkAllActivityCenterNotificationsRead() } +func (m *Messenger) MarkActivityCenterNotificationsRead(ids []types.HexBytes) error { + return m.persistence.MarkActivityCenterNotificationsRead(ids) +} + func (m *Messenger) processAcceptedActivityCenterNotifications(notifications []*ActivityCenterNotification) (*MessengerResponse, error) { response := &MessengerResponse{} var chats []*Chat diff --git a/protocol/persistence_test.go b/protocol/persistence_test.go index 12bf061e5..ce9651ad4 100644 --- a/protocol/persistence_test.go +++ b/protocol/persistence_test.go @@ -1207,7 +1207,13 @@ func TestActivityCenterPersistence(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(2), count) - // Mark the all read + // Mark first one as read + require.NoError(t, p.MarkActivityCenterNotificationsRead([]types.HexBytes{nID1})) + count, err = p.UnreadActivityCenterNotificationsCount() + require.NoError(t, err) + require.Equal(t, uint64(1), count) + + // Mark all read require.NoError(t, p.MarkAllActivityCenterNotificationsRead()) _, notifications, err = p.ActivityCenterNotifications(cursor, 2) require.NoError(t, err) diff --git a/services/ext/api.go b/services/ext/api.go index 12ce9d898..e789c9cb7 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -757,6 +757,10 @@ func (api *PublicAPI) MarkAllActivityCenterNotificationsRead() error { return api.service.messenger.MarkAllActivityCenterNotificationsRead() } +func (api *PublicAPI) MarkActivityCenterNotificationsRead(ids []types.HexBytes) error { + return api.service.messenger.MarkActivityCenterNotificationsRead(ids) +} + func (api *PublicAPI) AcceptAllActivityCenterNotifications() (*protocol.MessengerResponse, error) { return api.service.messenger.AcceptAllActivityCenterNotifications() }