π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add error handling for social interactions
ashilkn05979823621f
diff --git a/mobile/apps/photos/lib/models/social/social_data_provider.dart b/mobile/apps/photos/lib/models/social/social_data_provider.dartindex 68f381fc6a..53b1618be4 100644--- a/mobile/apps/photos/lib/models/social/social_data_provider.dart+++ b/mobile/apps/photos/lib/models/social/social_data_provider.dart@@ -107,7 +107,7 @@ class SocialDataProvider {/// Adds a comment via API, then stores locally.///- /// Returns the created Comment on success, null on failure.+ /// Returns the created Comment on success, throws on failure.Future<Comment?> addComment({required int collectionID,required String text,@@ -146,13 +146,13 @@ class SocialDataProvider {return comment;} catch (e) {_logger.severe('Failed to add comment', e);- return null;+ rethrow;}}/// Deletes a comment via API, then marks as deleted locally.///- /// Returns the deleted Comment on success, null on failure.+ /// Returns the deleted Comment on success, throws on failure.Future<Comment?> deleteComment(String id) async {try {// Call API@@ -162,7 +162,7 @@ class SocialDataProvider {return _db.deleteComment(id);} catch (e) {_logger.severe('Failed to delete comment $id', e);- return null;+ rethrow;}}@@ -234,7 +234,7 @@ class SocialDataProvider {}} catch (e) {_logger.severe('Failed to toggle reaction', e);- return null;+ rethrow;}}diff --git a/mobile/apps/photos/lib/ui/social/comments_screen.dart b/mobile/apps/photos/lib/ui/social/comments_screen.dartindex 97d4dda582..aecd580e44 100644--- a/mobile/apps/photos/lib/ui/social/comments_screen.dart+++ b/mobile/apps/photos/lib/ui/social/comments_screen.dart@@ -14,6 +14,7 @@ import "package:photos/models/social/social_data_provider.dart";import "package:photos/services/collections_service.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/components/buttons/icon_button_widget.dart";+import "package:photos/ui/notification/toast.dart";import "package:photos/ui/social/widgets/collection_selector_widget.dart";import "package:photos/ui/social/widgets/comment_bubble_widget.dart";import "package:photos/ui/social/widgets/comment_input_widget.dart";@@ -327,38 +328,47 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {final text = _textController.text.trim();if (text.isEmpty) return;- // Call API to create comment- final result = await SocialDataProvider.instance.addComment(- collectionID: _selectedCollectionID,- text: text,- fileID: widget.fileID,- parentCommentID: _replyingTo?.id,- );- if (result == null) {- _logger.warning('Failed to save comment');- return;- }+ try {+ final result = await SocialDataProvider.instance.addComment(+ collectionID: _selectedCollectionID,+ text: text,+ fileID: widget.fileID,+ parentCommentID: _replyingTo?.id,+ );+ if (result == null) {+ _logger.warning('Failed to save comment');+ if (mounted) {+ showShortToast(context, "Failed to send comment");+ }+ return;+ }- // Update UI only after successful persistence- if (mounted) {- setState(() {- _comments.insert(0, result);- _replyingTo = null;+ // Update UI only after successful persistence+ if (mounted) {+ setState(() {+ _comments.insert(0, result);+ _replyingTo = null;- // Update comment count in shared collections list- final index = _sharedCollections.indexWhere(- (c) => c.collection.id == _selectedCollectionID,- );- if (index != -1) {- final old = _sharedCollections[index];- _sharedCollections[index] = CollectionCommentInfo(- collection: old.collection,- commentCount: old.commentCount + 1,- thumbnail: old.thumbnail,+ // Update comment count in shared collections list+ final index = _sharedCollections.indexWhere(+ (c) => c.collection.id == _selectedCollectionID,);- }- });- _textController.clear();+ if (index != -1) {+ final old = _sharedCollections[index];+ _sharedCollections[index] = CollectionCommentInfo(+ collection: old.collection,+ commentCount: old.commentCount + 1,+ thumbnail: old.thumbnail,+ );+ }+ });+ _textController.clear();+ }+ } catch (e) {+ _logger.severe('Failed to send comment', e);+ if (mounted) {+ showShortToast(context, "Failed to send comment");+ }}}diff --git a/mobile/apps/photos/lib/ui/social/like_collection_selector_sheet.dart b/mobile/apps/photos/lib/ui/social/like_collection_selector_sheet.dartindex 22f783bda3..4247387318 100644--- a/mobile/apps/photos/lib/ui/social/like_collection_selector_sheet.dart+++ b/mobile/apps/photos/lib/ui/social/like_collection_selector_sheet.dart@@ -1,4 +1,5 @@import "package:flutter/material.dart";+import "package:logging/logging.dart";import "package:photos/core/constants.dart";import "package:photos/db/files_db.dart";import "package:photos/models/collection/collection.dart";@@ -11,6 +12,8 @@ import "package:photos/ui/components/buttons/icon_button_widget.dart";import "package:photos/ui/notification/toast.dart";import "package:photos/ui/viewer/file/thumbnail_widget.dart";+final _logger = Logger("LikeCollectionSelectorSheet");+const _greenHeartColor = Color(0xFF08C225);/// Holds collection info with mutable like state for the selector@@ -129,7 +132,7 @@ class _LikeCollectionSelectorSheetState_isLoading = false;});} catch (e, s) {- debugPrint("Error loading like selector data: $e\n$s");+ _logger.severe("Error loading like selector data", e, s);if (mounted) {setState(() {_hasError = true;@@ -151,11 +154,11 @@ class _LikeCollectionSelectorSheetStatefileID: widget.fileID,);} catch (e) {- // Revert on error+ _logger.severe("Failed to toggle like", e);if (mounted) {setState(() => state.isLiked = previousState);+ showShortToast(context, "Failed to update like");}- debugPrint("Failed to toggle like: $e");}}@@ -190,7 +193,7 @@ class _LikeCollectionSelectorSheetState);} catch (e) {failed.add(c);- debugPrint("Failed to like ${c.collection.displayName}: $e");+ _logger.severe("Failed to like ${c.collection.displayName}", e);}}),);diff --git a/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart b/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dartindex da3e27e9b2..86b3f687e2 100644--- a/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart+++ b/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart@@ -172,17 +172,26 @@ class _CommentBubbleWidgetState extends State<CommentBubbleWidget>}Future<void> _toggleLike() async {- // Optimistic update+ final previousState = _isLiked;setState(() => _isLiked = !_isLiked);- await SocialDataProvider.instance.toggleReaction(- userID: widget.currentUserID,- collectionID: widget.collectionID,- fileID: widget.comment.fileID,- commentID: widget.comment.id,- );+ try {+ await SocialDataProvider.instance.toggleReaction(+ userID: widget.currentUserID,+ collectionID: widget.collectionID,+ fileID: widget.comment.fileID,+ commentID: widget.comment.id,+ );+ } catch (e) {+ _logger.severe('Failed to toggle comment like', e);+ if (mounted) {+ setState(() => _isLiked = previousState);+ showShortToast(context, "Failed to like comment");+ }+ return;+ }- // Refresh reactions+ // Refresh reactions after successful toggle (best-effort, no rollback if fails)_reactions = await widget.onFetchReactions();if (mounted) setState(() {});}diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dartindex 68a99fab74..243ea716a4 100644--- a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart@@ -31,6 +31,8 @@ import "package:photos/utils/navigation_util.dart";import "package:photos/utils/panorama_util.dart";import "package:photos/utils/share_util.dart";+final _logger = Logger("FileBottomBar");+class FileBottomBar extends StatefulWidget {final EnteFile file;final Function(EnteFile) onFileRemoved;@@ -382,14 +384,25 @@ class FileBottomBarState extends State<FileBottomBar> {.getSharedCollectionCountForFile(file.uploadedFileID!);if (sharedCount <= 1) {- // Single shared collection: like directly (existing behavior)- await SocialDataProvider.instance.toggleReaction(- userID: widget.userID!,- collectionID: file.collectionID!,- fileID: file.uploadedFileID,- );+ // Single shared collection: like directly+ final previousState = _hasLiked;_hasLiked = true;safeRefresh();++ try {+ await SocialDataProvider.instance.toggleReaction(+ userID: widget.userID!,+ collectionID: file.collectionID!,+ fileID: file.uploadedFileID,+ );+ } catch (e) {+ _logger.severe("Failed to like photo", e);+ if (mounted) {+ _hasLiked = previousState;+ safeRefresh();+ showShortToast(context, "Failed to like photo");+ }+ }} else {// Multiple shared collections: show selector bottom sheetawait showLikeCollectionSelectorSheet(@@ -461,10 +474,7 @@ class FileBottomBarState extends State<FileBottomBar> {if (failedCount > 0 && mounted) {_hasLiked = previousState;safeRefresh();- final msg = failedCount == 1- ? "Failed to remove like from 1 album"- : "Failed to remove like from $failedCount albums";- showShortToast(context, msg);+ showShortToast(context, "Failed to unlike photo");}} catch (e) {// Rollback on error (e.g., fetching collections failed)