Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Scope social state to visible collections

ashilkn635067e1c963
diff --git a/mobile/apps/photos/changes/scope-social-state-to-visible-collections.md b/mobile/apps/photos/changes/scope-social-state-to-visible-collections.md
new file mode 100644
index 0000000000..305ab87574
--- /dev/null
+++ b/mobile/apps/photos/changes/scope-social-state-to-visible-collections.md
@@ -0,0 +1 @@
+- Keep like and comment indicators consistent with the shared albums visible from the current viewer.
diff --git a/mobile/apps/photos/lib/db/social_db.dart b/mobile/apps/photos/lib/db/social_db.dart
index bb6a019fc2..7ae5d80ced 100644
--- a/mobile/apps/photos/lib/db/social_db.dart
+++ b/mobile/apps/photos/lib/db/social_db.dart
@@ -180,12 +180,21 @@ class SocialDB {
return rows.isEmpty ? null : _rowToComment(rows.first);
}
- Future<int> getCommentCountForFile(int fileID) async {
+ Future<int> getCommentCountForFileInCollections(
+ int fileID,
+ List<int> collectionIDs,
+ ) async {
+ if (collectionIDs.isEmpty) {
+ return 0;
+ }
+
+ final placeholders = List.filled(collectionIDs.length, '?').join(',');
final db = await database;
final result = await db.rawQuery(
'SELECT COUNT(*) as count FROM $_commentsTable '
- 'WHERE file_id = ? AND is_deleted = 0',
- [fileID],
+ 'WHERE file_id = ? AND collection_id IN ($placeholders) '
+ 'AND is_deleted = 0',
+ [fileID, ...collectionIDs],
);
return Sqflite.firstIntValue(result) ?? 0;
}
@@ -296,16 +305,26 @@ class SocialDB {
return rows.map(_rowToReaction).toList();
}
- Future<bool> hasUserReactedToFile(int fileID, int userID) async {
+ Future<bool> hasUserReactedToFileInCollections(
+ int fileID,
+ int userID,
+ List<int> collectionIDs,
+ ) async {
+ if (collectionIDs.isEmpty) {
+ return false;
+ }
+
+ final placeholders = List.filled(collectionIDs.length, '?').join(',');
final db = await database;
final rows = await db.rawQuery(
'''
SELECT 1 FROM $_reactionsTable
WHERE file_id = ? AND user_id = ?
+ AND collection_id IN ($placeholders)
AND comment_id IS NULL AND is_deleted = 0
LIMIT 1
''',
- [fileID, userID],
+ [fileID, userID, ...collectionIDs],
);
return rows.isNotEmpty;
}
diff --git a/mobile/apps/photos/lib/models/social/social_data_provider.dart b/mobile/apps/photos/lib/models/social/social_data_provider.dart
index 2b297f6f4f..dd2c41871d 100644
--- a/mobile/apps/photos/lib/models/social/social_data_provider.dart
+++ b/mobile/apps/photos/lib/models/social/social_data_provider.dart
@@ -36,8 +36,11 @@ class SocialDataProvider {
);
}
- Future<int> getCommentCountForFile(int fileID) {
- return _db.getCommentCountForFile(fileID);
+ Future<int> getCommentCountForFileInCollections(
+ int fileID,
+ List<int> collectionIDs,
+ ) {
+ return _db.getCommentCountForFileInCollections(fileID, collectionIDs);
}
Future<int> getCommentCountForFileInCollection(int fileID, int collectionID) {
@@ -48,8 +51,12 @@ class SocialDataProvider {
return _db.getReactionsForFile(fileID);
}
- Future<bool> hasUserReactedToFile(int fileID, int userID) {
- return _db.hasUserReactedToFile(fileID, userID);
+ Future<bool> hasUserReactedToFileInCollections(
+ int fileID,
+ int userID,
+ List<int> collectionIDs,
+ ) {
+ return _db.hasUserReactedToFileInCollections(fileID, userID, collectionIDs);
}
Future<List<Reaction>> getReactionsForFileInCollection(
diff --git a/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart b/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart
index c36e911248..aac2bb6ac3 100644
--- a/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart
+++ b/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart
@@ -147,8 +147,12 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
final provider = SocialDataProvider.instance;
final results = await Future.wait<Object?>([
- provider.hasUserReactedToFile(fileID, currentUserID),
- provider.getCommentCountForFile(fileID),
+ provider.hasUserReactedToFileInCollections(
+ fileID,
+ currentUserID,
+ collectionIDs,
+ ),
+ provider.getCommentCountForFileInCollections(fileID, collectionIDs),
provider.getLatestCommentForFile(
fileID,
candidateCollectionIDs: collectionIDs,
diff --git a/mobile/apps/photos/test/db/social_db_test.dart b/mobile/apps/photos/test/db/social_db_test.dart
index 097c37a781..c4161c342e 100644
--- a/mobile/apps/photos/test/db/social_db_test.dart
+++ b/mobile/apps/photos/test/db/social_db_test.dart
@@ -29,7 +29,7 @@ void main() {
await tempDir.delete(recursive: true);
});
- test("heart state is file-wide across collections", () async {
+ test("heart state stays inside the requested collection scope", () async {
await SocialDB.instance.upsertReactions([
_reaction(id: "visible", collectionID: 10, userID: 1),
_reaction(id: "hidden", collectionID: 20, userID: 2),
@@ -42,10 +42,43 @@ void main() {
),
]);
- expect(await SocialDB.instance.hasUserReactedToFile(100, 1), isTrue);
- expect(await SocialDB.instance.hasUserReactedToFile(100, 2), isTrue);
- expect(await SocialDB.instance.hasUserReactedToFile(100, 3), isFalse);
- expect(await SocialDB.instance.hasUserReactedToFile(100, 4), isFalse);
+ expect(
+ await SocialDB.instance.hasUserReactedToFileInCollections(100, 1, [10]),
+ isTrue,
+ );
+ expect(
+ await SocialDB.instance.hasUserReactedToFileInCollections(100, 2, [10]),
+ isFalse,
+ );
+ expect(
+ await SocialDB.instance.hasUserReactedToFileInCollections(100, 2, [20]),
+ isTrue,
+ );
+ expect(
+ await SocialDB.instance.hasUserReactedToFileInCollections(100, 2, [
+ 10,
+ 20,
+ ]),
+ isTrue,
+ );
+ expect(
+ await SocialDB.instance.hasUserReactedToFileInCollections(100, 3, [
+ 10,
+ 20,
+ ]),
+ isFalse,
+ );
+ expect(
+ await SocialDB.instance.hasUserReactedToFileInCollections(100, 4, [
+ 10,
+ 20,
+ ]),
+ isFalse,
+ );
+ expect(
+ await SocialDB.instance.hasUserReactedToFileInCollections(100, 1, []),
+ isFalse,
+ );
});
test("latest comment stays inside the eligible collection scope", () async {
@@ -74,14 +107,32 @@ void main() {
);
});
- test("comment count is aggregated across collections", () async {
+ test("comment count stays inside the requested collection scope", () async {
await SocialDB.instance.upsertComments([
_comment(id: "visible", collectionID: 10, createdAt: 10),
_comment(id: "hidden", collectionID: 20, createdAt: 20),
_comment(id: "deleted", collectionID: 20, createdAt: 30, isDeleted: true),
]);
- expect(await SocialDB.instance.getCommentCountForFile(100), 2);
+ expect(
+ await SocialDB.instance.getCommentCountForFileInCollections(100, [10]),
+ 1,
+ );
+ expect(
+ await SocialDB.instance.getCommentCountForFileInCollections(100, [20]),
+ 1,
+ );
+ expect(
+ await SocialDB.instance.getCommentCountForFileInCollections(100, [
+ 10,
+ 20,
+ ]),
+ 2,
+ );
+ expect(
+ await SocialDB.instance.getCommentCountForFileInCollections(100, []),
+ 0,
+ );
});
}