2023-02-24 23:47:04 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
2023-06-10 02:00:17 +00:00
|
|
|
"time"
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
"github.com/status-im/status-go/protocol/common"
|
2023-07-19 12:14:42 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func TestActivityCenterPersistence(t *testing.T) {
|
|
|
|
suite.Run(t, new(ActivityCenterPersistenceTestSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type ActivityCenterPersistenceTestSuite struct {
|
|
|
|
suite.Suite
|
2023-10-06 11:49:31 +00:00
|
|
|
idCounter int
|
2023-10-06 11:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ActivityCenterPersistenceTestSuite) SetupTest() {
|
2023-10-06 11:49:31 +00:00
|
|
|
s.idCounter = 0
|
2023-10-06 11:48:30 +00:00
|
|
|
}
|
|
|
|
|
2023-06-10 02:00:17 +00:00
|
|
|
func currentMilliseconds() uint64 {
|
|
|
|
c := time.Now().UnixMilli()
|
|
|
|
return uint64(c)
|
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) createNotifications(p *sqlitePersistence, notifications []*ActivityCenterNotification) []*ActivityCenterNotification {
|
2023-06-10 02:00:17 +00:00
|
|
|
now := currentMilliseconds()
|
2023-02-24 23:47:04 +00:00
|
|
|
for index, notif := range notifications {
|
|
|
|
if notif.Timestamp == 0 {
|
2023-06-10 02:00:17 +00:00
|
|
|
notif.Timestamp = now
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
if len(notif.ID) == 0 {
|
2023-10-06 11:49:31 +00:00
|
|
|
s.idCounter++
|
|
|
|
notif.ID = types.HexBytes(strconv.Itoa(s.idCounter + index))
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
2023-06-10 02:00:17 +00:00
|
|
|
if notif.UpdatedAt == 0 {
|
|
|
|
notif.UpdatedAt = now
|
|
|
|
}
|
|
|
|
_, err := p.SaveActivityCenterNotification(notif, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err, notif.ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fetches notifications to get an up-to-date slice.
|
|
|
|
var createdNotifications []*ActivityCenterNotification
|
|
|
|
for _, notif := range notifications {
|
|
|
|
n, err := p.GetActivityCenterNotificationByID(notif.ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err, notif.ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
createdNotifications = append(createdNotifications, n)
|
|
|
|
}
|
|
|
|
|
|
|
|
return createdNotifications
|
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_DeleteActivityCenterNotificationsWhenEmpty() {
|
2023-02-24 23:47:04 +00:00
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
chat := CreatePublicChat("test-chat", &testTimeSource{})
|
2023-08-18 11:39:59 +00:00
|
|
|
message := common.NewMessage()
|
2023-02-24 23:47:04 +00:00
|
|
|
message.Text = "sample text"
|
|
|
|
chat.LastMessage = message
|
|
|
|
err = p.SaveChat(*chat)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
s.createNotifications(p, []*ActivityCenterNotification{
|
2023-02-24 23:47:04 +00:00
|
|
|
{
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
var count uint64
|
2023-03-03 14:31:48 +00:00
|
|
|
count, _ = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().Equal(uint64(1), count)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.DeleteActivityCenterNotifications([]types.HexBytes{}, currentMilliseconds())
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
count, _ = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().Equal(uint64(1), count)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_DeleteActivityCenterNotificationsWithMultipleIds() {
|
2023-02-24 23:47:04 +00:00
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
chat := CreatePublicChat("test-chat", &testTimeSource{})
|
2023-08-18 11:39:59 +00:00
|
|
|
message := common.NewMessage()
|
2023-02-24 23:47:04 +00:00
|
|
|
message.Text = "sample text"
|
|
|
|
chat.LastMessage = message
|
|
|
|
err = p.SaveChat(*chat)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
notifications := s.createNotifications(p, []*ActivityCenterNotification{
|
2023-02-24 23:47:04 +00:00
|
|
|
{Type: ActivityCenterNotificationTypeMention},
|
|
|
|
{Type: ActivityCenterNotificationTypeNewOneToOne},
|
|
|
|
{Type: ActivityCenterNotificationTypeNewOneToOne},
|
|
|
|
})
|
|
|
|
|
|
|
|
var count uint64
|
2023-03-03 14:31:48 +00:00
|
|
|
count, _ = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().Equal(uint64(3), count)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.DeleteActivityCenterNotifications([]types.HexBytes{notifications[1].ID, notifications[2].ID}, currentMilliseconds())
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
count, _ = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().Equal(uint64(1), count)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_DeleteActivityCenterNotificationsForMessage() {
|
2023-02-24 23:47:04 +00:00
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
chat := CreatePublicChat("test-chat", &testTimeSource{})
|
|
|
|
err = p.SaveChat(*chat)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
chat2 := CreatePublicChat("test-chat", &testTimeSource{})
|
|
|
|
err = p.SaveChat(*chat2)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
messages := []*common.Message{
|
|
|
|
{
|
|
|
|
ID: "0x1",
|
2023-08-18 11:39:59 +00:00
|
|
|
ChatMessage: &protobuf.ChatMessage{},
|
2023-02-24 23:47:04 +00:00
|
|
|
LocalChatID: chat.ID,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "0x2",
|
2023-08-18 11:39:59 +00:00
|
|
|
ChatMessage: &protobuf.ChatMessage{},
|
2023-02-24 23:47:04 +00:00
|
|
|
LocalChatID: chat.ID,
|
|
|
|
},
|
|
|
|
{
|
2023-08-18 11:39:59 +00:00
|
|
|
ChatMessage: &protobuf.ChatMessage{},
|
|
|
|
ID: "0x3",
|
2023-02-24 23:47:04 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
err = p.SaveMessages(messages)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
chat.LastMessage = messages[1]
|
|
|
|
err = p.SaveChat(*chat)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
chatMessages, _, err := p.MessageByChatID(chat.ID, "", 2)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(chatMessages, 2)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
nID1 := types.HexBytes("1")
|
|
|
|
nID2 := types.HexBytes("2")
|
|
|
|
nID3 := types.HexBytes("3")
|
|
|
|
nID4 := types.HexBytes("4")
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
s.createNotifications(p, []*ActivityCenterNotification{
|
2023-02-24 23:47:04 +00:00
|
|
|
{
|
|
|
|
ID: nID1,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
Message: messages[0],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: nID2,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
Message: messages[1],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: nID3,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: nID4,
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
// Test: soft delete only the notifications that have Message.ID == messages[0].ID.
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.DeleteActivityCenterNotificationForMessage(chat.ID, messages[0].ID, currentMilliseconds())
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
notif, err := p.GetActivityCenterNotificationByID(nID1)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().True(notif.Deleted)
|
|
|
|
s.Require().True(notif.Dismissed)
|
|
|
|
s.Require().True(notif.Read)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Other notifications are not affected.
|
|
|
|
for _, id := range []types.HexBytes{nID2, nID3, nID4} {
|
|
|
|
notif, err = p.GetActivityCenterNotificationByID(id)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notif.Deleted, notif.ID)
|
|
|
|
s.Require().False(notif.Dismissed, notif.ID)
|
|
|
|
s.Require().False(notif.Read, notif.ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test: soft delete the notifications that have Message.ID == messages[1].ID
|
|
|
|
// or LastMessage.ID == chat.LastMessage.
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.DeleteActivityCenterNotificationForMessage(chat.ID, messages[1].ID, currentMilliseconds())
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
for _, id := range []types.HexBytes{nID2, nID3} {
|
|
|
|
notif, err = p.GetActivityCenterNotificationByID(id)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err, notif.ID)
|
|
|
|
s.Require().True(notif.Deleted, notif.ID)
|
|
|
|
s.Require().True(notif.Dismissed, notif.ID)
|
|
|
|
s.Require().True(notif.Read, notif.ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
notif, err = p.GetActivityCenterNotificationByID(nID4)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notif.Deleted)
|
|
|
|
s.Require().False(notif.Dismissed)
|
|
|
|
s.Require().False(notif.Read)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Test: don't do anything if passed a chat and message without notifications.
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.DeleteActivityCenterNotificationForMessage(chat2.ID, messages[2].ID, currentMilliseconds())
|
2023-07-19 12:14:42 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_AcceptActivityCenterNotificationsForInvitesFromUser() {
|
2023-02-24 23:47:04 +00:00
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
nID1 := types.HexBytes("1")
|
|
|
|
nID2 := types.HexBytes("2")
|
|
|
|
nID3 := types.HexBytes("3")
|
|
|
|
nID4 := types.HexBytes("4")
|
|
|
|
|
|
|
|
userPublicKey := "zQ3sh"
|
|
|
|
|
|
|
|
notifications := []*ActivityCenterNotification{
|
|
|
|
{
|
|
|
|
ID: nID1,
|
|
|
|
Type: ActivityCenterNotificationTypeNewPrivateGroupChat,
|
|
|
|
Timestamp: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: nID2,
|
|
|
|
Type: ActivityCenterNotificationTypeNewPrivateGroupChat,
|
|
|
|
Timestamp: 1,
|
|
|
|
Author: userPublicKey,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: nID3,
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
Timestamp: 1,
|
|
|
|
Author: userPublicKey,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: nID4,
|
|
|
|
Timestamp: 1,
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var notif *ActivityCenterNotification
|
|
|
|
for _, notif = range notifications {
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.SaveActivityCenterNotification(notif, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err, notif.ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Only notifications of type new private group chat and with Author equal to
|
|
|
|
// userPublicKey should be marked as accepted & read.
|
|
|
|
_, err = p.GetActivityCenterNotificationByID(nID2)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notifications[0].Accepted)
|
|
|
|
s.Require().False(notifications[0].Read)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-06-10 02:00:17 +00:00
|
|
|
notifications, err = p.AcceptActivityCenterNotificationsForInvitesFromUser(userPublicKey, 1)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().Equal(nID2, notifications[0].ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
notif, err = p.GetActivityCenterNotificationByID(nID2)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().True(notif.Accepted)
|
|
|
|
s.Require().True(notif.Read)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Deleted notifications are ignored.
|
|
|
|
notif = &ActivityCenterNotification{
|
|
|
|
ID: types.HexBytes("99"),
|
|
|
|
Type: ActivityCenterNotificationTypeNewPrivateGroupChat,
|
|
|
|
Timestamp: 1,
|
|
|
|
Author: userPublicKey,
|
|
|
|
Deleted: true,
|
|
|
|
}
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.SaveActivityCenterNotification(notif, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.AcceptActivityCenterNotificationsForInvitesFromUser(userPublicKey, currentMilliseconds())
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
notif, err = p.GetActivityCenterNotificationByID(notif.ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notif.Accepted)
|
|
|
|
s.Require().False(notif.Read)
|
|
|
|
s.Require().True(notif.Deleted)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Dismissed notifications are ignored.
|
|
|
|
notif = &ActivityCenterNotification{
|
|
|
|
ID: types.HexBytes("100"),
|
|
|
|
Type: ActivityCenterNotificationTypeNewPrivateGroupChat,
|
|
|
|
Timestamp: 1,
|
|
|
|
Author: userPublicKey,
|
|
|
|
Dismissed: true,
|
|
|
|
}
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.SaveActivityCenterNotification(notif, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.AcceptActivityCenterNotificationsForInvitesFromUser(userPublicKey, currentMilliseconds())
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
notif, err = p.GetActivityCenterNotificationByID(notif.ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notif.Accepted)
|
|
|
|
s.Require().False(notif.Read)
|
|
|
|
s.Require().True(notif.Dismissed)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_GetToProcessActivityCenterNotificationIds() {
|
2023-02-24 23:47:04 +00:00
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
notifications := s.createNotifications(p, []*ActivityCenterNotification{
|
2023-02-24 23:47:04 +00:00
|
|
|
{
|
|
|
|
Type: ActivityCenterNotificationTypeNewPrivateGroupChat,
|
|
|
|
Deleted: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: ActivityCenterNotificationTypeNewPrivateGroupChat,
|
|
|
|
Dismissed: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
Accepted: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
ids, err := p.GetToProcessActivityCenterNotificationIds()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(ids, 1)
|
|
|
|
s.Require().Equal(notifications[3].ID, types.HexBytes(ids[0]))
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_HasPendingNotificationsForChat() {
|
2023-02-24 23:47:04 +00:00
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
chat := CreatePublicChat("test-chat", &testTimeSource{})
|
|
|
|
err = p.SaveChat(*chat)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Test: there are no notifications.
|
|
|
|
result, err := p.HasPendingNotificationsForChat(chat.ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(result)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Test: there are only deleted, dismissed or accepted notifications,
|
|
|
|
// therefore, no pending notifications.
|
2023-10-06 11:48:30 +00:00
|
|
|
s.createNotifications(p, []*ActivityCenterNotification{
|
2023-02-24 23:47:04 +00:00
|
|
|
{
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Type: ActivityCenterNotificationTypeNewPrivateGroupChat,
|
|
|
|
Deleted: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Type: ActivityCenterNotificationTypeNewPrivateGroupChat,
|
|
|
|
Dismissed: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
Accepted: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
result, err = p.HasPendingNotificationsForChat(chat.ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(result)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Test: there's one pending notification.
|
|
|
|
notif := &ActivityCenterNotification{
|
|
|
|
ID: types.HexBytes("99"),
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Type: ActivityCenterNotificationTypeCommunityRequest,
|
|
|
|
Timestamp: 1,
|
|
|
|
}
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.SaveActivityCenterNotification(notif, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
result, err = p.HasPendingNotificationsForChat(chat.ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().True(result)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_DismissAllActivityCenterNotificationsFromUser() {
|
2023-02-24 23:47:04 +00:00
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
publicKey := "0x04"
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
notifications := s.createNotifications(p, []*ActivityCenterNotification{
|
2023-02-24 23:47:04 +00:00
|
|
|
{
|
|
|
|
Type: ActivityCenterNotificationTypeNewPrivateGroupChat,
|
|
|
|
Author: publicKey,
|
|
|
|
Deleted: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: ActivityCenterNotificationTypeNewPrivateGroupChat,
|
|
|
|
Author: publicKey,
|
|
|
|
Dismissed: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
Author: publicKey,
|
|
|
|
Accepted: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
Author: "0x09",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
Author: publicKey,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.DismissAllActivityCenterNotificationsFromUser(publicKey, 1)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Ignores already soft deleted.
|
|
|
|
notif, err := p.GetActivityCenterNotificationByID(notifications[0].ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notif.Accepted)
|
|
|
|
s.Require().False(notif.Read)
|
|
|
|
s.Require().False(notif.Dismissed)
|
|
|
|
s.Require().True(notif.Deleted)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Ignores already dismissed.
|
|
|
|
notif, err = p.GetActivityCenterNotificationByID(notifications[1].ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notif.Accepted)
|
|
|
|
s.Require().False(notif.Read)
|
|
|
|
s.Require().True(notif.Dismissed)
|
|
|
|
s.Require().False(notif.Deleted)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Ignores already accepted.
|
|
|
|
notif, err = p.GetActivityCenterNotificationByID(notifications[2].ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().True(notif.Accepted)
|
|
|
|
s.Require().False(notif.Read)
|
|
|
|
s.Require().False(notif.Dismissed)
|
|
|
|
s.Require().False(notif.Deleted)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Ignores notification from different author.
|
|
|
|
notif, err = p.GetActivityCenterNotificationByID(notifications[3].ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notif.Accepted)
|
|
|
|
s.Require().False(notif.Read)
|
|
|
|
s.Require().False(notif.Dismissed)
|
|
|
|
s.Require().False(notif.Deleted)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Finally, dismiss and mark as read this one notification.
|
|
|
|
notif, err = p.GetActivityCenterNotificationByID(notifications[4].ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notif.Accepted)
|
|
|
|
s.Require().True(notif.Read)
|
|
|
|
s.Require().True(notif.Dismissed)
|
|
|
|
s.Require().False(notif.Deleted)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_DismissAllActivityCenterNotificationsFromChatID() {
|
2023-02-24 23:47:04 +00:00
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
chatID := "0x99"
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
notifications := s.createNotifications(p, []*ActivityCenterNotification{
|
2023-02-24 23:47:04 +00:00
|
|
|
{
|
|
|
|
ChatID: chatID,
|
|
|
|
Type: ActivityCenterNotificationTypeNewPrivateGroupChat,
|
|
|
|
Deleted: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ChatID: chatID,
|
|
|
|
Type: ActivityCenterNotificationTypeNewPrivateGroupChat,
|
|
|
|
Dismissed: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ChatID: chatID,
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
Accepted: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ChatID: chatID,
|
|
|
|
Type: ActivityCenterNotificationTypeContactRequest,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ChatID: chatID,
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.DismissAllActivityCenterNotificationsFromChatID(chatID, currentMilliseconds())
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Ignores already soft deleted.
|
|
|
|
notif, err := p.GetActivityCenterNotificationByID(notifications[0].ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notif.Accepted)
|
|
|
|
s.Require().False(notif.Read)
|
|
|
|
s.Require().False(notif.Dismissed)
|
|
|
|
s.Require().True(notif.Deleted)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Do not ignore already dismissed, because notifications can become
|
|
|
|
// read/unread AND dismissed, and the method should still update the Read
|
|
|
|
// column.
|
|
|
|
notif, err = p.GetActivityCenterNotificationByID(notifications[1].ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notif.Accepted)
|
|
|
|
s.Require().True(notif.Read)
|
|
|
|
s.Require().True(notif.Dismissed)
|
|
|
|
s.Require().False(notif.Deleted)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Ignores already accepted.
|
|
|
|
notif, err = p.GetActivityCenterNotificationByID(notifications[2].ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().True(notif.Accepted)
|
|
|
|
s.Require().False(notif.Read)
|
|
|
|
s.Require().False(notif.Dismissed)
|
|
|
|
s.Require().False(notif.Deleted)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Ignores notification from different chat.
|
|
|
|
notif, err = p.GetActivityCenterNotificationByID(notifications[3].ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notif.Accepted)
|
|
|
|
s.Require().False(notif.Read)
|
|
|
|
s.Require().False(notif.Dismissed)
|
|
|
|
s.Require().False(notif.Deleted)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Ignores contact request notifications.
|
|
|
|
notif, err = p.GetActivityCenterNotificationByID(notifications[4].ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notif.Accepted)
|
|
|
|
s.Require().False(notif.Read)
|
|
|
|
s.Require().False(notif.Dismissed)
|
|
|
|
s.Require().False(notif.Deleted)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Finally, dismiss and mark as read this one notification.
|
|
|
|
notif, err = p.GetActivityCenterNotificationByID(notifications[5].ID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().False(notif.Accepted)
|
|
|
|
s.Require().True(notif.Read)
|
|
|
|
s.Require().True(notif.Dismissed)
|
|
|
|
s.Require().False(notif.Deleted)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_ActiveContactRequestNotification() {
|
2023-02-24 23:47:04 +00:00
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
chat := CreatePublicChat("test-chat", &testTimeSource{})
|
|
|
|
err = p.SaveChat(*chat)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
contactID := "0x99"
|
|
|
|
|
|
|
|
// Test: ignores deleted/dismissed/accepted notifications, as well as
|
|
|
|
// notifications not associated to any chat.
|
2023-10-06 11:48:30 +00:00
|
|
|
s.createNotifications(p, []*ActivityCenterNotification{
|
2023-02-24 23:47:04 +00:00
|
|
|
{
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Author: contactID,
|
|
|
|
Type: ActivityCenterNotificationTypeContactRequest,
|
|
|
|
Deleted: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Author: contactID,
|
|
|
|
Type: ActivityCenterNotificationTypeContactRequest,
|
|
|
|
Dismissed: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Author: contactID,
|
|
|
|
Type: ActivityCenterNotificationTypeContactRequest,
|
|
|
|
Accepted: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
notif, err := p.ActiveContactRequestNotification(contactID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Nil(notif)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Test: Ignores notifications that are not contact requests.
|
2023-10-06 11:48:30 +00:00
|
|
|
s.createNotifications(p, []*ActivityCenterNotification{
|
2023-02-24 23:47:04 +00:00
|
|
|
{ChatID: chat.ID, Author: contactID, Type: ActivityCenterNotificationTypeCommunityInvitation},
|
|
|
|
{ChatID: chat.ID, Author: contactID, Type: ActivityCenterNotificationTypeCommunityKicked},
|
|
|
|
{ChatID: chat.ID, Author: contactID, Type: ActivityCenterNotificationTypeCommunityMembershipRequest},
|
|
|
|
{ChatID: chat.ID, Author: contactID, Type: ActivityCenterNotificationTypeCommunityRequest},
|
|
|
|
{ChatID: chat.ID, Author: contactID, Type: ActivityCenterNotificationTypeContactVerification},
|
|
|
|
{ChatID: chat.ID, Author: contactID, Type: ActivityCenterNotificationTypeMention},
|
|
|
|
{ChatID: chat.ID, Author: contactID, Type: ActivityCenterNotificationTypeNewOneToOne},
|
|
|
|
{ChatID: chat.ID, Author: contactID, Type: ActivityCenterNotificationTypeNewPrivateGroupChat},
|
|
|
|
{ChatID: chat.ID, Author: contactID, Type: ActivityCenterNotificationTypeReply},
|
|
|
|
})
|
|
|
|
|
|
|
|
notif, err = p.ActiveContactRequestNotification(contactID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Nil(notif)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Test: Returns one, and only one contact request notification for the
|
|
|
|
// contact under test.
|
2023-10-06 11:48:30 +00:00
|
|
|
s.createNotifications(p, []*ActivityCenterNotification{
|
2023-02-24 23:47:04 +00:00
|
|
|
{ChatID: chat.ID, Author: contactID, Type: ActivityCenterNotificationTypeContactRequest},
|
|
|
|
})
|
|
|
|
|
|
|
|
notif, err = p.ActiveContactRequestNotification(contactID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-10-06 11:49:31 +00:00
|
|
|
s.Require().NotNil(notif)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().Equal(ActivityCenterNotificationTypeContactRequest, notif.Type)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Test: In case there's more than one notification, return the most recent
|
|
|
|
// one according to the notification's timestamp.
|
|
|
|
expectedID := types.HexBytes("667")
|
|
|
|
|
2023-06-10 02:00:17 +00:00
|
|
|
t1 := currentMilliseconds()
|
|
|
|
t2 := currentMilliseconds()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.createNotifications(p, []*ActivityCenterNotification{
|
2023-02-24 23:47:04 +00:00
|
|
|
{
|
|
|
|
ID: expectedID,
|
2023-06-10 02:00:17 +00:00
|
|
|
Timestamp: t2 + 1,
|
2023-02-24 23:47:04 +00:00
|
|
|
ChatID: chat.ID,
|
|
|
|
Author: contactID,
|
|
|
|
Type: ActivityCenterNotificationTypeContactRequest,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: types.HexBytes("666"),
|
2023-06-10 02:00:17 +00:00
|
|
|
Timestamp: t1,
|
2023-02-24 23:47:04 +00:00
|
|
|
ChatID: chat.ID,
|
|
|
|
Author: contactID,
|
|
|
|
Type: ActivityCenterNotificationTypeContactRequest,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
notif, err = p.ActiveContactRequestNotification(contactID)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(expectedID, notif.ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_UnreadActivityCenterNotificationsCount() {
|
2023-02-24 23:47:04 +00:00
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
s.createNotifications(p, []*ActivityCenterNotification{
|
2023-02-24 23:47:04 +00:00
|
|
|
{Type: ActivityCenterNotificationTypeMention, Read: true},
|
|
|
|
{Type: ActivityCenterNotificationTypeNewOneToOne, Deleted: true},
|
|
|
|
{Type: ActivityCenterNotificationTypeMention, Dismissed: true},
|
|
|
|
{Type: ActivityCenterNotificationTypeCommunityRequest, Accepted: true},
|
|
|
|
{Type: ActivityCenterNotificationTypeContactRequest},
|
|
|
|
})
|
|
|
|
|
|
|
|
// Test: Ignore soft deleted and accepted.
|
2023-03-03 14:31:48 +00:00
|
|
|
count, err := p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(uint64(3), count)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_UnreadAndAcceptedActivityCenterNotificationsCount() {
|
2023-02-24 23:47:04 +00:00
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
s.createNotifications(p, []*ActivityCenterNotification{
|
2023-02-24 23:47:04 +00:00
|
|
|
{Type: ActivityCenterNotificationTypeMention, Read: true},
|
|
|
|
{Type: ActivityCenterNotificationTypeNewOneToOne, Deleted: true},
|
|
|
|
{Type: ActivityCenterNotificationTypeMention, Dismissed: true},
|
|
|
|
{Type: ActivityCenterNotificationTypeCommunityRequest, Accepted: true},
|
|
|
|
{Type: ActivityCenterNotificationTypeContactRequest},
|
|
|
|
})
|
|
|
|
|
|
|
|
// Test: counts everything, except soft deleted notifications.
|
2023-03-03 14:31:48 +00:00
|
|
|
count, err := p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(uint64(3), count)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Test: counts everything, except soft deleted ones and limit by type.
|
2023-03-03 14:31:48 +00:00
|
|
|
count, err = p.ActivityCenterNotificationsCount([]ActivityCenterType{
|
|
|
|
ActivityCenterNotificationTypeContactRequest,
|
|
|
|
}, ActivityCenterQueryParamsReadUnread, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(uint64(1), count)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_ActivityCenterPersistence() {
|
2023-02-24 23:47:04 +00:00
|
|
|
nID1 := types.HexBytes([]byte("1"))
|
|
|
|
nID2 := types.HexBytes([]byte("2"))
|
|
|
|
nID3 := types.HexBytes([]byte("3"))
|
|
|
|
nID4 := types.HexBytes([]byte("4"))
|
|
|
|
|
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
chat := CreatePublicChat("test-chat", &testTimeSource{})
|
2023-08-18 11:39:59 +00:00
|
|
|
message := common.NewMessage()
|
2023-02-24 23:47:04 +00:00
|
|
|
message.Text = "sample text"
|
|
|
|
chat.LastMessage = message
|
|
|
|
err = p.SaveChat(*chat)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
notification := &ActivityCenterNotification{
|
|
|
|
ID: nID1,
|
|
|
|
Type: ActivityCenterNotificationTypeNewOneToOne,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Timestamp: 1,
|
|
|
|
}
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.SaveActivityCenterNotification(notification, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
cursor, notifications, err := p.ActivityCenterNotifications("", 2, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Empty(cursor)
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().Equal(chat.ID, notifications[0].ChatID)
|
|
|
|
s.Require().Equal(message, notifications[0].LastMessage)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Add another notification
|
|
|
|
|
|
|
|
notification = &ActivityCenterNotification{
|
|
|
|
ID: nID2,
|
|
|
|
Type: ActivityCenterNotificationTypeNewOneToOne,
|
|
|
|
Timestamp: 2,
|
|
|
|
}
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.SaveActivityCenterNotification(notification, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
cursor, notifications, err = p.ActivityCenterNotifications("", 1, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().NotEmpty(cursor)
|
|
|
|
s.Require().Equal(nID2, notifications[0].ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// fetch next pagination
|
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
cursor, notifications, err = p.ActivityCenterNotifications(cursor, 1, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().Empty(cursor)
|
|
|
|
s.Require().False(notifications[0].Read)
|
|
|
|
s.Require().Equal(nID1, notifications[0].ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Check count
|
2023-03-03 14:31:48 +00:00
|
|
|
count, err := p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(uint64(2), count)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-06-10 02:00:17 +00:00
|
|
|
var updatedAt uint64 = 1
|
2023-02-24 23:47:04 +00:00
|
|
|
// Mark first one as read
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(p.MarkActivityCenterNotificationsRead([]types.HexBytes{nID1}, updatedAt))
|
2023-03-03 14:31:48 +00:00
|
|
|
count, err = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(uint64(1), count)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Mark first one as unread
|
2023-06-10 02:00:17 +00:00
|
|
|
updatedAt++
|
|
|
|
_, err = p.MarkActivityCenterNotificationsUnread([]types.HexBytes{nID1}, updatedAt)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-03-03 14:31:48 +00:00
|
|
|
count, err = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(uint64(2), count)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Mark all read
|
2023-06-10 02:00:17 +00:00
|
|
|
updatedAt++
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(p.MarkAllActivityCenterNotificationsRead(updatedAt))
|
2023-03-03 14:31:48 +00:00
|
|
|
_, notifications, err = p.ActivityCenterNotifications(cursor, 2, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 2)
|
|
|
|
s.Require().Empty(cursor)
|
|
|
|
s.Require().True(notifications[0].Read)
|
|
|
|
s.Require().True(notifications[1].Read)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Check count
|
2023-03-03 14:31:48 +00:00
|
|
|
count, err = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(uint64(0), count)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Mark first one as accepted
|
2023-06-10 02:00:17 +00:00
|
|
|
updatedAt++
|
|
|
|
notifications, err = p.AcceptActivityCenterNotifications([]types.HexBytes{nID1}, updatedAt)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 1)
|
2023-03-03 14:31:48 +00:00
|
|
|
_, notifications, err = p.ActivityCenterNotifications("", 2, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
// It should not be returned anymore
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().Len(notifications, 1)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Mark last one as dismissed
|
2023-06-10 02:00:17 +00:00
|
|
|
updatedAt++
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(p.DismissActivityCenterNotifications([]types.HexBytes{nID2}, updatedAt))
|
2023-03-03 14:31:48 +00:00
|
|
|
_, notifications, err = p.ActivityCenterNotifications("", 2, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().True(notifications[0].Dismissed)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Insert new notification
|
|
|
|
notification = &ActivityCenterNotification{
|
|
|
|
ID: nID3,
|
|
|
|
Type: ActivityCenterNotificationTypeNewOneToOne,
|
|
|
|
Timestamp: 3,
|
|
|
|
}
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.SaveActivityCenterNotification(notification, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Mark all as accepted
|
2023-06-10 02:00:17 +00:00
|
|
|
updatedAt++
|
|
|
|
notifications, err = p.AcceptAllActivityCenterNotifications(updatedAt)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 2)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
_, notifications, err = p.ActivityCenterNotifications("", 2, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().Len(notifications, 1)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Insert new notification
|
|
|
|
notification = &ActivityCenterNotification{
|
|
|
|
ID: nID4,
|
|
|
|
Type: ActivityCenterNotificationTypeNewOneToOne,
|
|
|
|
Timestamp: 4,
|
|
|
|
}
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.SaveActivityCenterNotification(notification, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Mark all as dismissed
|
2023-06-10 02:00:17 +00:00
|
|
|
updatedAt++
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(p.DismissAllActivityCenterNotifications(updatedAt))
|
2023-03-03 14:31:48 +00:00
|
|
|
_, notifications, err = p.ActivityCenterNotifications("", 2, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().Len(notifications, 2)
|
|
|
|
s.Require().True(notifications[0].Dismissed)
|
|
|
|
s.Require().True(notifications[1].Dismissed)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_ActivityCenterReadUnreadPagination() {
|
2023-02-24 23:47:04 +00:00
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
initialOrFinalCursor := ""
|
|
|
|
|
|
|
|
chat := CreatePublicChat("test-chat", &testTimeSource{})
|
2023-08-18 11:39:59 +00:00
|
|
|
message := common.NewMessage()
|
2023-02-24 23:47:04 +00:00
|
|
|
message.Text = "sample text"
|
|
|
|
chat.LastMessage = message
|
|
|
|
err = p.SaveChat(*chat)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
nID1 := types.HexBytes("1")
|
|
|
|
nID2 := types.HexBytes("2")
|
|
|
|
nID3 := types.HexBytes("3")
|
|
|
|
nID4 := types.HexBytes("4")
|
|
|
|
nID5 := types.HexBytes("5")
|
|
|
|
|
|
|
|
allNotifications := []*ActivityCenterNotification{
|
|
|
|
{
|
|
|
|
ID: nID1,
|
|
|
|
Type: ActivityCenterNotificationTypeNewOneToOne,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Timestamp: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: nID2,
|
|
|
|
Type: ActivityCenterNotificationTypeNewOneToOne,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Timestamp: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: nID3,
|
|
|
|
Type: ActivityCenterNotificationTypeNewOneToOne,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Timestamp: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: nID4,
|
|
|
|
Type: ActivityCenterNotificationTypeNewOneToOne,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Timestamp: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: nID5,
|
|
|
|
Type: ActivityCenterNotificationTypeNewOneToOne,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Timestamp: 1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, notification := range allNotifications {
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.SaveActivityCenterNotification(notification, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark the notification as read
|
2023-06-10 02:00:17 +00:00
|
|
|
err = p.MarkActivityCenterNotificationsRead([]types.HexBytes{nID2}, currentMilliseconds())
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-06-10 02:00:17 +00:00
|
|
|
err = p.MarkActivityCenterNotificationsRead([]types.HexBytes{nID4}, currentMilliseconds())
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Fetch UNREAD notifications, first page.
|
2023-03-03 14:31:48 +00:00
|
|
|
cursor, notifications, err := p.ActivityCenterNotifications(
|
2023-02-24 23:47:04 +00:00
|
|
|
initialOrFinalCursor,
|
|
|
|
1,
|
|
|
|
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
|
2023-03-03 14:31:48 +00:00
|
|
|
ActivityCenterQueryParamsReadUnread,
|
|
|
|
false,
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().Equal(nID5, notifications[0].ID)
|
|
|
|
s.Require().NotEmpty(cursor)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Fetch next pages.
|
2023-03-03 14:31:48 +00:00
|
|
|
cursor, notifications, err = p.ActivityCenterNotifications(
|
2023-02-24 23:47:04 +00:00
|
|
|
cursor,
|
|
|
|
1,
|
|
|
|
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
|
2023-03-03 14:31:48 +00:00
|
|
|
ActivityCenterQueryParamsReadUnread,
|
|
|
|
false,
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().Equal(nID3, notifications[0].ID)
|
|
|
|
s.Require().NotEmpty(cursor)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
cursor, notifications, err = p.ActivityCenterNotifications(
|
2023-02-24 23:47:04 +00:00
|
|
|
cursor,
|
|
|
|
1,
|
|
|
|
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
|
2023-03-03 14:31:48 +00:00
|
|
|
ActivityCenterQueryParamsReadUnread,
|
|
|
|
false,
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().Equal(nID1, notifications[0].ID)
|
|
|
|
s.Require().Empty(cursor)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Fetch READ notifications, first page.
|
2023-03-03 14:31:48 +00:00
|
|
|
cursor, notifications, err = p.ActivityCenterNotifications(
|
2023-02-24 23:47:04 +00:00
|
|
|
initialOrFinalCursor,
|
|
|
|
1,
|
|
|
|
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
|
2023-03-03 14:31:48 +00:00
|
|
|
ActivityCenterQueryParamsReadRead,
|
|
|
|
false,
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().Equal(nID4, notifications[0].ID)
|
|
|
|
s.Require().NotEmpty(cursor)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Fetch next page.
|
2023-03-03 14:31:48 +00:00
|
|
|
cursor, notifications, err = p.ActivityCenterNotifications(
|
2023-02-24 23:47:04 +00:00
|
|
|
cursor,
|
|
|
|
1,
|
|
|
|
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
|
2023-03-03 14:31:48 +00:00
|
|
|
ActivityCenterQueryParamsReadRead,
|
|
|
|
false,
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().Equal(nID2, notifications[0].ID)
|
|
|
|
s.Require().Empty(cursor)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_ActivityCenterReadUnreadFilterByTypes() {
|
2023-02-24 23:47:04 +00:00
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
chat := CreatePublicChat("test-chat", &testTimeSource{})
|
2023-08-18 11:39:59 +00:00
|
|
|
message := common.NewMessage()
|
2023-02-24 23:47:04 +00:00
|
|
|
message.Text = "sample text"
|
|
|
|
chat.LastMessage = message
|
|
|
|
err = p.SaveChat(*chat)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
initialCursor := ""
|
|
|
|
limit := uint64(3)
|
|
|
|
|
|
|
|
nID1 := types.HexBytes("1")
|
|
|
|
nID2 := types.HexBytes("2")
|
|
|
|
nID3 := types.HexBytes("3")
|
|
|
|
|
|
|
|
allNotifications := []*ActivityCenterNotification{
|
|
|
|
{
|
|
|
|
ID: nID1,
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Timestamp: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: nID2,
|
|
|
|
Type: ActivityCenterNotificationTypeNewOneToOne,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Timestamp: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: nID3,
|
|
|
|
Type: ActivityCenterNotificationTypeMention,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Timestamp: 1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, notification := range allNotifications {
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.SaveActivityCenterNotification(notification, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't filter by type if the array of types is empty.
|
2023-03-03 14:31:48 +00:00
|
|
|
_, notifications, err := p.ActivityCenterNotifications(
|
2023-02-24 23:47:04 +00:00
|
|
|
initialCursor,
|
|
|
|
limit,
|
|
|
|
[]ActivityCenterType{},
|
2023-03-03 14:31:48 +00:00
|
|
|
ActivityCenterQueryParamsReadUnread,
|
|
|
|
false,
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 3)
|
|
|
|
s.Require().Equal(nID3, notifications[0].ID)
|
|
|
|
s.Require().Equal(nID2, notifications[1].ID)
|
|
|
|
s.Require().Equal(nID1, notifications[2].ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
_, notifications, err = p.ActivityCenterNotifications(
|
2023-02-24 23:47:04 +00:00
|
|
|
initialCursor,
|
|
|
|
limit,
|
|
|
|
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
|
2023-03-03 14:31:48 +00:00
|
|
|
ActivityCenterQueryParamsReadUnread,
|
|
|
|
false,
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().Equal(nID2, notifications[0].ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
_, notifications, err = p.ActivityCenterNotifications(
|
2023-02-24 23:47:04 +00:00
|
|
|
initialCursor,
|
|
|
|
limit,
|
|
|
|
[]ActivityCenterType{ActivityCenterNotificationTypeMention},
|
2023-03-03 14:31:48 +00:00
|
|
|
ActivityCenterQueryParamsReadUnread,
|
|
|
|
false,
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 2)
|
|
|
|
s.Require().Equal(nID3, notifications[0].ID)
|
|
|
|
s.Require().Equal(nID1, notifications[1].ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
_, notifications, err = p.ActivityCenterNotifications(
|
2023-02-24 23:47:04 +00:00
|
|
|
initialCursor,
|
|
|
|
limit,
|
|
|
|
[]ActivityCenterType{ActivityCenterNotificationTypeMention, ActivityCenterNotificationTypeNewOneToOne},
|
2023-03-03 14:31:48 +00:00
|
|
|
ActivityCenterQueryParamsReadUnread,
|
|
|
|
false,
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 3)
|
|
|
|
s.Require().Equal(nID3, notifications[0].ID)
|
|
|
|
s.Require().Equal(nID2, notifications[1].ID)
|
|
|
|
s.Require().Equal(nID1, notifications[2].ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Mark all notifications as read.
|
|
|
|
for _, notification := range allNotifications {
|
2023-06-10 02:00:17 +00:00
|
|
|
err = p.MarkActivityCenterNotificationsRead([]types.HexBytes{notification.ID}, currentMilliseconds())
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
_, notifications, err = p.ActivityCenterNotifications(
|
2023-02-24 23:47:04 +00:00
|
|
|
initialCursor,
|
|
|
|
limit,
|
|
|
|
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
|
2023-03-03 14:31:48 +00:00
|
|
|
ActivityCenterQueryParamsReadRead,
|
|
|
|
false,
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().Equal(nID2, notifications[0].ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
_, notifications, err = p.ActivityCenterNotifications(
|
2023-02-24 23:47:04 +00:00
|
|
|
initialCursor,
|
|
|
|
limit,
|
|
|
|
[]ActivityCenterType{ActivityCenterNotificationTypeMention},
|
2023-03-03 14:31:48 +00:00
|
|
|
ActivityCenterQueryParamsReadRead,
|
|
|
|
false,
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(notifications, 2)
|
|
|
|
s.Require().Equal(nID3, notifications[0].ID)
|
|
|
|
s.Require().Equal(nID1, notifications[1].ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-06 11:48:30 +00:00
|
|
|
func (s *ActivityCenterPersistenceTestSuite) Test_ActivityCenterReadUnread() {
|
2023-02-24 23:47:04 +00:00
|
|
|
nID1 := types.HexBytes("1")
|
|
|
|
nID2 := types.HexBytes("2")
|
|
|
|
|
|
|
|
db, err := openTestDB()
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
p := newSQLitePersistence(db)
|
|
|
|
|
|
|
|
chat := CreatePublicChat("test-chat", &testTimeSource{})
|
2023-08-18 11:39:59 +00:00
|
|
|
message := common.NewMessage()
|
2023-02-24 23:47:04 +00:00
|
|
|
message.Text = "sample text"
|
|
|
|
chat.LastMessage = message
|
|
|
|
err = p.SaveChat(*chat)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
notification := &ActivityCenterNotification{
|
|
|
|
ID: nID1,
|
|
|
|
Type: ActivityCenterNotificationTypeNewOneToOne,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Timestamp: 1,
|
|
|
|
}
|
|
|
|
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.SaveActivityCenterNotification(notification, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
notification = &ActivityCenterNotification{
|
|
|
|
ID: nID2,
|
|
|
|
Type: ActivityCenterNotificationTypeNewOneToOne,
|
|
|
|
ChatID: chat.ID,
|
|
|
|
Timestamp: 1,
|
|
|
|
}
|
|
|
|
|
2023-06-10 02:00:17 +00:00
|
|
|
_, err = p.SaveActivityCenterNotification(notification, true)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
|
|
|
// Mark the notification as read
|
2023-06-10 02:00:17 +00:00
|
|
|
err = p.MarkActivityCenterNotificationsRead([]types.HexBytes{nID2}, currentMilliseconds())
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
cursor, notifications, err := p.ActivityCenterNotifications(
|
2023-02-24 23:47:04 +00:00
|
|
|
"",
|
|
|
|
2,
|
|
|
|
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
|
2023-03-03 14:31:48 +00:00
|
|
|
ActivityCenterQueryParamsReadUnread,
|
|
|
|
false,
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Empty(cursor)
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().Equal(nID1, notifications[0].ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
|
2023-03-03 14:31:48 +00:00
|
|
|
cursor, notifications, err = p.ActivityCenterNotifications(
|
2023-02-24 23:47:04 +00:00
|
|
|
"",
|
|
|
|
2,
|
|
|
|
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
|
2023-03-03 14:31:48 +00:00
|
|
|
ActivityCenterQueryParamsReadRead,
|
|
|
|
false,
|
2023-02-24 23:47:04 +00:00
|
|
|
)
|
2023-10-06 11:48:30 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Empty(cursor)
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().Equal(nID2, notifications[0].ID)
|
2023-02-24 23:47:04 +00:00
|
|
|
}
|