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
This commit is contained in:
Jonathan Rainville 2021-06-11 12:47:53 -04:00 committed by GitHub
parent cab6281dc5
commit f2678ea950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 2 deletions

View File

@ -1 +1 @@
0.79.11
0.79.12

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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()
}