feat: refactor activity center endpoints (#3237)

* feat: refactor activity center endpoints

* fix: restore activity center tests using new endpoints

* feat: Remove from activity center endpoints accepted flag

* feat: Activity Center review fixes
This commit is contained in:
Mikhail Rogachev 2023-03-03 18:31:48 +04:00 committed by GitHub
parent 596660c110
commit 224f7461e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 147 additions and 198 deletions

View File

@ -1 +1 @@
0.135.2
0.136.0

View File

@ -38,6 +38,14 @@ const (
ActivityCenterMembershipStatusDeclined
)
type ActivityCenterQueryParamsRead uint
const (
ActivityCenterQueryParamsReadRead = iota + 1
ActivityCenterQueryParamsReadUnread
ActivityCenterQueryParamsReadAll
)
var ErrInvalidActivityCenterNotification = errors.New("invalid activity center notification")
type ActivityCenterNotification struct {
@ -59,11 +67,25 @@ type ActivityCenterNotification struct {
ContactVerificationStatus verification.RequestStatus `json:"contactVerificationStatus"`
}
type ActivityCenterNotificationsRequest struct {
Cursor string `json:"cursor"`
Limit uint64 `json:"limit"`
ActivityTypes []ActivityCenterType `json:"activityTypes"`
ReadType ActivityCenterQueryParamsRead `json:"readType"`
}
type ActivityCenterCountRequest struct {
ActivityTypes []ActivityCenterType `json:"activityTypes"`
ReadType ActivityCenterQueryParamsRead `json:"readType"`
}
type ActivityCenterPaginationResponse struct {
Cursor string `json:"cursor"`
Notifications []*ActivityCenterNotification `json:"notifications"`
}
type ActivityCenterCountResponse = map[ActivityCenterType]uint64
type ActivityCenterState struct {
HasSeen bool `json:"hasSeen"`
}

View File

@ -323,14 +323,6 @@ func (db sqlitePersistence) unmarshalActivityCenterNotificationRows(rows *sql.Ro
}
type ActivityCenterQueryParamsRead uint
const (
ActivityCenterQueryParamsReadRead = iota + 1
ActivityCenterQueryParamsReadUnread
ActivityCenterQueryParamsReadAll
)
type activityCenterQueryParams struct {
cursor string
limit uint64
@ -580,40 +572,6 @@ func (db sqlitePersistence) GetActivityCenterNotificationByID(id types.HexBytes)
return notification, err
}
func (db sqlitePersistence) UnreadActivityCenterNotifications(cursor string, limit uint64, activityTypes []ActivityCenterType) (string, []*ActivityCenterNotification, error) {
params := activityCenterQueryParams{
activityCenterTypes: activityTypes,
cursor: cursor,
limit: limit,
read: ActivityCenterQueryParamsReadUnread,
}
return db.activityCenterNotifications(params)
}
func (db sqlitePersistence) ReadActivityCenterNotifications(cursor string, limit uint64, activityTypes []ActivityCenterType) (string, []*ActivityCenterNotification, error) {
params := activityCenterQueryParams{
activityCenterTypes: activityTypes,
cursor: cursor,
limit: limit,
read: ActivityCenterQueryParamsReadRead,
}
return db.activityCenterNotifications(params)
}
func (db sqlitePersistence) ActivityCenterNotificationsBy(cursor string, limit uint64, activityTypes []ActivityCenterType, readType ActivityCenterQueryParamsRead, accepted bool) (string, []*ActivityCenterNotification, error) {
params := activityCenterQueryParams{
activityCenterTypes: activityTypes,
cursor: cursor,
limit: limit,
read: readType,
accepted: accepted,
}
return db.activityCenterNotifications(params)
}
func (db sqlitePersistence) activityCenterNotifications(params activityCenterQueryParams) (string, []*ActivityCenterNotification, error) {
var tx *sql.Tx
var err error
@ -648,14 +606,6 @@ func (db sqlitePersistence) activityCenterNotifications(params activityCenterQue
return latestCursor, notifications, nil
}
func (db sqlitePersistence) ActivityCenterNotifications(currCursor string, limit uint64) (string, []*ActivityCenterNotification, error) {
params := activityCenterQueryParams{
cursor: currCursor,
limit: limit,
}
return db.activityCenterNotifications(params)
}
func (db sqlitePersistence) DismissAllActivityCenterNotifications() error {
_, err := db.db.Exec(`UPDATE activity_center_notifications SET read = 1, dismissed = 1 WHERE NOT dismissed AND NOT accepted`)
return err
@ -887,22 +837,21 @@ func (db sqlitePersistence) MarkActivityCenterNotificationsUnread(ids []types.He
query := "UPDATE activity_center_notifications SET read = 0 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.buildActivityCenterNotificationsCountQuery(true, ActivityCenterQueryParamsReadUnread, []ActivityCenterType{}).Scan(&count)
return count, err
func (db sqlitePersistence) ActivityCenterNotifications(cursor string, limit uint64, activityTypes []ActivityCenterType, readType ActivityCenterQueryParamsRead, accepted bool) (string, []*ActivityCenterNotification, error) {
params := activityCenterQueryParams{
activityCenterTypes: activityTypes,
cursor: cursor,
limit: limit,
read: readType,
accepted: accepted,
}
return db.activityCenterNotifications(params)
}
func (db sqlitePersistence) UnreadAndAcceptedActivityCenterNotificationsCount(activityTypes []ActivityCenterType) (uint64, error) {
var count uint64
err := db.buildActivityCenterNotificationsCountQuery(true, ActivityCenterQueryParamsReadUnread, activityTypes).Scan(&count)
return count, err
}
func (db sqlitePersistence) ActivityCenterNotificationsCountBy(activityTypes []ActivityCenterType, readType ActivityCenterQueryParamsRead, accepted bool) (uint64, error) {
func (db sqlitePersistence) ActivityCenterNotificationsCount(activityTypes []ActivityCenterType, readType ActivityCenterQueryParamsRead, accepted bool) (uint64, error) {
var count uint64
err := db.buildActivityCenterNotificationsCountQuery(accepted, readType, activityTypes).Scan(&count)
return count, err

View File

@ -52,13 +52,13 @@ func TestDeleteActivityCenterNotificationsWhenEmpty(t *testing.T) {
})
var count uint64
count, _ = p.UnreadActivityCenterNotificationsCount()
count, _ = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
require.Equal(t, uint64(1), count)
err = p.DeleteActivityCenterNotifications([]types.HexBytes{})
require.NoError(t, err)
count, _ = p.UnreadActivityCenterNotificationsCount()
count, _ = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
require.Equal(t, uint64(1), count)
}
@ -81,13 +81,13 @@ func TestDeleteActivityCenterNotificationsWithMultipleIds(t *testing.T) {
})
var count uint64
count, _ = p.UnreadActivityCenterNotificationsCount()
count, _ = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
require.Equal(t, uint64(3), count)
err = p.DeleteActivityCenterNotifications([]types.HexBytes{notifications[1].ID, notifications[2].ID})
require.NoError(t, err)
count, _ = p.UnreadActivityCenterNotificationsCount()
count, _ = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
require.Equal(t, uint64(1), count)
}
@ -651,7 +651,7 @@ func TestUnreadActivityCenterNotificationsCount(t *testing.T) {
})
// Test: Ignore soft deleted and accepted.
count, err := p.UnreadActivityCenterNotificationsCount()
count, err := p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, true)
require.NoError(t, err)
require.Equal(t, uint64(3), count)
}
@ -670,16 +670,14 @@ func TestUnreadAndAcceptedActivityCenterNotificationsCount(t *testing.T) {
})
// Test: counts everything, except soft deleted notifications.
count, err := p.UnreadAndAcceptedActivityCenterNotificationsCount([]ActivityCenterType{})
count, err := p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, true)
require.NoError(t, err)
require.Equal(t, uint64(3), count)
// Test: counts everything, except soft deleted ones and limit by type.
count, err = p.UnreadAndAcceptedActivityCenterNotificationsCount(
[]ActivityCenterType{
ActivityCenterNotificationTypeContactRequest,
},
)
count, err = p.ActivityCenterNotificationsCount([]ActivityCenterType{
ActivityCenterNotificationTypeContactRequest,
}, ActivityCenterQueryParamsReadUnread, true)
require.NoError(t, err)
require.Equal(t, uint64(1), count)
}
@ -710,7 +708,7 @@ func TestActivityCenterPersistence(t *testing.T) {
err = p.SaveActivityCenterNotification(notification)
require.NoError(t, err)
cursor, notifications, err := p.ActivityCenterNotifications("", 2)
cursor, notifications, err := p.ActivityCenterNotifications("", 2, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
require.NoError(t, err)
require.Empty(t, cursor)
require.Len(t, notifications, 1)
@ -727,7 +725,7 @@ func TestActivityCenterPersistence(t *testing.T) {
err = p.SaveActivityCenterNotification(notification)
require.NoError(t, err)
cursor, notifications, err = p.ActivityCenterNotifications("", 1)
cursor, notifications, err = p.ActivityCenterNotifications("", 1, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
require.NoError(t, err)
require.Len(t, notifications, 1)
require.NotEmpty(t, cursor)
@ -735,7 +733,7 @@ func TestActivityCenterPersistence(t *testing.T) {
// fetch next pagination
cursor, notifications, err = p.ActivityCenterNotifications(cursor, 1)
cursor, notifications, err = p.ActivityCenterNotifications(cursor, 1, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
require.NoError(t, err)
require.Len(t, notifications, 1)
require.Empty(t, cursor)
@ -743,25 +741,25 @@ func TestActivityCenterPersistence(t *testing.T) {
require.Equal(t, nID1, notifications[0].ID)
// Check count
count, err := p.UnreadActivityCenterNotificationsCount()
count, err := p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
require.NoError(t, err)
require.Equal(t, uint64(2), count)
// Mark first one as read
require.NoError(t, p.MarkActivityCenterNotificationsRead([]types.HexBytes{nID1}))
count, err = p.UnreadActivityCenterNotificationsCount()
count, err = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
require.NoError(t, err)
require.Equal(t, uint64(1), count)
// Mark first one as unread
require.NoError(t, p.MarkActivityCenterNotificationsUnread([]types.HexBytes{nID1}))
count, err = p.UnreadActivityCenterNotificationsCount()
count, err = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
require.NoError(t, err)
require.Equal(t, uint64(2), count)
// Mark all read
require.NoError(t, p.MarkAllActivityCenterNotificationsRead())
_, notifications, err = p.ActivityCenterNotifications(cursor, 2)
_, notifications, err = p.ActivityCenterNotifications(cursor, 2, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
require.NoError(t, err)
require.Len(t, notifications, 2)
require.Empty(t, cursor)
@ -769,7 +767,7 @@ func TestActivityCenterPersistence(t *testing.T) {
require.True(t, notifications[1].Read)
// Check count
count, err = p.UnreadActivityCenterNotificationsCount()
count, err = p.ActivityCenterNotificationsCount([]ActivityCenterType{}, ActivityCenterQueryParamsReadUnread, false)
require.NoError(t, err)
require.Equal(t, uint64(0), count)
@ -778,14 +776,14 @@ func TestActivityCenterPersistence(t *testing.T) {
notifications, err = p.AcceptActivityCenterNotifications([]types.HexBytes{nID1})
require.NoError(t, err)
require.Len(t, notifications, 1)
_, notifications, err = p.ActivityCenterNotifications("", 2)
_, notifications, err = p.ActivityCenterNotifications("", 2, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
require.NoError(t, err)
// It should not be returned anymore
require.Len(t, notifications, 1)
// Mark last one as dismissed
require.NoError(t, p.DismissActivityCenterNotifications([]types.HexBytes{nID2}))
_, notifications, err = p.ActivityCenterNotifications("", 2)
_, notifications, err = p.ActivityCenterNotifications("", 2, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
require.NoError(t, err)
require.Len(t, notifications, 1)
@ -805,7 +803,7 @@ func TestActivityCenterPersistence(t *testing.T) {
require.NoError(t, err)
require.Len(t, notifications, 2)
_, notifications, err = p.ActivityCenterNotifications("", 2)
_, notifications, err = p.ActivityCenterNotifications("", 2, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
require.NoError(t, err)
require.Len(t, notifications, 1)
@ -821,7 +819,7 @@ func TestActivityCenterPersistence(t *testing.T) {
// Mark all as dismissed
require.NoError(t, p.DismissAllActivityCenterNotifications())
_, notifications, err = p.ActivityCenterNotifications("", 2)
_, notifications, err = p.ActivityCenterNotifications("", 2, []ActivityCenterType{}, ActivityCenterQueryParamsReadAll, false)
require.NoError(t, err)
require.Len(t, notifications, 2)
@ -894,10 +892,12 @@ func TestActivityCenterReadUnreadPagination(t *testing.T) {
require.NoError(t, err)
// Fetch UNREAD notifications, first page.
cursor, notifications, err := p.UnreadActivityCenterNotifications(
cursor, notifications, err := p.ActivityCenterNotifications(
initialOrFinalCursor,
1,
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
ActivityCenterQueryParamsReadUnread,
false,
)
require.NoError(t, err)
require.Len(t, notifications, 1)
@ -905,20 +905,24 @@ func TestActivityCenterReadUnreadPagination(t *testing.T) {
require.NotEmpty(t, cursor)
// Fetch next pages.
cursor, notifications, err = p.UnreadActivityCenterNotifications(
cursor, notifications, err = p.ActivityCenterNotifications(
cursor,
1,
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
ActivityCenterQueryParamsReadUnread,
false,
)
require.NoError(t, err)
require.Len(t, notifications, 1)
require.Equal(t, nID3, notifications[0].ID)
require.NotEmpty(t, cursor)
cursor, notifications, err = p.UnreadActivityCenterNotifications(
cursor, notifications, err = p.ActivityCenterNotifications(
cursor,
1,
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
ActivityCenterQueryParamsReadUnread,
false,
)
require.NoError(t, err)
require.Len(t, notifications, 1)
@ -926,10 +930,12 @@ func TestActivityCenterReadUnreadPagination(t *testing.T) {
require.Empty(t, cursor)
// Fetch READ notifications, first page.
cursor, notifications, err = p.ReadActivityCenterNotifications(
cursor, notifications, err = p.ActivityCenterNotifications(
initialOrFinalCursor,
1,
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
ActivityCenterQueryParamsReadRead,
false,
)
require.NoError(t, err)
require.Len(t, notifications, 1)
@ -937,10 +943,12 @@ func TestActivityCenterReadUnreadPagination(t *testing.T) {
require.NotEmpty(t, cursor)
// Fetch next page.
cursor, notifications, err = p.ReadActivityCenterNotifications(
cursor, notifications, err = p.ActivityCenterNotifications(
cursor,
1,
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
ActivityCenterQueryParamsReadRead,
false,
)
require.NoError(t, err)
require.Len(t, notifications, 1)
@ -994,10 +1002,12 @@ func TestActivityCenterReadUnreadFilterByTypes(t *testing.T) {
}
// Don't filter by type if the array of types is empty.
_, notifications, err := p.UnreadActivityCenterNotifications(
_, notifications, err := p.ActivityCenterNotifications(
initialCursor,
limit,
[]ActivityCenterType{},
ActivityCenterQueryParamsReadUnread,
false,
)
require.NoError(t, err)
require.Len(t, notifications, 3)
@ -1005,29 +1015,35 @@ func TestActivityCenterReadUnreadFilterByTypes(t *testing.T) {
require.Equal(t, nID2, notifications[1].ID)
require.Equal(t, nID1, notifications[2].ID)
_, notifications, err = p.UnreadActivityCenterNotifications(
_, notifications, err = p.ActivityCenterNotifications(
initialCursor,
limit,
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
ActivityCenterQueryParamsReadUnread,
false,
)
require.NoError(t, err)
require.Len(t, notifications, 1)
require.Equal(t, nID2, notifications[0].ID)
_, notifications, err = p.UnreadActivityCenterNotifications(
_, notifications, err = p.ActivityCenterNotifications(
initialCursor,
limit,
[]ActivityCenterType{ActivityCenterNotificationTypeMention},
ActivityCenterQueryParamsReadUnread,
false,
)
require.NoError(t, err)
require.Len(t, notifications, 2)
require.Equal(t, nID3, notifications[0].ID)
require.Equal(t, nID1, notifications[1].ID)
_, notifications, err = p.UnreadActivityCenterNotifications(
_, notifications, err = p.ActivityCenterNotifications(
initialCursor,
limit,
[]ActivityCenterType{ActivityCenterNotificationTypeMention, ActivityCenterNotificationTypeNewOneToOne},
ActivityCenterQueryParamsReadUnread,
false,
)
require.NoError(t, err)
require.Len(t, notifications, 3)
@ -1041,19 +1057,23 @@ func TestActivityCenterReadUnreadFilterByTypes(t *testing.T) {
require.NoError(t, err)
}
_, notifications, err = p.ReadActivityCenterNotifications(
_, notifications, err = p.ActivityCenterNotifications(
initialCursor,
limit,
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
ActivityCenterQueryParamsReadRead,
false,
)
require.NoError(t, err)
require.Len(t, notifications, 1)
require.Equal(t, nID2, notifications[0].ID)
_, notifications, err = p.ReadActivityCenterNotifications(
_, notifications, err = p.ActivityCenterNotifications(
initialCursor,
limit,
[]ActivityCenterType{ActivityCenterNotificationTypeMention},
ActivityCenterQueryParamsReadRead,
false,
)
require.NoError(t, err)
require.Len(t, notifications, 2)
@ -1100,20 +1120,24 @@ func TestActivityCenterReadUnread(t *testing.T) {
err = p.MarkActivityCenterNotificationsRead([]types.HexBytes{nID2})
require.NoError(t, err)
cursor, notifications, err := p.UnreadActivityCenterNotifications(
cursor, notifications, err := p.ActivityCenterNotifications(
"",
2,
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
ActivityCenterQueryParamsReadUnread,
false,
)
require.NoError(t, err)
require.Empty(t, cursor)
require.Len(t, notifications, 1)
require.Equal(t, nID1, notifications[0].ID)
cursor, notifications, err = p.ReadActivityCenterNotifications(
cursor, notifications, err = p.ActivityCenterNotifications(
"",
2,
[]ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne},
ActivityCenterQueryParamsReadRead,
false,
)
require.NoError(t, err)
require.Empty(t, cursor)

View File

@ -12,22 +12,6 @@ import (
"github.com/status-im/status-go/protocol/protobuf"
)
func (m *Messenger) UnreadActivityCenterNotificationsCount() (uint64, error) {
return m.persistence.UnreadActivityCenterNotificationsCount()
}
func (m *Messenger) UnreadAndAcceptedActivityCenterNotificationsCount(activityTypes []ActivityCenterType) (uint64, error) {
return m.persistence.UnreadAndAcceptedActivityCenterNotificationsCount(activityTypes)
}
func (m *Messenger) HasUnseenActivityCenterNotifications() (bool, error) {
return m.persistence.HasUnseenActivityCenterNotifications()
}
func (m *Messenger) GetActivityCenterState() (*ActivityCenterState, error) {
return m.persistence.GetActivityCenterState()
}
func toHexBytes(b [][]byte) []types.HexBytes {
hb := make([]types.HexBytes, len(b))
@ -48,6 +32,41 @@ func fromHexBytes(hb []types.HexBytes) [][]byte {
return b
}
func (m *Messenger) ActivityCenterNotifications(request ActivityCenterNotificationsRequest) (*ActivityCenterPaginationResponse, error) {
cursor, notifications, err := m.persistence.ActivityCenterNotifications(request.Cursor, request.Limit, request.ActivityTypes, request.ReadType, true)
if err != nil {
return nil, err
}
return &ActivityCenterPaginationResponse{
Cursor: cursor,
Notifications: notifications,
}, nil
}
func (m *Messenger) ActivityCenterNotificationsCount(request ActivityCenterCountRequest) (*ActivityCenterCountResponse, error) {
response := make(ActivityCenterCountResponse)
for _, activityType := range request.ActivityTypes {
count, err := m.persistence.ActivityCenterNotificationsCount([]ActivityCenterType{activityType}, request.ReadType, true)
if err != nil {
return nil, err
}
response[activityType] = count
}
return &response, nil
}
func (m *Messenger) HasUnseenActivityCenterNotifications() (bool, error) {
return m.persistence.HasUnseenActivityCenterNotifications()
}
func (m *Messenger) GetActivityCenterState() (*ActivityCenterState, error) {
return m.persistence.GetActivityCenterState()
}
func (m *Messenger) MarkAsSeenActivityCenterNotifications() (*MessengerResponse, error) {
response := &MessengerResponse{}
err := m.persistence.MarkAsSeenActivityCenterNotifications()
@ -278,58 +297,6 @@ func (m *Messenger) ActivityCenterNotification(id types.HexBytes) (*ActivityCent
return m.persistence.GetActivityCenterNotificationByID(id)
}
func (m *Messenger) ActivityCenterNotifications(cursor string, limit uint64) (*ActivityCenterPaginationResponse, error) {
cursor, notifications, err := m.persistence.ActivityCenterNotifications(cursor, limit)
if err != nil {
return nil, err
}
return &ActivityCenterPaginationResponse{
Cursor: cursor,
Notifications: notifications,
}, nil
}
func (m *Messenger) ReadActivityCenterNotifications(cursor string, limit uint64, activityTypes []ActivityCenterType) (*ActivityCenterPaginationResponse, error) {
cursor, notifications, err := m.persistence.ReadActivityCenterNotifications(cursor, limit, activityTypes)
if err != nil {
return nil, err
}
return &ActivityCenterPaginationResponse{
Cursor: cursor,
Notifications: notifications,
}, nil
}
func (m *Messenger) UnreadActivityCenterNotifications(cursor string, limit uint64, activityTypes []ActivityCenterType) (*ActivityCenterPaginationResponse, error) {
cursor, notifications, err := m.persistence.UnreadActivityCenterNotifications(cursor, limit, activityTypes)
if err != nil {
return nil, err
}
return &ActivityCenterPaginationResponse{
Cursor: cursor,
Notifications: notifications,
}, nil
}
func (m *Messenger) ActivityCenterNotificationsBy(cursor string, limit uint64, activityTypes []ActivityCenterType, readType ActivityCenterQueryParamsRead, accepted bool) (*ActivityCenterPaginationResponse, error) {
cursor, notifications, err := m.persistence.ActivityCenterNotificationsBy(cursor, limit, activityTypes, readType, accepted)
if err != nil {
return nil, err
}
return &ActivityCenterPaginationResponse{
Cursor: cursor,
Notifications: notifications,
}, nil
}
func (m *Messenger) ActivityCenterNotificationsCountBy(activityTypes []ActivityCenterType, readType ActivityCenterQueryParamsRead, accepted bool) (uint64, error) {
return m.persistence.ActivityCenterNotificationsCountBy(activityTypes, readType, accepted)
}
func (m *Messenger) handleActivityCenterRead(state *ReceivedMessageState, message protobuf.SyncActivityCenterRead) error {
resp, err := m.MarkActivityCenterNotificationsRead(context.TODO(), toHexBytes(message.Ids), false)

View File

@ -116,7 +116,13 @@ func (s *MessengerContactRequestSuite) TestReceiveAndAcceptContactRequest() { //
s.Require().Equal(common.ContactRequestStatePending, resp.Messages()[0].ContactRequestState)
notifications, err := theirMessenger.ActivityCenterNotifications("", 10)
notifications, err := theirMessenger.ActivityCenterNotifications(ActivityCenterNotificationsRequest{
Cursor: "",
Limit: 10,
ActivityTypes: []ActivityCenterType{},
ReadType: ActivityCenterQueryParamsReadUnread,
},
)
s.Require().NoError(err)
s.Require().Len(notifications.Notifications, 1)

View File

@ -691,10 +691,13 @@ func (s *MessengerVerificationRequests) TestCancelVerificationRequest() {
s.Require().Equal(common.ContactVerificationStatePending, resp.Messages()[0].ContactVerificationState)
// Make sure it's stored and retrieved correctly
notifications, err := theirMessenger.UnreadActivityCenterNotifications(
"",
4,
[]ActivityCenterType{ActivityCenterNotificationTypeContactVerification},
notifications, err := theirMessenger.ActivityCenterNotifications(
ActivityCenterNotificationsRequest{
Cursor: "",
Limit: 4,
ActivityTypes: []ActivityCenterType{ActivityCenterNotificationTypeContactVerification},
ReadType: ActivityCenterQueryParamsReadUnread,
},
)
s.Require().NoError(err)
s.Require().Greater(len(notifications.Notifications), 0)

View File

@ -1090,14 +1090,12 @@ func (api *PublicAPI) RequestCommunityInfoFromMailserverAsync(communityID string
return api.service.messenger.RequestCommunityInfoFromMailserverAsync(communityID)
}
func (api *PublicAPI) UnreadActivityCenterNotificationsCount() (uint64, error) {
return api.service.messenger.UnreadActivityCenterNotificationsCount()
func (api *PublicAPI) ActivityCenterNotifications(request protocol.ActivityCenterNotificationsRequest) (*protocol.ActivityCenterPaginationResponse, error) {
return api.service.messenger.ActivityCenterNotifications(request)
}
// UnreadAndAcceptedActivityCenterNotificationsCount is a temporary endpoint to
// support the mobile client needs.
func (api *PublicAPI) UnreadAndAcceptedActivityCenterNotificationsCount(activityTypes []protocol.ActivityCenterType) (uint64, error) {
return api.service.messenger.UnreadAndAcceptedActivityCenterNotificationsCount(activityTypes)
func (api *PublicAPI) ActivityCenterNotificationsCount(request protocol.ActivityCenterCountRequest) (*protocol.ActivityCenterCountResponse, error) {
return api.service.messenger.ActivityCenterNotificationsCount(request)
}
func (api *PublicAPI) HasUnseenActivityCenterNotifications() (bool, error) {
@ -1137,26 +1135,6 @@ func (api *PublicAPI) DeleteActivityCenterNotifications(ctx context.Context, ids
return api.service.messenger.DeleteActivityCenterNotifications(ctx, ids, false)
}
func (api *PublicAPI) ActivityCenterNotifications(cursor string, limit uint64) (*protocol.ActivityCenterPaginationResponse, error) {
return api.service.messenger.ActivityCenterNotifications(cursor, limit)
}
func (api *PublicAPI) ReadActivityCenterNotifications(cursor string, limit uint64, activityType protocol.ActivityCenterType) (*protocol.ActivityCenterPaginationResponse, error) {
return api.service.messenger.ReadActivityCenterNotifications(cursor, limit, []protocol.ActivityCenterType{activityType})
}
func (api *PublicAPI) UnreadActivityCenterNotifications(cursor string, limit uint64, activityType protocol.ActivityCenterType) (*protocol.ActivityCenterPaginationResponse, error) {
return api.service.messenger.UnreadActivityCenterNotifications(cursor, limit, []protocol.ActivityCenterType{activityType})
}
func (api *PublicAPI) ActivityCenterNotificationsBy(cursor string, limit uint64, activityTypes []protocol.ActivityCenterType, readType protocol.ActivityCenterQueryParamsRead, accepted bool) (*protocol.ActivityCenterPaginationResponse, error) {
return api.service.messenger.ActivityCenterNotificationsBy(cursor, limit, activityTypes, readType, accepted)
}
func (api *PublicAPI) ActivityCenterNotificationsCountBy(activityTypes []protocol.ActivityCenterType, readType protocol.ActivityCenterQueryParamsRead, accepted bool) (uint64, error) {
return api.service.messenger.ActivityCenterNotificationsCountBy(activityTypes, readType, accepted)
}
func (api *PublicAPI) RequestAllHistoricMessages() (*protocol.MessengerResponse, error) {
return api.service.messenger.RequestAllHistoricMessages()
}