Skip to content

armgit / ente

Public Imported from GitHub
0

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

Simplify social viewer async flow

ashilkncb8fc3c9b130
diff --git a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
index 60ae24690a..26a45bc2b0 100644
--- a/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
+++ b/mobile/apps/photos/lib/ui/home/memories/full_screen_memory.dart
@@ -680,10 +680,8 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
},
onSwipeUp: () {
if (!(ModalRoute.of(context)?.isCurrent ?? false)) return;
- unawaited(
- _runWithViewerPaused(
- () => showDetailsSheet(context, currentFile),
- ),
+ _runWithViewerPaused(
+ () => showDetailsSheet(context, currentFile),
);
},
canSwipeUp: () => !_isMediaZoomed,
@@ -787,12 +785,10 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
title: widget.title,
onClose: () => Navigator.pop(context),
onDateTap: (file) {
- unawaited(
- _runWithViewerPaused(
- () => routeToPage(
- context,
- JumpToDateGallery(fileToJumpTo: file),
- ),
+ _runWithViewerPaused(
+ () => routeToPage(
+ context,
+ JumpToDateGallery(fileToJumpTo: file),
),
);
},
@@ -974,7 +970,7 @@ class _MemoryActionButton extends StatelessWidget {
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
overlayColor: Colors.white.withValues(alpha: 0.08),
),
- onPressed: () => unawaited(onPressed()),
+ onPressed: onPressed,
icon: icon,
),
);
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 90f1604d96..7467db911b 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
@@ -26,14 +26,6 @@ const _likedColor = Color(0xFF08C225);
const _socialControlsSize = 40.0;
const _socialIconSize = 32.0;
-bool fileSocialContextIncludesHiddenCollections(
- int? openingCollectionID,
- Set<int> hiddenCollectionIDs,
-) {
- return openingCollectionID != null &&
- hiddenCollectionIDs.contains(openingCollectionID);
-}
-
/// Social content for a file. The host owns placement and visibility effects.
class FileSocialOverlay extends StatefulWidget {
final EnteFile file;
@@ -62,7 +54,7 @@ class FileSocialOverlay extends StatefulWidget {
}
class _FileSocialOverlayState extends State<FileSocialOverlay> {
- List<int> _eligibleSharedCollectionIDs = const [];
+ bool _hasEligibleSharedCollections = false;
bool _hasLiked = false;
int _commentCount = 0;
Comment? _latestComment;
@@ -86,46 +78,34 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
}
void _clearSocialState() {
- _eligibleSharedCollectionIDs = const [];
+ _hasEligibleSharedCollections = false;
_hasLiked = false;
_commentCount = 0;
_latestComment = null;
_latestCommentAuthor = null;
}
- bool _canApplySocialRefresh({
- required int requestedFileID,
- required int refreshID,
- }) {
- return mounted &&
- refreshID == _latestRefreshID &&
- widget.file.uploadedFileID == requestedFileID;
+ bool _isCurrentSocialRefresh(int refreshID) {
+ return mounted && refreshID == _latestRefreshID;
}
bool get _includeHiddenCollections {
- return fileSocialContextIncludesHiddenCollections(
- widget.openingCollectionID,
- CollectionsService.instance.getHiddenCollectionIds(),
- );
+ final openingCollectionID = widget.openingCollectionID;
+ return openingCollectionID != null &&
+ CollectionsService.instance.getHiddenCollectionIds().contains(
+ openingCollectionID,
+ );
}
Future<void> _refreshSocialState() async {
- // Recheck the captured file after every await before touching state.
+ // Recheck that this refresh is still current after every await.
final fileID = widget.file.uploadedFileID;
final currentUserID = widget.currentUserID;
final refreshID = ++_latestRefreshID;
if (fileID == null || currentUserID == null) {
_clearSocialState();
- // Defer because a user-null transition can arrive from didUpdateWidget.
- scheduleMicrotask(() {
- if (!mounted ||
- refreshID != _latestRefreshID ||
- widget.file.uploadedFileID != fileID) {
- return;
- }
- widget.onVisibilityChanged?.call(false);
- });
+ widget.onVisibilityChanged?.call(false);
return;
}
@@ -135,10 +115,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
fileID,
includeHidden: _includeHiddenCollections,
);
- if (!_canApplySocialRefresh(
- requestedFileID: fileID,
- refreshID: refreshID,
- )) {
+ if (!_isCurrentSocialRefresh(refreshID)) {
return;
}
@@ -157,10 +134,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
candidateCollectionIDs: collectionIDs,
),
]);
- if (!_canApplySocialRefresh(
- requestedFileID: fileID,
- refreshID: refreshID,
- )) {
+ if (!_isCurrentSocialRefresh(refreshID)) {
return;
}
@@ -174,10 +148,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
latestComment.collectionID,
)
: const <String, String>{};
- if (!_canApplySocialRefresh(
- requestedFileID: fileID,
- refreshID: refreshID,
- )) {
+ if (!_isCurrentSocialRefresh(refreshID)) {
return;
}
@@ -189,14 +160,11 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
);
}
- if (!_canApplySocialRefresh(
- requestedFileID: fileID,
- refreshID: refreshID,
- )) {
+ if (!_isCurrentSocialRefresh(refreshID)) {
return;
}
setState(() {
- _eligibleSharedCollectionIDs = collectionIDs;
+ _hasEligibleSharedCollections = true;
_hasLiked = hasLiked;
_commentCount = commentCount;
_latestComment = latestComment;
@@ -219,7 +187,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
final currentUserID = widget.currentUserID;
if (fileID == null ||
currentUserID == null ||
- _eligibleSharedCollectionIDs.isEmpty ||
+ !_hasEligibleSharedCollections ||
_reactionUpdateFileIDs.contains(fileID)) {
return;
}
@@ -335,7 +303,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
Future<void> _showLikes() async {
final fileID = widget.file.uploadedFileID;
- if (fileID == null || _eligibleSharedCollectionIDs.isEmpty) return;
+ if (fileID == null || !_hasEligibleSharedCollections) return;
await _runSheetAndRefresh(() async {
final sharedCollections = await CollectionsService.instance
.getSharedCollectionsForFile(
@@ -362,7 +330,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
Future<void> _openComments({Comment? comment}) async {
final fileID = widget.file.uploadedFileID;
- if (fileID == null || _eligibleSharedCollectionIDs.isEmpty) return;
+ if (fileID == null || !_hasEligibleSharedCollections) return;
await _runSheetAndRefresh(() async {
final sharedCollections = await CollectionsService.instance
.getSharedCollectionsForFile(
@@ -417,7 +385,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
@override
Widget build(BuildContext context) {
- if (_eligibleSharedCollectionIDs.isEmpty) {
+ if (!_hasEligibleSharedCollections) {
return const SizedBox.shrink();
}
@@ -440,7 +408,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
Tooltip(
message: AppLocalizations.of(context).like,
child: GestureDetector(
- onLongPress: () => unawaited(_showLikes()),
+ onLongPress: _showLikes,
child: SizedBox.square(
dimension: _socialControlsSize,
child: IconButton(
@@ -451,7 +419,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
overlayColor: WidgetStateColor.transparent,
),
- onPressed: () => unawaited(_toggleReaction()),
+ onPressed: _toggleReaction,
icon: Icon(
_hasLiked ? EnteIcons.likeFilled : EnteIcons.likeStroke,
color: _hasLiked ? _likedColor : Colors.white,
@@ -473,7 +441,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
maximumSize: const Size.square(_socialControlsSize),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
- onPressed: () => unawaited(_openComments()),
+ onPressed: _openComments,
icon: _buildCommentIcon(),
),
),
@@ -492,7 +460,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
- onTap: () => unawaited(_openComments(comment: comment)),
+ onTap: () => _openComments(comment: comment),
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: maxWidth),
child: Stack(
diff --git a/mobile/apps/photos/lib/ui/tabs/albums/empty_states/shared_empty_state.dart b/mobile/apps/photos/lib/ui/tabs/albums/empty_states/shared_empty_state.dart
index c8822b9810..0942d84314 100644
--- a/mobile/apps/photos/lib/ui/tabs/albums/empty_states/shared_empty_state.dart
+++ b/mobile/apps/photos/lib/ui/tabs/albums/empty_states/shared_empty_state.dart
@@ -1,5 +1,3 @@
-import "dart:async";
-
import "package:ente_components/ente_components.dart";
import "package:flutter/material.dart";
import "package:photos/generated/l10n.dart";
@@ -65,14 +63,10 @@ class SharedEmptyState extends StatelessWidget {
ButtonComponent(
label: strings.shareAnAlbum,
shouldSurfaceExecutionStates: false,
- onTap: () async {
- unawaited(
- showCollectionActionSheet(
- context,
- actionType: CollectionActionType.shareCollection,
- ),
- );
- },
+ onTap: () => showCollectionActionSheet(
+ context,
+ actionType: CollectionActionType.shareCollection,
+ ),
),
],
),
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
index 07f5feb5bb..70d26e6230 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
@@ -609,38 +609,33 @@ class _FileSelectionActionsWidgetState
skipNotify: true,
);
}
- unawaited(
- showCollectionActionSheet(
- context,
- selectedFiles: widget.selectedFiles,
- actionType: CollectionActionType.moveFiles,
- ),
+ await showCollectionActionSheet(
+ context,
+ selectedFiles: widget.selectedFiles,
+ actionType: CollectionActionType.moveFiles,
);
}
Future<void> _moveFilesToHiddenAlbum() async {
- unawaited(
- showCollectionActionSheet(
- context,
- selectedFiles: widget.selectedFiles,
- actionType: CollectionActionType.moveToHiddenCollection,
- ),
+ await showCollectionActionSheet(
+ context,
+ selectedFiles: widget.selectedFiles,
+ actionType: CollectionActionType.moveToHiddenCollection,
);
}
Future<void> _addToAlbum() async {
- unawaited(
- showCollectionActionSheet(context, selectedFiles: widget.selectedFiles),
+ await showCollectionActionSheet(
+ context,
+ selectedFiles: widget.selectedFiles,
);
}
Future<void> _addToHiddenAlbum() async {
- unawaited(
- showCollectionActionSheet(
- context,
- selectedFiles: widget.selectedFiles,
- actionType: CollectionActionType.addToHiddenAlbum,
- ),
+ await showCollectionActionSheet(
+ context,
+ selectedFiles: widget.selectedFiles,
+ actionType: CollectionActionType.addToHiddenAlbum,
);
}
@@ -891,12 +886,10 @@ class _FileSelectionActionsWidgetState
skipNotify: true,
);
}
- unawaited(
- showCollectionActionSheet(
- context,
- selectedFiles: widget.selectedFiles,
- actionType: CollectionActionType.unHide,
- ),
+ await showCollectionActionSheet(
+ context,
+ selectedFiles: widget.selectedFiles,
+ actionType: CollectionActionType.unHide,
);
}
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart
index 7106755cc1..274d67877b 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart
@@ -1,5 +1,3 @@
-import "dart:async";
-
import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
@@ -354,14 +352,12 @@ class _PeopleSelectionActionWidgetState
final selectedPersonIds = _getSelectedPersonIds(personMap);
if (selectedPersonIds.isEmpty) return;
if (!mounted) return;
- unawaited(
- showCollectionActionSheet(
- context,
- selectedPeople: selectedPersonIds,
- actionType: CollectionActionType.autoAddPeople,
- ),
- );
widget.selectedPeople.clearAll();
+ await showCollectionActionSheet(
+ context,
+ selectedPeople: selectedPersonIds,
+ actionType: CollectionActionType.autoAddPeople,
+ );
}
Future<void> _updatePinState(bool shouldPin) async {
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
index a324e1189f..62c533cd98 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
@@ -565,12 +565,10 @@ class FileAppBarState extends State<FileAppBar> {
} else if (value == 10) {
final selectedFiles = SelectedFiles();
selectedFiles.files.add(widget.file);
- unawaited(
- showCollectionActionSheet(
- context,
- selectedFiles: selectedFiles,
- actionType: CollectionActionType.addFiles,
- ),
+ await showCollectionActionSheet(
+ context,
+ selectedFiles: selectedFiles,
+ actionType: CollectionActionType.addFiles,
);
}
}
@@ -617,12 +615,10 @@ class FileAppBarState extends State<FileAppBar> {
Future<void> _handleUnHideRequest(BuildContext context) async {
final selectedFiles = SelectedFiles();
selectedFiles.files.add(widget.file);
- unawaited(
- showCollectionActionSheet(
- context,
- selectedFiles: selectedFiles,
- actionType: CollectionActionType.unHide,
- ),
+ await showCollectionActionSheet(
+ context,
+ selectedFiles: selectedFiles,
+ actionType: CollectionActionType.unHide,
);
}
diff --git a/mobile/apps/photos/test/ui/social/file_social_context_test.dart b/mobile/apps/photos/test/ui/social/file_social_context_test.dart
deleted file mode 100644
index 573bcbddd6..0000000000
--- a/mobile/apps/photos/test/ui/social/file_social_context_test.dart
+++ /dev/null
@@ -1,12 +0,0 @@
-import "package:flutter_test/flutter_test.dart";
-import "package:photos/ui/social/widgets/file_social_overlay.dart";
-
-void main() {
- test("non-hidden opening context excludes hidden collections", () {
- expect(fileSocialContextIncludesHiddenCollections(10, {20}), isFalse);
- });
-
- test("hidden opening context includes all shared collections", () {
- expect(fileSocialContextIncludesHiddenCollections(20, {20}), isTrue);
- });
-}