π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Send Android sync pushes after manual album sharing
AmanRajSinghMourya610cf2f352b8
diff --git a/server/ente/push.go b/server/ente/push.goindex 390a186680..5f37e022d1 100644--- a/server/ente/push.go+++ b/server/ente/push.go@@ -19,6 +19,7 @@ type PushNotificationRegistration struct {}type PushToken struct {+ Platform string `json:"-"`UserID int64 `json:"userID"`FCMToken string `json:"fcmToken"`CreatedAt int64 `json:"createdAt"`diff --git a/server/pkg/controller/collections/share.go b/server/pkg/controller/collections/share.goindex ab0a4ea6c6..9b9f1e5e80 100644--- a/server/pkg/controller/collections/share.go+++ b/server/pkg/controller/collections/share.go@@ -44,7 +44,7 @@ func (c *CollectionController) Share(ctx *gin.Context, req ente.AlterShareRequesif err := validateShareRecipient(fromUserID, collection.Owner.ID, toUserID); err != nil {return nil, err}- added, err := c.CollectionRepo.Share(+ err = c.CollectionRepo.Share(req.CollectionID,collection.Owner.ID,toUserID,@@ -55,7 +55,7 @@ func (c *CollectionController) Share(ctx *gin.Context, req ente.AlterShareRequesif err != nil {return nil, stacktrace.Propagate(err, "")}- if added && collection.App == string(ente.Photos) {+ if collection.App == string(ente.Photos) {go c.PushCtrl.NotifyAlbumShare(ctx.Request.Context(), []int64{toUserID})}sharees, err := c.GetSharees(ctx, req.CollectionID, fromUserID)@@ -107,7 +107,7 @@ func (c *CollectionController) BatchShare(ctx *gin.Context, shares []ente.AlterS})}- added, err := c.CollectionRepo.BatchShare(+ err = c.CollectionRepo.BatchShare(ctx.Request.Context(),collection.ID,collection.Owner.ID,@@ -117,8 +117,12 @@ func (c *CollectionController) BatchShare(ctx *gin.Context, shares []ente.AlterSif err != nil {return nil, stacktrace.Propagate(err, "")}- if len(added) > 0 && collection.App == string(ente.Photos) {- go c.PushCtrl.NotifyAlbumShare(ctx.Request.Context(), added)+ if collection.App == string(ente.Photos) {+ recipients := make([]int64, len(resolvedShares))+ for i, share := range resolvedShares {+ recipients[i] = share.ToUserID+ }+ go c.PushCtrl.NotifyAlbumShare(ctx.Request.Context(), recipients)}sharees, err := c.GetSharees(ctx, collection.ID, fromUserID)if err != nil {@@ -187,7 +191,7 @@ func (c *CollectionController) BulkShare(notify := falseresults := make([]ente.BulkCollectionShareResult, 0, len(req.Collections))for _, item := range req.Collections {- status, addedShare, err := c.shareCollectionWithUserID(+ status, shouldNotify, err := c.shareCollectionWithUserID(ctx,fromUserID,req.RecipientUserID,@@ -202,7 +206,7 @@ func (c *CollectionController) BulkShare(}).Warn("bulk collection share failed")status = ente.CollectionShareOperationFailed}- notify = notify || (err == nil && addedShare)+ notify = notify || (err == nil && shouldNotify)results = append(results, ente.BulkCollectionShareResult{CollectionID: item.CollectionID,Status: status,@@ -254,7 +258,7 @@ func (c *CollectionController) shareCollectionWithUserID(}updationTime := time.Microseconds()if source == ente.ManualShare {- added, err := c.CollectionRepo.Share(+ err := c.CollectionRepo.Share(item.CollectionID,collection.Owner.ID,toUserID,@@ -262,7 +266,7 @@ func (c *CollectionController) shareCollectionWithUserID(item.Role,updationTime,)- return ente.CollectionShared, added && collection.App == string(ente.Photos), err+ return ente.CollectionShared, collection.App == string(ente.Photos), err}status, err := c.CollectionRepo.ShareAutomatically(ctx,@@ -373,7 +377,7 @@ func (c *CollectionController) JoinViaLink(ctx *gin.Context, req ente.JoinCollecif collectionLinkToken.EnableCollect {role = ente.COLLABORATOR}- _, joinErr := c.CollectionRepo.Share(req.CollectionID, collection.Owner.ID, userID, req.EncryptedKey, role, time.Microseconds())+ joinErr := c.CollectionRepo.Share(req.CollectionID, collection.Owner.ID, userID, req.EncryptedKey, role, time.Microseconds())if joinErr != nil {return stacktrace.Propagate(joinErr, "")}diff --git a/server/pkg/controller/collections/share_test.go b/server/pkg/controller/collections/share_test.goindex d50ac43b95..808b29b88f 100644--- a/server/pkg/controller/collections/share_test.go+++ b/server/pkg/controller/collections/share_test.go@@ -189,7 +189,7 @@ func addShareTestShare(role ente.CollectionParticipantRole,) {t.Helper()- if _, err := collectionRepo.Share(collectionID, ownerID, shareeID, "share-key", role, 1); err != nil {+ if err := collectionRepo.Share(collectionID, ownerID, shareeID, "share-key", role, 1); err != nil {t.Fatal(err)}}@@ -369,7 +369,7 @@ func TestAutomaticShareLifecycle(t *testing.T) {ctx := context.Background()manualCollectionID := createShareTestCollection(t, collectionRepo, ownerID)- if _, err := collectionRepo.Share(+ if err := collectionRepo.Share(manualCollectionID,ownerID,shareeID,@@ -444,7 +444,7 @@ func TestUnShareContextBumpsCollectionForDeletedShareRow(t *testing.T) {db, collectionRepo, ownerID, shareeID := setupCollectionShareTest(t)ctx := context.Background()collectionID := createShareTestCollection(t, collectionRepo, ownerID)- if _, err := collectionRepo.Share(+ if err := collectionRepo.Share(collectionID,ownerID,shareeID,@@ -787,7 +787,7 @@ func TestBatchShareRollsBackWhenAnyWriteFails(t *testing.T) {collectionID := createShareTestCollection(t, collectionRepo, ownerID)originalCollectionTime := collectionUpdationTime(t, db, collectionID)- _, err := collectionRepo.BatchShare(+ err := collectionRepo.BatchShare(context.Background(),collectionID,ownerID,@@ -836,7 +836,7 @@ func TestBatchShareRejectsDeletedCollection(t *testing.T) {t.Fatalf("unauthorized BatchShare() error = %v, want %v", err, ente.ErrPermissionDenied)}- _, err = collectionRepo.BatchShare(+ err = collectionRepo.BatchShare(context.Background(),collectionID,ownerID,@@ -955,7 +955,7 @@ func (f albumSharePushFunc) NotifyAlbumShare(ctx context.Context, recipients []if(ctx, recipients)}-func TestAlbumShareNotifiesOnlyNewAccess(t *testing.T) {+func TestAlbumShareNotifiesAfterEverySuccessfulShare(t *testing.T) {db, r, owner, recipient := setupCollectionShareTest(t)c := newBatchShareTestController(db, r)id := createShareTestCollection(t, r, owner)@@ -979,7 +979,9 @@ func TestAlbumShareNotifiesOnlyNewAccess(t *testing.T) {request.Role = &role_, err = c.Share(newBatchShareTestContext(owner), request)require.NoError(t, err)- require.Never(t, func() bool { return len(notifications) > 0 }, 50*time.Millisecond, time.Millisecond, "retry and role change must not notify")+ require.Eventually(t, func() bool { return len(notifications) == 2 }, time.Second, time.Millisecond, "retry and role change must notify")+ require.Equal(t, []int64{recipient}, <-notifications)+ require.Equal(t, []int64{recipient}, <-notifications)var storedRole ente.CollectionParticipantRolevar deleted boolvar encryptedKey string@@ -1013,7 +1015,7 @@ func TestAlbumShareNotifiesOnlyNewAccess(t *testing.T) {require.True(t, deleted, "failed share must roll back restored access")}-func TestBatchShareNotifiesOnlyNewRecipient(t *testing.T) {+func TestBatchShareNotifiesAllRecipients(t *testing.T) {db, r, owner, existingRecipient := setupCollectionShareTest(t)newRecipient := testutil.InsertUser(t, db, testutil.UserFixture{UserID: 3, Email: "[email protected]", CreationTime: 1,@@ -1040,29 +1042,33 @@ func TestBatchShareNotifiesOnlyNewRecipient(t *testing.T) {require.Equal(t, ente.COLLABORATOR, roles[newRecipient])select {case recipients := <-notifications:- require.Equal(t, []int64{newRecipient}, recipients)+ require.ElementsMatch(t, []int64{existingRecipient, newRecipient}, recipients)case <-time.After(time.Second):t.Fatal("new recipient was not notified")}}-func TestConcurrentAlbumShareGrantsAccessOnce(t *testing.T) {- _, r, owner, recipient := setupCollectionShareTest(t)+func TestConcurrentAlbumSharesNotifyAfterEachSuccess(t *testing.T) {+ db, r, owner, recipient := setupCollectionShareTest(t)+ c := newBatchShareTestController(db, r)id := createShareTestCollection(t, r, owner)var count atomic.Int32+ c.PushCtrl = albumSharePushFunc(func(context.Context, []int64) { count.Add(1) })var wg sync.WaitGroupfor range 8 {wg.Go(func() {- added, err := r.BatchShare(context.Background(), id, owner, []repo.CollectionShareItem{{ToUserID: recipient, EncryptedKey: "test-key", Role: ente.VIEWER}}, 2)+ _, err := c.BatchShare(newBatchShareTestContext(owner), []ente.AlterShareRequest{{CollectionID: id, Email: "[email protected]", EncryptedKey: b64OfLen(sealedCollectionKeyLen)}})if err != nil {t.Error(err)- return}- count.Add(int32(len(added)))})}wg.Wait()- require.EqualValues(t, 1, count.Load())+ require.Eventually(t, func() bool { return count.Load() == 8 }, time.Second, time.Millisecond)+ require.Equal(t, 1, collectionShareCount(t, db, id))+ var active bool+ require.NoError(t, db.QueryRow(`SELECT NOT is_deleted FROM collection_shares WHERE collection_id=$1 AND to_user_id=$2`, id, recipient).Scan(&active))+ require.True(t, active)}func TestBulkAlbumShareNotifiesOnceAfterAllMutations(t *testing.T) {@@ -1085,8 +1091,7 @@ func TestBulkAlbumShareNotifiesOnceAfterAllMutations(t *testing.T) {_, err := c.BulkShare(newBatchShareTestContext(owner), request)require.NoError(t, err)}- require.Eventually(t, func() bool { return calls.Load() == 1 }, time.Second, time.Millisecond)- require.Never(t, func() bool { return calls.Load() > 1 }, 50*time.Millisecond, time.Millisecond)+ require.Eventually(t, func() bool { return calls.Load() == 2 }, time.Second, time.Millisecond)}func TestAlbumSharePushEligibility(t *testing.T) {diff --git a/server/pkg/controller/push.go b/server/pkg/controller/push.goindex 8f4ab004cf..a8de788ce9 100644--- a/server/pkg/controller/push.go+++ b/server/pkg/controller/push.go@@ -129,14 +129,17 @@ func (c *PushController) NotifyAlbumShare(ctx context.Context, recipients []int6}var unregisteredTokens []stringfor _, token := range tokens {- ciphertext, err := box.SealAnonymous(nil, []byte(`{"version":1,"eventType":"album_shared"}`), (*[32]byte)(token.NotificationPublicKey), rand.Reader)- if err != nil {- log.WithError(err).Warn("album share notification encryption failed")- continue- }- err = c.fcm.sendMessage(ctx, map[string]any{- "token": token.FCMToken,- "apns": map[string]any{+ message := map[string]any{"token": token.FCMToken}+ if token.Platform == "android" {+ message["data"] = map[string]string{"action": "sync"}+ message["android"] = map[string]string{"priority": "high", "ttl": "86400s"}+ } else {+ ciphertext, err := box.SealAnonymous(nil, []byte(`{"version":1,"eventType":"album_shared"}`), (*[32]byte)(token.NotificationPublicKey), rand.Reader)+ if err != nil {+ log.WithError(err).Warn("album share notification encryption failed")+ continue+ }+ message["apns"] = map[string]any{"headers": map[string]string{"apns-push-type": "alert","apns-priority": "10",@@ -151,8 +154,9 @@ func (c *PushController) NotifyAlbumShare(ctx context.Context, recipients []int6"notificationVersion": 1,"notificationCiphertext": base64.StdEncoding.EncodeToString(ciphertext),},- },- })+ }+ }+ err = c.fcm.sendMessage(ctx, message)if err != nil {log.WithError(err).Warn("album share push failed; album remains shared")if errors.Is(err, errUnregisteredToken) {diff --git a/server/pkg/controller/push_test.go b/server/pkg/controller/push_test.goindex 71b75d7950..36a2187c98 100644--- a/server/pkg/controller/push_test.go+++ b/server/pkg/controller/push_test.go@@ -168,7 +168,7 @@ func TestFCMSendDoesNotClassifyInvalidArgumentAsUnregistered(t *testing.T) {require.False(t, errors.Is(err, errUnregisteredToken))}-func TestAlbumShareEncryptsEventForEachDevice(t *testing.T) {+func TestAlbumShareSendsPlatformPayloads(t *testing.T) {testutil.WithServerRoot(t)db := testutil.RequireTestDB(t)testutil.ResetTables(t, db)@@ -190,6 +190,8 @@ func TestAlbumShareEncryptsEventForEachDevice(t *testing.T) {Notification: &ente.PushNotificationRegistration{Version: 1, PublicKey: publicKey[:]},}))}+ platform = "android"+ require.NoError(t, controller.AddToken(1, hash[:], ente.PushTokenRequest{FCMToken: "android-device", Platform: &platform}))var messages []map[string]anycontroller.fcm = &fcmClient{projectID: "test-project", httpClient: &http.Client{Transport: roundTripFunc(func(request *http.Request) (*http.Response, error) {require.NoError(t, request.Context().Err())@@ -204,8 +206,16 @@ func TestAlbumShareEncryptsEventForEachDevice(t *testing.T) {cancel()before := time.Now().Add(24 * time.Hour).Unix()controller.NotifyAlbumShare(ctx, []int64{1})- require.Len(t, messages, 2)+ require.Len(t, messages, 3)for _, message := range messages {+ if message["token"] == "android-device" {+ require.Equal(t, map[string]any{+ "token": "android-device",+ "data": map[string]any{"action": "sync"},+ "android": map[string]any{"priority": "high", "ttl": "86400s"},+ }, message)+ continue+ }require.Len(t, message, 2)device := message["token"].(string)apns := message["apns"].(map[string]any)@@ -243,7 +253,7 @@ func TestAlbumShareEncryptsEventForEachDevice(t *testing.T) {return jsonResponse(http.StatusInternalServerError, "unavailable"), nil})controller.NotifyAlbumShare(context.Background(), []int64{1})- require.Len(t, messages, 2, "one device failure must not stop the other send")+ require.Len(t, messages, 3, "one device failure must not stop the other sends")}func TestAlbumSharePrunesOnlyUnregisteredTokens(t *testing.T) {diff --git a/server/pkg/repo/collection.go b/server/pkg/repo/collection.goindex 894b793727..1d888e4e28 100644--- a/server/pkg/repo/collection.go+++ b/server/pkg/repo/collection.go@@ -511,18 +511,18 @@ func (repo *CollectionRepository) Share(toUserID int64,encryptedKey string,role ente.CollectionParticipantRole,- updationTime int64) (bool, error) {+ updationTime int64) error {context := context.Background()tx, err := repo.DB.BeginTx(context, nil)if err != nil {- return false, stacktrace.Propagate(err, "")+ return stacktrace.Propagate(err, "")}defer tx.Rollback()if role != ente.VIEWER && role != ente.COLLABORATOR && role != ente.ADMIN {err = fmt.Errorf("invalid role %s", string(role))- return false, stacktrace.Propagate(err, "")+ return stacktrace.Propagate(err, "")}- result, err := tx.ExecContext(context, `INSERT INTO collection_shares(collection_id, from_user_id, to_user_id, encrypted_key, updation_time, role_type, shared_at) VALUES($1, $2, $3, $4, $5, $6, $7)+ _, err = tx.ExecContext(context, `INSERT INTO collection_shares(collection_id, from_user_id, to_user_id, encrypted_key, updation_time, role_type, shared_at) VALUES($1, $2, $3, $4, $5, $6, $7)ON CONFLICT (collection_id, from_user_id, to_user_id)DO UPDATE SETis_deleted = FALSE,@@ -531,40 +531,24 @@ func (repo *CollectionRepository) Share(shared_at = CASEWHEN collection_shares.is_deleted = TRUE THEN $7ELSE collection_shares.shared_at- END- WHERE collection_shares.is_deleted IS NOT FALSE`,+ END`,collectionID, fromUserID, toUserID, encryptedKey, updationTime, role, updationTime)if err != nil {- return false, stacktrace.Propagate(err, "")- }- added, err := result.RowsAffected()- if err != nil {- return false, stacktrace.Propagate(err, "")- }- if added == 0 {- _, err = tx.ExecContext(context, `UPDATE collection_shares SET updation_time = $4, role_type = $5- WHERE collection_id = $1 AND from_user_id = $2 AND to_user_id = $3`,- collectionID, fromUserID, toUserID, updationTime, role)- if err != nil {- return false, stacktrace.Propagate(err, "")- }+ return stacktrace.Propagate(err, "")}- result, err = tx.ExecContext(context, `UPDATE collections SET updation_time = $1+ result, err := tx.ExecContext(context, `UPDATE collections SET updation_time = $1WHERE collection_id = $2 AND is_deleted = FALSE`, updationTime, collectionID)if err != nil {- return false, stacktrace.Propagate(err, "")+ return stacktrace.Propagate(err, "")}updated, err := result.RowsAffected()if err != nil {- return false, stacktrace.Propagate(err, "")+ return stacktrace.Propagate(err, "")}if updated == 0 {- return false, stacktrace.Propagate(ente.ErrCollectionDeleted, "")- }- if err := tx.Commit(); err != nil {- return false, stacktrace.Propagate(err, "")+ return stacktrace.Propagate(ente.ErrCollectionDeleted, "")}- return added == 1, nil+ return stacktrace.Propagate(tx.Commit(), "")}func (repo *CollectionRepository) BatchShare(@@ -573,7 +557,7 @@ func (repo *CollectionRepository) BatchShare(fromUserID int64,shares []CollectionShareItem,updationTime int64,-) ([]int64, error) {+) error {toUserIDs := make([]int64, len(shares))encryptedKeys := make([]string, len(shares))roles := make([]string, len(shares))@@ -585,11 +569,11 @@ func (repo *CollectionRepository) BatchShare(tx, err := repo.DB.BeginTx(ctx, nil)if err != nil {- return nil, stacktrace.Propagate(err, "")+ return stacktrace.Propagate(err, "")}defer tx.Rollback()- rows, err := tx.QueryContext(ctx, `INSERT INTO collection_shares+ _, err = tx.ExecContext(ctx, `INSERT INTO collection_shares(collection_id, from_user_id, to_user_id, encrypted_key, updation_time, role_type, shared_at)SELECT $1, $2, input.to_user_id, input.encrypted_key, $3, input.role, $3FROM unnest($4::bigint[], $5::text[], $6::role_enum[])@@ -603,9 +587,7 @@ func (repo *CollectionRepository) BatchShare(shared_at = CASEWHEN collection_shares.is_deleted = TRUE THEN EXCLUDED.shared_atELSE collection_shares.shared_at- END- WHERE collection_shares.is_deleted IS NOT FALSE- RETURNING to_user_id`,+ END`,collectionID,fromUserID,updationTime,@@ -614,49 +596,22 @@ func (repo *CollectionRepository) BatchShare(pq.Array(roles),)if err != nil {- return nil, stacktrace.Propagate(err, "")- }-- added := []int64{}- for rows.Next() {- var id int64- if err := rows.Scan(&id); err != nil {- rows.Close()- return nil, stacktrace.Propagate(err, "")- }- added = append(added, id)- }- rows.Close()- if err := rows.Err(); err != nil {- return nil, stacktrace.Propagate(err, "")- }- if len(added) < len(shares) {- _, err = tx.ExecContext(ctx, `UPDATE collection_shares s SET role_type = input.role, updation_time = $3- FROM unnest($4::bigint[], $5::role_enum[]) AS input(to_user_id, role)- WHERE s.collection_id = $1 AND s.from_user_id = $2 AND s.to_user_id = input.to_user_id- AND s.to_user_id <> ALL($6::bigint[])`,- collectionID, fromUserID, updationTime, pq.Array(toUserIDs), pq.Array(roles), pq.Array(added))- if err != nil {- return nil, stacktrace.Propagate(err, "")- }+ return stacktrace.Propagate(err, "")}result, err := tx.ExecContext(ctx, `UPDATE collections SET updation_time = $1WHERE collection_id = $2 AND is_deleted = FALSE`, updationTime, collectionID)if err != nil {- return nil, stacktrace.Propagate(err, "")+ return stacktrace.Propagate(err, "")}updated, err := result.RowsAffected()if err != nil {- return nil, stacktrace.Propagate(err, "")+ return stacktrace.Propagate(err, "")}if updated == 0 {- return nil, stacktrace.Propagate(ente.ErrCollectionDeleted, "")+ return stacktrace.Propagate(ente.ErrCollectionDeleted, "")}- if err := tx.Commit(); err != nil {- return nil, stacktrace.Propagate(err, "")- }- return added, nil+ return stacktrace.Propagate(tx.Commit(), "")}// ShareAutomatically creates a share without modifying a prior share.diff --git a/server/pkg/repo/push.go b/server/pkg/repo/push.goindex 4cbd65d0ed..8b03e5709e 100644--- a/server/pkg/repo/push.go+++ b/server/pkg/repo/push.go@@ -63,10 +63,11 @@ func (repo *PushTokenRepository) GetTokensToBeNotified(lastNotificationTime int6}func (repo *PushTokenRepository) GetTokensForAlbumShare(ctx context.Context, userIDs []int64) ([]ente.PushToken, error) {- rows, err := repo.DB.QueryContext(ctx, `SELECT p.fcm_token, p.notification_public_key FROM push_tokens p+ rows, err := repo.DB.QueryContext(ctx, `SELECT p.fcm_token, p.platform, p.notification_public_key FROM push_tokens pJOIN tokens t ON t.token_hash = p.session_token_hash AND t.user_id = p.user_id AND t.is_deleted = false AND t.app = $3JOIN remote_store r ON r.user_id = p.user_id AND r.key_name = $2 AND r.key_value = 'true'- WHERE p.user_id = ANY($1) AND p.platform = 'ios' AND p.notification_public_key IS NOT NULL`,+ WHERE p.user_id = ANY($1)+ AND (p.platform = 'android' OR (p.platform = 'ios' AND p.notification_public_key IS NOT NULL))`,pq.Array(userIDs), string(ente.IsInternalUser), string(ente.Photos))if err != nil {return nil, stacktrace.Propagate(err, "")@@ -75,7 +76,7 @@ func (repo *PushTokenRepository) GetTokensForAlbumShare(ctx context.Context, usevar tokens []ente.PushTokenfor rows.Next() {var token ente.PushToken- if err := rows.Scan(&token.FCMToken, &token.NotificationPublicKey); err != nil {+ if err := rows.Scan(&token.FCMToken, &token.Platform, &token.NotificationPublicKey); err != nil {return nil, stacktrace.Propagate(err, "")}tokens = append(tokens, token)diff --git a/server/pkg/repo/push_test.go b/server/pkg/repo/push_test.goindex ad42991e68..40ba3f5b6e 100644--- a/server/pkg/repo/push_test.go+++ b/server/pkg/repo/push_test.go@@ -180,19 +180,20 @@ func TestPushNotificationRegistrationMigration(t *testing.T) {require.Equal(t, 2, count)}-func TestAlbumShareTokensRequireInternalIOSAndActiveSession(t *testing.T) {+func TestAlbumShareTokensRequireInternalAndActiveSession(t *testing.T) {testutil.WithServerRoot(t)db := testutil.RequireTestDB(t)testutil.ResetTables(t, db)t.Cleanup(func() { testutil.ResetTables(t, db) })key := append([]byte{9}, make([]byte, 31)...)+ var userIDs []int64for id, tc := range []struct {name, platform, flag, session stringapp ente.Appkey []byte}{{"eligible", "ios", "true", "active", ente.Photos, key},- {"android", "android", "true", "active", ente.Photos, key},+ {"android", "android", "true", "active", ente.Photos, nil},{"non-internal", "ios", "false", "active", ente.Photos, key},{"missing flag", "ios", "", "active", ente.Photos, key},{"unenrolled", "ios", "true", "active", ente.Photos, nil},@@ -200,8 +201,14 @@ func TestAlbumShareTokensRequireInternalIOSAndActiveSession(t *testing.T) {{"revoked", "ios", "true", "revoked", ente.Photos, key},{"wrong owner", "ios", "true", "wrong owner", ente.Photos, key},{"other app", "ios", "true", "active", ente.Locker, key},+ {"android non-internal", "android", "false", "active", ente.Photos, nil},+ {"android legacy", "android", "true", "missing", ente.Photos, nil},+ {"android revoked", "android", "true", "revoked", ente.Photos, nil},+ {"android wrong owner", "android", "true", "wrong owner", ente.Photos, nil},+ {"android other app", "android", "true", "active", ente.Locker, nil},} {userID := int64(id + 1)+ userIDs = append(userIDs, userID)testutil.InsertUser(t, db, testutil.UserFixture{UserID: userID, Email: fmt.Sprintf("user%[email protected]", userID), CreationTime: 1})hash := sha256.Sum256([]byte(tc.name))var sessionHash []byte@@ -230,11 +237,13 @@ func TestAlbumShareTokensRequireInternalIOSAndActiveSession(t *testing.T) {}}r := &PushTokenRepository{DB: db}- tokens, err := r.GetTokensForAlbumShare(context.Background(), []int64{1, 2, 3, 4, 5, 6, 7, 8, 9})+ tokens, err := r.GetTokensForAlbumShare(context.Background(), userIDs)require.NoError(t, err)- require.Len(t, tokens, 1)- require.Equal(t, "eligible", tokens[0].FCMToken)- require.Equal(t, key, tokens[0].NotificationPublicKey)+ var selected []string+ for _, token := range tokens {+ selected = append(selected, token.FCMToken)+ }+ require.ElementsMatch(t, []string{"eligible", "android"}, selected)for _, apnsToken := range []any{"", nil} {_, err := db.Exec(`UPDATE push_tokens SET apns_token=$1 WHERE fcm_token='eligible'`, apnsToken)require.NoError(t, err)@@ -242,10 +251,13 @@ func TestAlbumShareTokensRequireInternalIOSAndActiveSession(t *testing.T) {require.NoError(t, err)require.Len(t, tokens, 1)require.Equal(t, "eligible", tokens[0].FCMToken)+ require.Equal(t, key, tokens[0].NotificationPublicKey)}tokens, err = r.GetTokensForAlbumShare(context.Background(), []int64{2})require.NoError(t, err)- require.Empty(t, tokens)+ require.Len(t, tokens, 1)+ require.Equal(t, "android", tokens[0].FCMToken)+ require.Empty(t, tokens[0].NotificationPublicKey)tokens, err = r.GetTokensToBeNotified(1, 100)require.NoError(t, err)for _, token := range tokens {