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:
parent
cab6281dc5
commit
f2678ea950
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue