From e40cbfc28f6195b31eb0f59cbd58fd1d77a12821 Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Fri, 20 Jan 2023 09:45:32 -0300 Subject: [PATCH] feat: Support fetching accepted Activity Center notifications by multiple types (#3088) Summary ======= - [x] Changes endpoint ActivityCenterNotificationsBy to support fetching multiple types of notification in a single query. - [x] Adds endpoint UnreadAndAcceptedActivityCenterNotificationsCount to allow the mobile client to fetch the count of unread & accepted notifications. - [x] Add `golangci-lint` to Nix shell. This was possible since PR https://github.com/status-im/status-go/pull/3087 was merged. Notes ===== - If you'd like to understand why these changes are needed, please see the mobile PR https://github.com/status-im/status-mobile/pull/14785, or issue https://github.com/status-im/status-mobile/issues/14712 - All changes should be completely backwards compatible, and there should be no impact for the desktop app. - The mobile client has been already tested using this branch. --- VERSION | 2 +- protocol/activity_center_persistence.go | 247 ++++++++++-------- protocol/messenger_activity_center.go | 16 +- protocol/messenger_communities.go | 5 +- .../messenger_contact_verification_test.go | 18 +- protocol/persistence_test.go | 91 ++++++- services/ens/api.go | 4 +- services/ext/api.go | 12 +- shell.nix | 2 +- 9 files changed, 252 insertions(+), 145 deletions(-) diff --git a/VERSION b/VERSION index ee476f3ae..b1fa68e5d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.124.0 +0.125.0 diff --git a/protocol/activity_center_persistence.go b/protocol/activity_center_persistence.go index ac3c2ff70..b077fe451 100644 --- a/protocol/activity_center_persistence.go +++ b/protocol/activity_center_persistence.go @@ -36,8 +36,7 @@ func (db sqlitePersistence) DeleteActivityCenterNotificationForMessage(chatID st }() params := activityCenterQueryParams{ - chatID: chatID, - activityCenterType: ActivityCenterNotificationNoType, + chatID: chatID, } _, notifications, err := db.buildActivityCenterQuery(tx, params) @@ -294,27 +293,29 @@ const ( ) type activityCenterQueryParams struct { - cursor string - limit uint64 - ids []types.HexBytes - chatID string - author string - read ActivityCenterQueryParamsRead - activityCenterType ActivityCenterType + cursor string + limit uint64 + ids []types.HexBytes + chatID string + author string + read ActivityCenterQueryParamsRead + accepted bool + activityCenterTypes []ActivityCenterType } func (db sqlitePersistence) buildActivityCenterQuery(tx *sql.Tx, params activityCenterQueryParams) (string, []*ActivityCenterNotification, error) { var args []interface{} - var cursorWhere, inQueryWhere, inChatWhere, fromAuthorWhere, ofTypeWhere, readWhere string + var cursorWhere, inQueryWhere, inChatWhere, fromAuthorWhere, inTypeWhere, readWhere, acceptedWhere string cursor := params.cursor ids := params.ids author := params.author - activityCenterType := params.activityCenterType + activityCenterTypes := params.activityCenterTypes limit := params.limit chatID := params.chatID read := params.read + accepted := params.accepted if cursor != "" { cursorWhere = "AND cursor <= ?" //nolint: goconst @@ -322,13 +323,11 @@ func (db sqlitePersistence) buildActivityCenterQuery(tx *sql.Tx, params activity } if len(ids) != 0 { - inVector := strings.Repeat("?, ", len(ids)-1) + "?" inQueryWhere = fmt.Sprintf(" AND a.id IN (%s)", inVector) for _, id := range ids { args = append(args, id) } - } switch read { @@ -338,52 +337,60 @@ func (db sqlitePersistence) buildActivityCenterQuery(tx *sql.Tx, params activity readWhere = "AND NOT(a.read)" } + if !accepted { + acceptedWhere = "AND NOT a.accepted" + } + if chatID != "" { inChatWhere = "AND a.chat_id = ?" //nolint: goconst args = append(args, chatID) } if author != "" { - fromAuthorWhere = " AND author = ?" + fromAuthorWhere = " AND a.author = ?" args = append(args, author) } - if activityCenterType != ActivityCenterNotificationNoType { - ofTypeWhere = " AND notification_type = ?" - args = append(args, activityCenterType) + if len(activityCenterTypes) != 0 { + inVector := strings.Repeat("?, ", len(activityCenterTypes)-1) + "?" + inTypeWhere = fmt.Sprintf(" AND a.notification_type IN (%s)", inVector) + for _, activityCenterType := range activityCenterTypes { + args = append(args, activityCenterType) + } } query := fmt.Sprintf( // nolint: gosec ` - SELECT - a.id, - a.timestamp, - a.notification_type, - a.chat_id, - a.community_id, - a.membership_status, - a.read, - a.accepted, - a.dismissed, - a.message, - c.last_message, - a.reply_message, - a.contact_verification_status, - c.name, - a.author, - substr('0000000000000000000000000000000000000000000000000000000000000000' || a.timestamp, -64, 64) || a.id as cursor - FROM activity_center_notifications a - LEFT JOIN chats c - ON - c.id = a.chat_id - WHERE NOT a.dismissed AND NOT a.accepted - %s - %s - %s - %s - %s - %s - ORDER BY cursor DESC`, cursorWhere, inQueryWhere, inChatWhere, fromAuthorWhere, ofTypeWhere, readWhere) + SELECT + a.id, + a.timestamp, + a.notification_type, + a.chat_id, + a.community_id, + a.membership_status, + a.read, + a.accepted, + a.dismissed, + a.message, + c.last_message, + a.reply_message, + a.contact_verification_status, + c.name, + a.author, + substr('0000000000000000000000000000000000000000000000000000000000000000' || a.timestamp, -64, 64) || a.id as cursor + FROM activity_center_notifications a + LEFT JOIN chats c + ON + c.id = a.chat_id + WHERE NOT a.dismissed + %s + %s + %s + %s + %s + %s + %s + ORDER BY cursor DESC`, cursorWhere, inQueryWhere, inChatWhere, fromAuthorWhere, inTypeWhere, readWhere, acceptedWhere) if limit != 0 { args = append(args, limit) @@ -475,27 +482,27 @@ func (db sqlitePersistence) GetActivityCenterNotificationsByID(ids []types.HexBy func (db sqlitePersistence) GetActivityCenterNotificationByID(id types.HexBytes) (*ActivityCenterNotification, error) { row := db.db.QueryRow(` - SELECT - a.id, - a.timestamp, - a.notification_type, - a.chat_id, - a.community_id, - a.membership_status, - a.read, - a.accepted, - a.dismissed, - a.message, - c.last_message, - a.reply_message, - a.contact_verification_status, - c.name, - a.author - FROM activity_center_notifications a - LEFT JOIN chats c - ON - c.id = a.chat_id - WHERE a.id = ?`, id) + SELECT + a.id, + a.timestamp, + a.notification_type, + a.chat_id, + a.community_id, + a.membership_status, + a.read, + a.accepted, + a.dismissed, + a.message, + c.last_message, + a.reply_message, + a.contact_verification_status, + c.name, + a.author + FROM activity_center_notifications a + LEFT JOIN chats c + ON + c.id = a.chat_id + WHERE a.id = ?`, id) notification, err := db.unmarshalActivityCenterNotificationRow(row) if err == sql.ErrNoRows { @@ -504,34 +511,35 @@ func (db sqlitePersistence) GetActivityCenterNotificationByID(id types.HexBytes) return notification, err } -func (db sqlitePersistence) UnreadActivityCenterNotifications(cursor string, limit uint64, activityType ActivityCenterType) (string, []*ActivityCenterNotification, error) { +func (db sqlitePersistence) UnreadActivityCenterNotifications(cursor string, limit uint64, activityTypes []ActivityCenterType) (string, []*ActivityCenterNotification, error) { params := activityCenterQueryParams{ - activityCenterType: activityType, - cursor: cursor, - limit: limit, - read: ActivityCenterQueryParamsReadUnread, + activityCenterTypes: activityTypes, + cursor: cursor, + limit: limit, + read: ActivityCenterQueryParamsReadUnread, } return db.activityCenterNotifications(params) } -func (db sqlitePersistence) ReadActivityCenterNotifications(cursor string, limit uint64, activityType ActivityCenterType) (string, []*ActivityCenterNotification, error) { +func (db sqlitePersistence) ReadActivityCenterNotifications(cursor string, limit uint64, activityTypes []ActivityCenterType) (string, []*ActivityCenterNotification, error) { params := activityCenterQueryParams{ - activityCenterType: activityType, - cursor: cursor, - limit: limit, - read: ActivityCenterQueryParamsReadRead, + activityCenterTypes: activityTypes, + cursor: cursor, + limit: limit, + read: ActivityCenterQueryParamsReadRead, } return db.activityCenterNotifications(params) } -func (db sqlitePersistence) ActivityCenterNotificationsBy(cursor string, limit uint64, activityType ActivityCenterType, readType ActivityCenterQueryParamsRead) (string, []*ActivityCenterNotification, error) { +func (db sqlitePersistence) ActivityCenterNotificationsBy(cursor string, limit uint64, activityTypes []ActivityCenterType, readType ActivityCenterQueryParamsRead, accepted bool) (string, []*ActivityCenterNotification, error) { params := activityCenterQueryParams{ - activityCenterType: activityType, - cursor: cursor, - limit: limit, - read: readType, + activityCenterTypes: activityTypes, + cursor: cursor, + limit: limit, + read: readType, + accepted: accepted, } return db.activityCenterNotifications(params) @@ -657,11 +665,7 @@ func (db sqlitePersistence) AcceptAllActivityCenterNotifications() ([]*ActivityC _ = tx.Rollback() }() - params := activityCenterQueryParams{ - activityCenterType: ActivityCenterNotificationNoType, - } - - _, notifications, err := db.buildActivityCenterQuery(tx, params) + _, notifications, err := db.buildActivityCenterQuery(tx, activityCenterQueryParams{}) _, err = tx.Exec(`UPDATE activity_center_notifications SET read = 1, accepted = 1 WHERE NOT accepted AND NOT dismissed`) if err != nil { @@ -689,8 +693,7 @@ func (db sqlitePersistence) AcceptActivityCenterNotifications(ids []types.HexByt }() params := activityCenterQueryParams{ - ids: ids, - activityCenterType: ActivityCenterNotificationNoType, + ids: ids, } _, notifications, err := db.buildActivityCenterQuery(tx, params) @@ -761,8 +764,8 @@ func (db sqlitePersistence) AcceptActivityCenterNotificationsForInvitesFromUser( }() params := activityCenterQueryParams{ - author: userPublicKey, - activityCenterType: ActivityCenterNotificationTypeNewPrivateGroupChat, + author: userPublicKey, + activityCenterTypes: []ActivityCenterType{ActivityCenterNotificationTypeNewPrivateGroupChat}, } _, notifications, err := db.buildActivityCenterQuery(tx, params) @@ -813,35 +816,53 @@ func (db sqlitePersistence) MarkActivityCenterNotificationsUnread(ids []types.He } +func buildActivityCenterNotificationsCountQuery(isAccepted bool) string { + var acceptedWhere string + + if !isAccepted { + acceptedWhere = `AND NOT accepted` + } + + return fmt.Sprintf(`SELECT COUNT(1) FROM activity_center_notifications WHERE NOT read AND NOT dismissed %s`, acceptedWhere) +} + func (db sqlitePersistence) UnreadActivityCenterNotificationsCount() (uint64, error) { var count uint64 - err := db.db.QueryRow(`SELECT COUNT(1) FROM activity_center_notifications WHERE NOT read AND NOT dismissed AND NOT accepted`).Scan(&count) + query := buildActivityCenterNotificationsCountQuery(false) + err := db.db.QueryRow(query).Scan(&count) + return count, err +} + +func (db sqlitePersistence) UnreadAndAcceptedActivityCenterNotificationsCount() (uint64, error) { + var count uint64 + query := buildActivityCenterNotificationsCountQuery(true) + err := db.db.QueryRow(query).Scan(&count) return count, err } func (db sqlitePersistence) ActiveContactRequestNotification(contactID string) (*ActivityCenterNotification, error) { row := db.db.QueryRow(` - SELECT - a.id, - a.timestamp, - a.notification_type, - a.chat_id, - a.community_id, - a.membership_status, - a.read, - a.accepted, - a.dismissed, - a.message, - c.last_message, - a.reply_message, - a.contact_verification_status, - c.name, - a.author - FROM activity_center_notifications a - LEFT JOIN chats c - ON - c.id = a.chat_id - WHERE NOT dismissed AND NOT a.accepted AND notification_type = ? AND author = ?`, ActivityCenterNotificationTypeContactRequest, contactID) + SELECT + a.id, + a.timestamp, + a.notification_type, + a.chat_id, + a.community_id, + a.membership_status, + a.read, + a.accepted, + a.dismissed, + a.message, + c.last_message, + a.reply_message, + a.contact_verification_status, + c.name, + a.author + FROM activity_center_notifications a + LEFT JOIN chats c + ON + c.id = a.chat_id + WHERE NOT dismissed AND NOT a.accepted AND notification_type = ? AND author = ?`, ActivityCenterNotificationTypeContactRequest, contactID) notification, err := db.unmarshalActivityCenterNotificationRow(row) if err == sql.ErrNoRows { return nil, nil diff --git a/protocol/messenger_activity_center.go b/protocol/messenger_activity_center.go index 75bda8fd8..cd2eedf73 100644 --- a/protocol/messenger_activity_center.go +++ b/protocol/messenger_activity_center.go @@ -16,6 +16,10 @@ func (m *Messenger) UnreadActivityCenterNotificationsCount() (uint64, error) { return m.persistence.UnreadActivityCenterNotificationsCount() } +func (m *Messenger) UnreadAndAcceptedActivityCenterNotificationsCount() (uint64, error) { + return m.persistence.UnreadAndAcceptedActivityCenterNotificationsCount() +} + func toHexBytes(b [][]byte) []types.HexBytes { hb := make([]types.HexBytes, len(b)) @@ -243,8 +247,8 @@ func (m *Messenger) ActivityCenterNotifications(cursor string, limit uint64) (*A }, nil } -func (m *Messenger) ReadActivityCenterNotifications(cursor string, limit uint64, activityType ActivityCenterType) (*ActivityCenterPaginationResponse, error) { - cursor, notifications, err := m.persistence.ReadActivityCenterNotifications(cursor, limit, activityType) +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 } @@ -255,8 +259,8 @@ func (m *Messenger) ReadActivityCenterNotifications(cursor string, limit uint64, }, nil } -func (m *Messenger) UnreadActivityCenterNotifications(cursor string, limit uint64, activityType ActivityCenterType) (*ActivityCenterPaginationResponse, error) { - cursor, notifications, err := m.persistence.UnreadActivityCenterNotifications(cursor, limit, activityType) +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 } @@ -267,8 +271,8 @@ func (m *Messenger) UnreadActivityCenterNotifications(cursor string, limit uint6 }, nil } -func (m *Messenger) ActivityCenterNotificationsBy(cursor string, limit uint64, activityType ActivityCenterType, readType ActivityCenterQueryParamsRead) (*ActivityCenterPaginationResponse, error) { - cursor, notifications, err := m.persistence.ActivityCenterNotificationsBy(cursor, limit, activityType, readType) +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 } diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index f8dc58ce9..95009cd81 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -2005,9 +2005,10 @@ func (m *Messenger) resumeHistoryArchivesImport(communityID types.HexBytes) erro m.communitiesManager.AddHistoryArchiveDownloadTask(communityID.String(), task) + // this wait groups tracks the ongoing task for a particular community + task.Waiter.Add(1) + go func() { - // this wait groups tracks the ongoing task for a particular community - task.Waiter.Add(1) defer func() { task.Waiter.Done() m.communitiesManager.DeleteHistoryArchiveDownloadTask(communityID.String()) diff --git a/protocol/messenger_contact_verification_test.go b/protocol/messenger_contact_verification_test.go index cb22d0987..68da2d9d6 100644 --- a/protocol/messenger_contact_verification_test.go +++ b/protocol/messenger_contact_verification_test.go @@ -535,7 +535,11 @@ func (s *MessengerVerificationRequests) TestDeclineVerificationRequests() { s.Require().Equal(resp.Messages()[0].ContactVerificationState, common.ContactVerificationStatePending) // Make sure it's stored and retrieved correctly - notifications, err := theirMessenger.UnreadActivityCenterNotifications("", 4, ActivityCenterNotificationTypeContactVerification) + notifications, err := theirMessenger.UnreadActivityCenterNotifications( + "", + 4, + []ActivityCenterType{ActivityCenterNotificationTypeContactVerification}, + ) s.Require().NoError(err) s.Require().Len(notifications.Notifications, 1) s.Require().Equal(notifications.Notifications[0].ContactVerificationStatus, verification.RequestStatusPENDING) @@ -561,7 +565,11 @@ func (s *MessengerVerificationRequests) TestDeclineVerificationRequests() { s.Require().Equal(resp.Messages()[0].ContactVerificationState, common.ContactVerificationStateDeclined) // Make sure it's stored and retrieved correctly - notifications, err = theirMessenger.UnreadActivityCenterNotifications("", 4, ActivityCenterNotificationTypeContactVerification) + notifications, err = theirMessenger.UnreadActivityCenterNotifications( + "", + 4, + []ActivityCenterType{ActivityCenterNotificationTypeContactVerification}, + ) s.Require().NoError(err) s.Require().Len(notifications.Notifications, 1) s.Require().Equal(notifications.Notifications[0].ContactVerificationStatus, verification.RequestStatusDECLINED) @@ -629,7 +637,11 @@ 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, ActivityCenterNotificationTypeContactVerification) + notifications, err := theirMessenger.UnreadActivityCenterNotifications( + "", + 4, + []ActivityCenterType{ActivityCenterNotificationTypeContactVerification}, + ) s.Require().NoError(err) s.Require().Len(notifications.Notifications, 1) s.Require().Equal(notifications.Notifications[0].ContactVerificationStatus, verification.RequestStatusPENDING) diff --git a/protocol/persistence_test.go b/protocol/persistence_test.go index 835713249..0c2280997 100644 --- a/protocol/persistence_test.go +++ b/protocol/persistence_test.go @@ -1486,20 +1486,28 @@ func TestActivityCenterReadUnread(t *testing.T) { err = p.MarkActivityCenterNotificationsRead([]types.HexBytes{nID2}) require.NoError(t, err) - cursor, notifications, err := p.UnreadActivityCenterNotifications("", 2, ActivityCenterNotificationTypeNewOneToOne) + cursor, notifications, err := p.UnreadActivityCenterNotifications( + "", + 2, + []ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne}, + ) 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("", 2, ActivityCenterNotificationTypeNewOneToOne) + cursor, notifications, err = p.ReadActivityCenterNotifications( + "", + 2, + []ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne}, + ) require.NoError(t, err) require.Empty(t, cursor) require.Len(t, notifications, 1) require.Equal(t, nID2, notifications[0].ID) } -func TestActivityCenterReadUnreadFilterByType(t *testing.T) { +func TestActivityCenterReadUnreadFilterByTypes(t *testing.T) { db, err := openTestDB() require.NoError(t, err) p := newSQLitePersistence(db) @@ -1544,29 +1552,68 @@ func TestActivityCenterReadUnreadFilterByType(t *testing.T) { require.NoError(t, err) } - _, notifications, err := p.UnreadActivityCenterNotifications(initialCursor, limit, ActivityCenterNotificationTypeNewOneToOne) + // Don't filter by type if the array of types is empty. + _, notifications, err := p.UnreadActivityCenterNotifications( + initialCursor, + limit, + []ActivityCenterType{}, + ) + require.NoError(t, err) + require.Len(t, notifications, 3) + require.Equal(t, nID3, notifications[0].ID) + require.Equal(t, nID2, notifications[1].ID) + require.Equal(t, nID1, notifications[2].ID) + + _, notifications, err = p.UnreadActivityCenterNotifications( + initialCursor, + limit, + []ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne}, + ) require.NoError(t, err) require.Len(t, notifications, 1) require.Equal(t, nID2, notifications[0].ID) - _, notifications, err = p.UnreadActivityCenterNotifications(initialCursor, limit, ActivityCenterNotificationTypeMention) + _, notifications, err = p.UnreadActivityCenterNotifications( + initialCursor, + limit, + []ActivityCenterType{ActivityCenterNotificationTypeMention}, + ) 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( + initialCursor, + limit, + []ActivityCenterType{ActivityCenterNotificationTypeMention, ActivityCenterNotificationTypeNewOneToOne}, + ) + require.NoError(t, err) + require.Len(t, notifications, 3) + require.Equal(t, nID3, notifications[0].ID) + require.Equal(t, nID2, notifications[1].ID) + require.Equal(t, nID1, notifications[2].ID) + // Mark all notifications as read. for _, notification := range allNotifications { err = p.MarkActivityCenterNotificationsRead([]types.HexBytes{notification.ID}) require.NoError(t, err) } - _, notifications, err = p.ReadActivityCenterNotifications(initialCursor, limit, ActivityCenterNotificationTypeNewOneToOne) + _, notifications, err = p.ReadActivityCenterNotifications( + initialCursor, + limit, + []ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne}, + ) require.NoError(t, err) require.Len(t, notifications, 1) require.Equal(t, nID2, notifications[0].ID) - _, notifications, err = p.ReadActivityCenterNotifications(initialCursor, limit, ActivityCenterNotificationTypeMention) + _, notifications, err = p.ReadActivityCenterNotifications( + initialCursor, + limit, + []ActivityCenterType{ActivityCenterNotificationTypeMention}, + ) require.NoError(t, err) require.Len(t, notifications, 2) require.Equal(t, nID3, notifications[0].ID) @@ -1638,34 +1685,54 @@ func TestActivityCenterReadUnreadPagination(t *testing.T) { require.NoError(t, err) // Fetch UNREAD notifications, first page. - cursor, notifications, err := p.UnreadActivityCenterNotifications(initialOrFinalCursor, 1, ActivityCenterNotificationTypeNewOneToOne) + cursor, notifications, err := p.UnreadActivityCenterNotifications( + initialOrFinalCursor, + 1, + []ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne}, + ) require.NoError(t, err) require.Len(t, notifications, 1) require.Equal(t, nID5, notifications[0].ID) require.NotEmpty(t, cursor) // Fetch next pages. - cursor, notifications, err = p.UnreadActivityCenterNotifications(cursor, 1, ActivityCenterNotificationTypeNewOneToOne) + cursor, notifications, err = p.UnreadActivityCenterNotifications( + cursor, + 1, + []ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne}, + ) 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, 1, ActivityCenterNotificationTypeNewOneToOne) + cursor, notifications, err = p.UnreadActivityCenterNotifications( + cursor, + 1, + []ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne}, + ) require.NoError(t, err) require.Len(t, notifications, 1) require.Equal(t, nID1, notifications[0].ID) require.Empty(t, cursor) // Fetch READ notifications, first page. - cursor, notifications, err = p.ReadActivityCenterNotifications(initialOrFinalCursor, 1, ActivityCenterNotificationTypeNewOneToOne) + cursor, notifications, err = p.ReadActivityCenterNotifications( + initialOrFinalCursor, + 1, + []ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne}, + ) require.NoError(t, err) require.Len(t, notifications, 1) require.Equal(t, nID4, notifications[0].ID) require.NotEmpty(t, cursor) // Fetch next page. - cursor, notifications, err = p.ReadActivityCenterNotifications(cursor, 1, ActivityCenterNotificationTypeNewOneToOne) + cursor, notifications, err = p.ReadActivityCenterNotifications( + cursor, + 1, + []ActivityCenterType{ActivityCenterNotificationTypeNewOneToOne}, + ) require.NoError(t, err) require.Len(t, notifications, 1) require.Equal(t, nID2, notifications[0].ID) diff --git a/services/ens/api.go b/services/ens/api.go index 99fa5cf57..559878a4e 100644 --- a/services/ens/api.go +++ b/services/ens/api.go @@ -31,7 +31,6 @@ import ( "github.com/status-im/status-go/contracts/resolver" "github.com/status-im/status-go/contracts/snt" "github.com/status-im/status-go/eth-node/types" - "github.com/status-im/status-go/multiaccounts/accounts" "github.com/status-im/status-go/params" "github.com/status-im/status-go/rpc" "github.com/status-im/status-go/services/rpcfilters" @@ -73,8 +72,7 @@ type API struct { quitOnce sync.Once quit chan struct{} - db *Database - settings *accounts.Database // NOTE: Accounts db is here for compatibility. Remove when settings.usernames is dropped. + db *Database } func (api *API) Stop() { diff --git a/services/ext/api.go b/services/ext/api.go index 86045ad5a..d1beb28fb 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -1082,6 +1082,10 @@ func (api *PublicAPI) UnreadActivityCenterNotificationsCount() (uint64, error) { return api.service.messenger.UnreadActivityCenterNotificationsCount() } +func (api *PublicAPI) UnreadAndAcceptedActivityCenterNotificationsCount() (uint64, error) { + return api.service.messenger.UnreadAndAcceptedActivityCenterNotificationsCount() +} + func (api *PublicAPI) MarkAllActivityCenterNotificationsRead(ctx context.Context) error { return api.service.messenger.MarkAllActivityCenterNotificationsRead(ctx) } @@ -1117,15 +1121,15 @@ func (api *PublicAPI) ActivityCenterNotifications(cursor string, limit uint64) ( } func (api *PublicAPI) ReadActivityCenterNotifications(cursor string, limit uint64, activityType protocol.ActivityCenterType) (*protocol.ActivityCenterPaginationResponse, error) { - return api.service.messenger.ReadActivityCenterNotifications(cursor, limit, activityType) + 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, activityType) + return api.service.messenger.UnreadActivityCenterNotifications(cursor, limit, []protocol.ActivityCenterType{activityType}) } -func (api *PublicAPI) ActivityCenterNotificationsBy(cursor string, limit uint64, activityType protocol.ActivityCenterType, readType protocol.ActivityCenterQueryParamsRead) (*protocol.ActivityCenterPaginationResponse, error) { - return api.service.messenger.ActivityCenterNotificationsBy(cursor, limit, activityType, readType) +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) RequestAllHistoricMessages() (*protocol.MessengerResponse, error) { diff --git a/shell.nix b/shell.nix index 7a8009ff9..624923607 100644 --- a/shell.nix +++ b/shell.nix @@ -34,7 +34,7 @@ pkgs.mkShell { buildInputs = with pkgs; [ git jq which - go_1_18 gopls go-bindata + go_1_18 golangci-lint gopls go-bindata mockgen protobuf3_17 protoc-gen-go (gomobile.override { xcodeWrapperArgs = { version = "13.4.1"; }; }) ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [