π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix social comment collection selection
ashil-pilot7c7d9dabe19c
diff --git a/mobile/apps/photos/changes/latest-comment-album.md b/mobile/apps/photos/changes/latest-comment-album.mdnew file mode 100644index 0000000000..f1b25788d4--- /dev/null+++ b/mobile/apps/photos/changes/latest-comment-album.md@@ -0,0 +1 @@+- Fixed opening the wrong album when tapping the latest comment on a photo.diff --git a/mobile/apps/photos/lib/ui/social/comment_collection_selection.dart b/mobile/apps/photos/lib/ui/social/comment_collection_selection.dartnew file mode 100644index 0000000000..2f2ccaaf05--- /dev/null+++ b/mobile/apps/photos/lib/ui/social/comment_collection_selection.dart@@ -0,0 +1,12 @@+int resolveInitialCommentsCollectionID({+ required int requestedCollectionID,+ required int? draftCollectionID,+ required bool preferDraftCollection,+ required bool hasHighlightedComment,+}) {+ return preferDraftCollection &&+ !hasHighlightedComment &&+ draftCollectionID != null+ ? draftCollectionID+ : requestedCollectionID;+}diff --git a/mobile/apps/photos/lib/ui/social/comments_screen.dart b/mobile/apps/photos/lib/ui/social/comments_screen.dartindex 8a02f2dab3..4f550ab401 100644--- a/mobile/apps/photos/lib/ui/social/comments_screen.dart+++ b/mobile/apps/photos/lib/ui/social/comments_screen.dart@@ -17,6 +17,7 @@ import 'package:photos/services/social_notification_coordinator.dart';import "package:photos/theme/ente_theme.dart";import "package:photos/ui/common/loading_widget.dart";import "package:photos/ui/components/buttons/icon_button_widget.dart";+import "package:photos/ui/social/comment_collection_selection.dart";import "package:photos/ui/social/social_actor_contact_navigation.dart";import "package:photos/ui/social/widgets/collection_selector_widget.dart";import "package:photos/ui/social/widgets/comment_bubble_widget.dart";@@ -41,6 +42,7 @@ Future<void> showFileCommentsBottomSheet(required int collectionID,required int fileID,String? highlightCommentID,+ bool preferDraftCollection = true,List<Collection>? sharedCollections,}) {return showModalBottomSheet(@@ -52,6 +54,7 @@ Future<void> showFileCommentsBottomSheet(collectionID: collectionID,fileID: fileID,highlightCommentID: highlightCommentID,+ preferDraftCollection: preferDraftCollection,sharedCollections: sharedCollections,),);@@ -62,6 +65,7 @@ class _DraggableCommentsSheet extends StatefulWidget {final int collectionID;final int fileID;final String? highlightCommentID;+ final bool preferDraftCollection;final List<Collection>? sharedCollections;const _DraggableCommentsSheet({@@ -69,6 +73,7 @@ class _DraggableCommentsSheet extends StatefulWidget {required this.collectionID,required this.fileID,this.highlightCommentID,+ required this.preferDraftCollection,this.sharedCollections,});@@ -102,6 +107,7 @@ class _DraggableCommentsSheetState extends State<_DraggableCommentsSheet> {collectionID: widget.collectionID,fileID: widget.fileID,highlightCommentID: widget.highlightCommentID,+ preferDraftCollection: widget.preferDraftCollection,sharedCollections: widget.sharedCollections,dragController: scrollController,sheetController: sheetController,@@ -119,6 +125,10 @@ class FileCommentsBottomSheet extends StatefulWidget {/// Optional comment ID to scroll to and highlight.final String? highlightCommentID;+ /// Whether an unsent draft in another collection may override+ /// [collectionID] when the sheet opens.+ final bool preferDraftCollection;+/// Scroll controller for the drag handle (from DraggableScrollableSheet).final ScrollController dragController;@@ -130,6 +140,7 @@ class FileCommentsBottomSheet extends StatefulWidget {required this.collectionID,required this.fileID,this.sharedCollections,+ this.preferDraftCollection = true,required this.dragController,required this.sheetController,this.highlightCommentID,@@ -183,9 +194,12 @@ class _FileCommentsBottomSheetState extends State<FileCommentsBottomSheet> {_inputFocusNode = FocusNode()..addListener(_onInputFocusChange);_scrollController = ScrollController()..addListener(_onScroll);_currentUserID = Configuration.instance.getUserID()!;- _selectedCollectionID = _canRestoreDraftCollection- ? _lastSelectedDraftCollectionIDs[_draftFileKey] ?? widget.collectionID- : widget.collectionID;+ _selectedCollectionID = resolveInitialCommentsCollectionID(+ requestedCollectionID: widget.collectionID,+ draftCollectionID: _lastSelectedDraftCollectionIDs[_draftFileKey],+ preferDraftCollection: widget.preferDraftCollection,+ hasHighlightedComment: widget.highlightCommentID != null,+ );_highlightedCommentID = widget.highlightCommentID;_loadSharedCollections();}@@ -674,7 +688,8 @@ class _FileCommentsBottomSheetState extends State<FileCommentsBottomSheet> {_CommentDraftFileKey get _draftFileKey =>(userID: _currentUserID, fileID: widget.fileID);- bool get _canRestoreDraftCollection => widget.highlightCommentID == null;+ bool get _canRestoreDraftCollection =>+ widget.preferDraftCollection && widget.highlightCommentID == null;_CommentDraftKey get _draftKey => (userID: _currentUserID,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.dartindex ee56aea0ce..03eacb5797 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@@ -123,7 +123,18 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {if (fileID == null || currentUserID == null) {_clearSocialState();- widget.onVisibilityChanged?.call(false);+ // This path can run synchronously from didUpdateWidget. Defer notifying+ // the host so a future uploaded-to-local transition cannot mark a+ // sibling widget dirty while Flutter is still building this overlay.+ scheduleMicrotask(() {+ if (!mounted ||+ refreshID != _latestRefreshID ||+ widget.file.uploadedFileID != fileID ||+ widget.currentUserID != currentUserID) {+ return;+ }+ widget.onVisibilityChanged?.call(false);+ });return;}@@ -389,6 +400,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {context,collectionID: initialCollection.id,fileID: fileID,+ preferDraftCollection: comment == null,sharedCollections: sharedCollections,);});diff --git a/mobile/apps/photos/test/ui/social/comments_collection_selection_test.dart b/mobile/apps/photos/test/ui/social/comments_collection_selection_test.dartnew file mode 100644index 0000000000..c0b4770148--- /dev/null+++ b/mobile/apps/photos/test/ui/social/comments_collection_selection_test.dart@@ -0,0 +1,42 @@+import "package:flutter_test/flutter_test.dart";+import "package:photos/ui/social/comment_collection_selection.dart";++void main() {+ group("initial comments collection", () {+ test("prefers a collection containing an unsent draft", () {+ expect(+ resolveInitialCommentsCollectionID(+ requestedCollectionID: 10,+ draftCollectionID: 20,+ preferDraftCollection: true,+ hasHighlightedComment: false,+ ),+ 20,+ );+ });++ test("keeps the requested collection for an explicit comment tap", () {+ expect(+ resolveInitialCommentsCollectionID(+ requestedCollectionID: 10,+ draftCollectionID: 20,+ preferDraftCollection: false,+ hasHighlightedComment: false,+ ),+ 10,+ );+ });++ test("keeps the requested collection for a highlighted comment", () {+ expect(+ resolveInitialCommentsCollectionID(+ requestedCollectionID: 10,+ draftCollectionID: 20,+ preferDraftCollection: true,+ hasHighlightedComment: true,+ ),+ 10,+ );+ });+ });+}