Skip to content

armgit / ente

Public Imported from GitHub
0

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

Create db for storing social states + show like button and comment icon on file's bottom bar and get like button working

ashilknf0186000ba65
diff --git a/mobile/apps/photos/lib/db/social_db.dart b/mobile/apps/photos/lib/db/social_db.dart
new file mode 100644
index 0000000000..cf7a4e2eac
--- /dev/null
+++ b/mobile/apps/photos/lib/db/social_db.dart
@@ -0,0 +1,372 @@
+import 'dart:async';
+import 'dart:io';
+
+import 'package:flutter/foundation.dart';
+import 'package:logging/logging.dart';
+import 'package:path/path.dart';
+import 'package:path_provider/path_provider.dart';
+import 'package:photos/models/social/comment.dart';
+import 'package:photos/models/social/reaction.dart';
+import 'package:sqflite/sqflite.dart';
+import 'package:uuid/uuid.dart';
+
+class SocialDB {
+ static final Logger _logger = Logger("SocialDB");
+ static const _databaseName = "ente.social.db";
+ static const _databaseVersion = 1;
+
+ static const commentsTable = 'comments';
+ static const reactionsTable = 'reactions';
+
+ SocialDB._privateConstructor();
+ static final SocialDB instance = SocialDB._privateConstructor();
+
+ static Future<Database>? _dbFuture;
+ Future<Database> get database async {
+ _dbFuture ??= _initDatabase();
+ return _dbFuture!;
+ }
+
+ Future<Database> _initDatabase() async {
+ final Directory documentsDirectory =
+ await getApplicationDocumentsDirectory();
+ final String path = join(documentsDirectory.path, _databaseName);
+ _logger.info("DB path: $path");
+ return await openDatabase(
+ path,
+ version: _databaseVersion,
+ onCreate: _onCreate,
+ );
+ }
+
+ Future _onCreate(Database db, int version) async {
+ await db.execute('''
+ CREATE TABLE $commentsTable (
+ id TEXT PRIMARY KEY NOT NULL,
+ collection_id INTEGER NOT NULL,
+ file_id INTEGER,
+ data TEXT NOT NULL,
+ parent_comment_id TEXT,
+ is_deleted INTEGER NOT NULL DEFAULT 0,
+ user_id INTEGER NOT NULL,
+ anon_user_id TEXT,
+ created_at INTEGER NOT NULL,
+ updated_at INTEGER NOT NULL
+ )
+ ''');
+
+ await db.execute('''
+ CREATE TABLE $reactionsTable (
+ id TEXT PRIMARY KEY NOT NULL,
+ collection_id INTEGER NOT NULL,
+ file_id INTEGER,
+ comment_id TEXT,
+ data TEXT NOT NULL,
+ is_deleted INTEGER NOT NULL DEFAULT 0,
+ user_id INTEGER NOT NULL,
+ anon_user_id TEXT,
+ created_at INTEGER NOT NULL,
+ updated_at INTEGER NOT NULL
+ )
+ ''');
+ }
+
+ // Comment methods
+
+ Future<Comment?> addComment(Comment comment) async {
+ if (comment.data.trim().isEmpty) {
+ debugPrint('addComment: Cannot add comment with empty data');
+ return null;
+ }
+
+ if (comment.parentCommentID != null) {
+ final parentExists = await _commentExists(comment.parentCommentID!);
+ if (!parentExists) {
+ debugPrint(
+ 'addComment: Parent comment ${comment.parentCommentID} does not exist',
+ );
+ return null;
+ }
+ }
+
+ final db = await database;
+ await db.insert(
+ commentsTable,
+ _commentToRow(comment),
+ conflictAlgorithm: ConflictAlgorithm.replace,
+ );
+ return comment;
+ }
+
+ Future<Comment?> deleteComment(String id) async {
+ final db = await database;
+ final rows = await db.query(
+ commentsTable,
+ where: 'id = ?',
+ whereArgs: [id],
+ );
+
+ if (rows.isEmpty) {
+ debugPrint('deleteComment: Comment $id does not exist');
+ return null;
+ }
+
+ final updatedAt = DateTime.now().millisecondsSinceEpoch;
+ await db.update(
+ commentsTable,
+ {'is_deleted': 1, 'updated_at': updatedAt},
+ where: 'id = ?',
+ whereArgs: [id],
+ );
+
+ final updatedRows = await db.query(
+ commentsTable,
+ where: 'id = ?',
+ whereArgs: [id],
+ );
+ return _rowToComment(updatedRows.first);
+ }
+
+ Future<List<Comment>> getCommentsForFile(int fileID) async {
+ final db = await database;
+ final rows = await db.query(
+ commentsTable,
+ where: 'file_id = ? AND is_deleted = 0',
+ whereArgs: [fileID],
+ );
+ return rows.map(_rowToComment).toList();
+ }
+
+ Future<int> getCommentCountForFile(int fileID) async {
+ final comments = await getCommentsForFile(fileID);
+ return comments.length;
+ }
+
+ Future<List<Comment>> getCommentsForCollection(int collectionID) async {
+ final db = await database;
+ final rows = await db.query(
+ commentsTable,
+ where: 'collection_id = ? AND file_id IS NULL AND is_deleted = 0',
+ whereArgs: [collectionID],
+ );
+ return rows.map(_rowToComment).toList();
+ }
+
+ Future<List<Comment>> getRepliesForComment(String commentID) async {
+ final db = await database;
+ final rows = await db.query(
+ commentsTable,
+ where: 'parent_comment_id = ? AND is_deleted = 0',
+ whereArgs: [commentID],
+ );
+ return rows.map(_rowToComment).toList();
+ }
+
+ // Reaction methods
+
+ Future<Reaction?> addReaction(Reaction reaction) async {
+ if (reaction.commentID != null) {
+ final commentExists = await _commentExists(reaction.commentID!);
+ if (!commentExists) {
+ debugPrint(
+ 'addReaction: Comment ${reaction.commentID} does not exist',
+ );
+ return null;
+ }
+ }
+
+ final db = await database;
+ await db.insert(
+ reactionsTable,
+ _reactionToRow(reaction),
+ conflictAlgorithm: ConflictAlgorithm.replace,
+ );
+ return reaction;
+ }
+
+ Future<Reaction?> toggleReaction({
+ required int userID,
+ required int collectionID,
+ int? fileID,
+ String? commentID,
+ }) async {
+ final existingReaction = await _findExistingReaction(
+ userID: userID,
+ collectionID: collectionID,
+ fileID: fileID,
+ commentID: commentID,
+ );
+
+ if (existingReaction != null) {
+ // Toggle is_deleted on existing reaction
+ final db = await database;
+ final updatedAt = DateTime.now().millisecondsSinceEpoch;
+ final newIsDeleted = existingReaction.isDeleted ? 0 : 1;
+
+ await db.update(
+ reactionsTable,
+ {'is_deleted': newIsDeleted, 'updated_at': updatedAt},
+ where: 'id = ?',
+ whereArgs: [existingReaction.id],
+ );
+
+ final updatedRows = await db.query(
+ reactionsTable,
+ where: 'id = ?',
+ whereArgs: [existingReaction.id],
+ );
+ return _rowToReaction(updatedRows.first);
+ } else {
+ // Create new reaction
+ final now = DateTime.now().millisecondsSinceEpoch;
+ final reaction = Reaction(
+ id: const Uuid().v4(),
+ collectionID: collectionID,
+ fileID: fileID,
+ commentID: commentID,
+ data: '',
+ userID: userID,
+ createdAt: now,
+ updatedAt: now,
+ );
+ return addReaction(reaction);
+ }
+ }
+
+ Future<List<Reaction>> getReactionsForFile(int fileID) async {
+ final db = await database;
+ final rows = await db.query(
+ reactionsTable,
+ where: 'file_id = ? AND comment_id IS NULL AND is_deleted = 0',
+ whereArgs: [fileID],
+ );
+ return rows.map(_rowToReaction).toList();
+ }
+
+ Future<List<Reaction>> getReactionsForComment(String commentID) async {
+ final db = await database;
+ final rows = await db.query(
+ reactionsTable,
+ where: 'comment_id = ? AND is_deleted = 0',
+ whereArgs: [commentID],
+ );
+ return rows.map(_rowToReaction).toList();
+ }
+
+ Future<List<Reaction>> getReactionsForCollection(int collectionID) async {
+ final db = await database;
+ final rows = await db.query(
+ reactionsTable,
+ where:
+ 'collection_id = ? AND file_id IS NULL AND comment_id IS NULL AND is_deleted = 0',
+ whereArgs: [collectionID],
+ );
+ return rows.map(_rowToReaction).toList();
+ }
+
+ // Helper methods
+
+ Future<bool> _commentExists(String id) async {
+ final db = await database;
+ final rows = await db.query(
+ commentsTable,
+ where: 'id = ?',
+ whereArgs: [id],
+ );
+ return rows.isNotEmpty;
+ }
+
+ Future<Reaction?> _findExistingReaction({
+ required int userID,
+ required int collectionID,
+ int? fileID,
+ String? commentID,
+ }) async {
+ final db = await database;
+ String where;
+ List<Object?> whereArgs;
+
+ if (commentID != null) {
+ where = 'user_id = ? AND comment_id = ?';
+ whereArgs = [userID, commentID];
+ } else if (fileID != null) {
+ where = 'user_id = ? AND file_id = ? AND comment_id IS NULL';
+ whereArgs = [userID, fileID];
+ } else {
+ where =
+ 'user_id = ? AND collection_id = ? AND file_id IS NULL AND comment_id IS NULL';
+ whereArgs = [userID, collectionID];
+ }
+
+ final rows = await db.query(
+ reactionsTable,
+ where: where,
+ whereArgs: whereArgs,
+ );
+
+ if (rows.isEmpty) return null;
+ return _rowToReaction(rows.first);
+ }
+
+ Map<String, dynamic> _commentToRow(Comment comment) {
+ final map = comment.toMap();
+ return {
+ 'id': map['id'],
+ 'collection_id': map['collectionID'],
+ 'file_id': map['fileID'],
+ 'data': map['data'],
+ 'parent_comment_id': map['parentCommentID'],
+ 'is_deleted': map['isDeleted'] == true ? 1 : 0,
+ 'user_id': map['userID'],
+ 'anon_user_id': map['anonUserID'],
+ 'created_at': map['createdAt'],
+ 'updated_at': map['updatedAt'],
+ };
+ }
+
+ Comment _rowToComment(Map<String, dynamic> row) {
+ return Comment.fromMap({
+ 'id': row['id'],
+ 'collectionID': row['collection_id'],
+ 'fileID': row['file_id'],
+ 'data': row['data'],
+ 'parentCommentID': row['parent_comment_id'],
+ 'isDeleted': row['is_deleted'] == 1,
+ 'userID': row['user_id'],
+ 'anonUserID': row['anon_user_id'],
+ 'createdAt': row['created_at'],
+ 'updatedAt': row['updated_at'],
+ });
+ }
+
+ Map<String, dynamic> _reactionToRow(Reaction reaction) {
+ final map = reaction.toMap();
+ return {
+ 'id': map['id'],
+ 'collection_id': map['collectionID'],
+ 'file_id': map['fileID'],
+ 'comment_id': map['commentID'],
+ 'data': map['data'],
+ 'is_deleted': map['isDeleted'] == true ? 1 : 0,
+ 'user_id': map['userID'],
+ 'anon_user_id': map['anonUserID'],
+ 'created_at': map['createdAt'],
+ 'updated_at': map['updatedAt'],
+ };
+ }
+
+ Reaction _rowToReaction(Map<String, dynamic> row) {
+ return Reaction.fromMap({
+ 'id': row['id'],
+ 'collectionID': row['collection_id'],
+ 'fileID': row['file_id'],
+ 'commentID': row['comment_id'],
+ 'data': row['data'],
+ 'isDeleted': row['is_deleted'] == 1,
+ 'userID': row['user_id'],
+ 'anonUserID': row['anon_user_id'],
+ 'createdAt': row['created_at'],
+ 'updatedAt': row['updated_at'],
+ });
+ }
+}
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 6a5b3b6686..ad88dfa25c 100644
--- a/mobile/apps/photos/lib/models/social/social_data_provider.dart
+++ b/mobile/apps/photos/lib/models/social/social_data_provider.dart
@@ -1,4 +1,4 @@
-import "package:flutter/foundation.dart";
+import "package:photos/db/social_db.dart";
import "package:photos/models/social/comment.dart";
import "package:photos/models/social/reaction.dart";
@@ -6,164 +6,63 @@ class SocialDataProvider {
SocialDataProvider._();
static final instance = SocialDataProvider._();
- // Dummy data maps - add your test data here
- // Key: comment/reaction ID
- final Map<String, Comment> _comments = {
- // Example:
- // 'comment-1': Comment(
- // id: 'comment-1',
- // collectionID: 1,
- // fileID: 100,
- // data: 'Nice photo!',
- // userID: 1,
- // createdAt: 1700000000,
- // updatedAt: 1700000000,
- // ),
- };
-
- final Map<String, Reaction> _reactions = {
- // Example:
- // 'reaction-1': Reaction(
- // id: 'reaction-1',
- // collectionID: 1,
- // fileID: 100,
- // data: '',
- // userID: 1,
- // createdAt: 1700000000,
- // updatedAt: 1700000000,
- // ),
- };
+ final _db = SocialDB.instance;
// Query methods
- List<Comment> getCommentsForFile(int fileID) {
- return _comments.values
- .where((c) => c.fileID == fileID && !c.isDeleted)
- .toList();
+ Future<List<Comment>> getCommentsForFile(int fileID) {
+ return _db.getCommentsForFile(fileID);
}
- List<Reaction> getReactionsForFile(int fileID) {
- return _reactions.values
- .where((r) => r.fileID == fileID && r.commentID == null && !r.isDeleted)
- .toList();
+ Future<int> getCommentCountForFile(int fileID) {
+ return _db.getCommentCountForFile(fileID);
}
- List<Comment> getRepliesForComment(String commentID) {
- return _comments.values
- .where((c) => c.parentCommentID == commentID && !c.isDeleted)
- .toList();
+ Future<List<Reaction>> getReactionsForFile(int fileID) {
+ return _db.getReactionsForFile(fileID);
}
- List<Reaction> getReactionsForComment(String commentID) {
- return _reactions.values
- .where((r) => r.commentID == commentID && !r.isDeleted)
- .toList();
+ Future<List<Comment>> getRepliesForComment(String commentID) {
+ return _db.getRepliesForComment(commentID);
+ }
+
+ Future<List<Reaction>> getReactionsForComment(String commentID) {
+ return _db.getReactionsForComment(commentID);
}
// Collection-level queries
- List<Comment> getCommentsForCollection(int collectionID) {
- return _comments.values
- .where(
- (c) =>
- c.collectionID == collectionID &&
- c.fileID == null &&
- !c.isDeleted,
- )
- .toList();
+ Future<List<Comment>> getCommentsForCollection(int collectionID) {
+ return _db.getCommentsForCollection(collectionID);
}
- List<Reaction> getReactionsForCollection(int collectionID) {
- return _reactions.values
- .where(
- (r) =>
- r.collectionID == collectionID &&
- r.fileID == null &&
- r.commentID == null &&
- !r.isDeleted,
- )
- .toList();
+ Future<List<Reaction>> getReactionsForCollection(int collectionID) {
+ return _db.getReactionsForCollection(collectionID);
}
// Comment mutation methods
- Comment? addComment(Comment comment) {
- if (comment.data.trim().isEmpty) {
- debugPrint('addComment: Cannot add comment with empty data');
- return null;
- }
- if (comment.parentCommentID != null &&
- !_comments.containsKey(comment.parentCommentID)) {
- debugPrint(
- 'addComment: Parent comment ${comment.parentCommentID} does not exist',
- );
- return null;
- }
- _comments[comment.id] = comment;
- return comment;
+ Future<Comment?> addComment(Comment comment) {
+ return _db.addComment(comment);
}
- Comment? deleteComment(String id) {
- final existing = _comments[id];
- if (existing == null) {
- debugPrint('deleteComment: Comment $id does not exist');
- return null;
- }
- final updated = existing.copyWith(
- isDeleted: true,
- updatedAt: DateTime.now().millisecondsSinceEpoch,
- );
- _comments[id] = updated;
- return updated;
+ Future<Comment?> deleteComment(String id) {
+ return _db.deleteComment(id);
}
// Reaction mutation methods
- Reaction? addReaction(Reaction reaction) {
- // Validate comment exists if reacting to a comment
- if (reaction.commentID != null &&
- !_comments.containsKey(reaction.commentID)) {
- debugPrint(
- 'addReaction: Comment ${reaction.commentID} does not exist',
- );
- return null;
- }
-
- // Check if reaction already exists for same user + target
- final existing = _reactions.values.where((r) {
- if (r.userID != reaction.userID) return false;
- if (reaction.commentID != null) {
- return r.commentID == reaction.commentID;
- }
- if (reaction.fileID != null) {
- return r.fileID == reaction.fileID && r.commentID == null;
- }
- return r.collectionID == reaction.collectionID &&
- r.fileID == null &&
- r.commentID == null;
- }).firstOrNull;
-
- if (existing != null) {
- debugPrint(
- 'addReaction: Reaction already exists for user ${reaction.userID} on target',
- );
- return null;
- }
- _reactions[reaction.id] = reaction;
- return reaction;
- }
-
- Reaction? toggleReaction(String id) {
- final existing = _reactions[id];
- if (existing == null) {
- debugPrint('toggleReaction: Reaction $id does not exist');
- return null;
- }
- final updated = existing.copyWith(
- isDeleted: !existing.isDeleted,
- updatedAt: DateTime.now().millisecondsSinceEpoch,
+ Future<Reaction?> toggleReaction({
+ required int userID,
+ required int collectionID,
+ int? fileID,
+ String? commentID,
+ }) {
+ return _db.toggleReaction(
+ userID: userID,
+ collectionID: collectionID,
+ fileID: fileID,
+ commentID: commentID,
);
- _reactions[id] = updated;
- return updated;
}
}
diff --git a/mobile/apps/photos/lib/services/collections_service.dart b/mobile/apps/photos/lib/services/collections_service.dart
index 161f845ba4..e0045d24c8 100644
--- a/mobile/apps/photos/lib/services/collections_service.dart
+++ b/mobile/apps/photos/lib/services/collections_service.dart
@@ -234,6 +234,40 @@ class CollectionsService {
return true;
}
+ /// Returns true if the file exists in any shared collection.
+ ///
+ /// A collection is considered "shared" if it has sharees, has a public link,
+ /// or is owned by someone else (incoming share).
+ Future<bool> isFileInSharedCollection(int uploadedFileID) async {
+ final Set<int> collectionIDs =
+ await _filesDB.getAllCollectionIDsOfFile(uploadedFileID);
+
+ if (collectionIDs.isEmpty) {
+ return false;
+ }
+
+ final int? currentUserID = _config.getUserID();
+ if (currentUserID == null) {
+ return false;
+ }
+
+ for (final int collectionID in collectionIDs) {
+ final Collection? collection = _collectionIDToCollections[collectionID];
+
+ if (collection == null || collection.isDeleted) {
+ continue;
+ }
+
+ if (collection.hasSharees ||
+ collection.hasLink ||
+ !collection.isOwner(currentUserID)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
Future<List<Collection>> getArchivedCollection() async {
final allCollections = getCollectionsForUI();
return allCollections
@@ -2213,9 +2247,21 @@ class CollectionsService {
}
await _filesDB.removeFromCollection(collectionID, params["fileIDs"]);
- Bus.instance
- .fire(CollectionUpdatedEvent(collectionID, batch, "removeFrom", type: EventType.deletedFromRemote,));
- Bus.instance.fire(LocalPhotosUpdatedEvent(batch, source: "removeFrom", type: EventType.deletedFromRemote,));
+ Bus.instance.fire(
+ CollectionUpdatedEvent(
+ collectionID,
+ batch,
+ "removeFrom",
+ type: EventType.deletedFromRemote,
+ ),
+ );
+ Bus.instance.fire(
+ LocalPhotosUpdatedEvent(
+ batch,
+ source: "removeFrom",
+ type: EventType.deletedFromRemote,
+ ),
+ );
}
RemoteSyncService.instance.sync(silently: true).ignore();
}
@@ -2250,7 +2296,13 @@ class CollectionsService {
type: EventType.deletedFromRemote,
),
);
- Bus.instance.fire(LocalPhotosUpdatedEvent(files, source: "suggestDelete", type: EventType.deletedFromRemote,));
+ Bus.instance.fire(
+ LocalPhotosUpdatedEvent(
+ files,
+ source: "suggestDelete",
+ type: EventType.deletedFromRemote,
+ ),
+ );
RemoteSyncService.instance.sync(silently: true).ignore();
}
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.dart
index 2befca8b74..873eae87ce 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
@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
+import "package:hugeicons/hugeicons.dart";
import "package:logging/logging.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/guest_view_event.dart";
@@ -11,6 +12,9 @@ import "package:photos/models/file/extensions/file_props.dart";
import 'package:photos/models/file/file.dart';
import 'package:photos/models/file/trash_file.dart';
import 'package:photos/models/selected_files.dart';
+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/actions/file/file_actions.dart";
import 'package:photos/ui/collections/collection_action_sheet.dart';
import 'package:photos/utils/delete_file_util.dart';
@@ -42,10 +46,15 @@ class FileBottomBarState extends State<FileBottomBar> {
bool isGuestView = false;
late final StreamSubscription<GuestViewEvent> _guestViewEventSubscription;
int? lastFileGenID;
+ Future<bool>? _isFileInSharedCollectionFuture;
+ bool _hasLiked = false;
+ int _commentCount = 0;
@override
void initState() {
super.initState();
+ _updateSharedCollectionFuture();
+ _updateSocialState();
_guestViewEventSubscription =
Bus.instance.on<GuestViewEvent>().listen((event) {
setState(() {
@@ -54,6 +63,48 @@ class FileBottomBarState extends State<FileBottomBar> {
});
}
+ @override
+ void didUpdateWidget(FileBottomBar oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (oldWidget.file.uploadedFileID != widget.file.uploadedFileID) {
+ _updateSharedCollectionFuture();
+ _updateSocialState();
+ }
+ }
+
+ void _updateSharedCollectionFuture() {
+ if (widget.file.uploadedFileID != null) {
+ _isFileInSharedCollectionFuture =
+ CollectionsService.instance.isFileInSharedCollection(
+ widget.file.uploadedFileID!,
+ );
+ } else {
+ _isFileInSharedCollectionFuture = null;
+ }
+ }
+
+ Future<void> _updateSocialState() async {
+ if (widget.file.uploadedFileID == null) {
+ _hasLiked = false;
+ _commentCount = 0;
+ return;
+ }
+
+ final fileID = widget.file.uploadedFileID!;
+ final provider = SocialDataProvider.instance;
+
+ // Check if user has liked
+ final reactions = await provider.getReactionsForFile(fileID);
+ _hasLiked = reactions.any(
+ (r) => r.userID == widget.userID && !r.isDeleted,
+ );
+
+ // Get comment count
+ _commentCount = await provider.getCommentCountForFile(fileID);
+
+ safeRefresh();
+ }
+
@override
void dispose() {
_guestViewEventSubscription.cancel();
@@ -132,6 +183,12 @@ class FileBottomBarState extends State<FileBottomBar> {
),
),
);
+
+ // Add social icons (heart, comment) if file is in a shared collection
+ if (widget.file.uploadedFileID != null) {
+ children.add(_buildHeartIcon());
+ children.add(_buildCommentIcon());
+ }
}
return ValueListenableBuilder(
valueListenable: widget.enableFullScreenNotifier,
@@ -230,4 +287,111 @@ class FileBottomBarState extends State<FileBottomBar> {
),
);
}
+
+ Widget _buildHeartIcon() {
+ if (_isFileInSharedCollectionFuture == null) {
+ return const SizedBox.shrink();
+ }
+
+ return FutureBuilder<bool>(
+ future: _isFileInSharedCollectionFuture,
+ builder: (context, snapshot) {
+ if (snapshot.data != true) {
+ return const SizedBox.shrink();
+ }
+
+ return Padding(
+ padding: const EdgeInsets.only(top: 12),
+ child: GestureDetector(
+ onTap: _toggleReaction,
+ child: Icon(
+ _hasLiked
+ ? (Platform.isAndroid
+ ? Icons.favorite
+ : Icons.favorite_rounded)
+ : (Platform.isAndroid
+ ? Icons.favorite_border
+ : Icons.favorite_border_rounded),
+ color: _hasLiked
+ ? getEnteColorScheme(context).primary700
+ : Colors.white,
+ ),
+ ),
+ );
+ },
+ );
+ }
+
+ Future<void> _toggleReaction() async {
+ final file = widget.file;
+ if (file.uploadedFileID == null ||
+ file.collectionID == null ||
+ widget.userID == null) {
+ return;
+ }
+
+ await SocialDataProvider.instance.toggleReaction(
+ userID: widget.userID!,
+ collectionID: file.collectionID!,
+ fileID: file.uploadedFileID,
+ );
+
+ _hasLiked = !_hasLiked;
+ safeRefresh();
+ }
+
+ Widget _buildCommentIcon() {
+ if (_isFileInSharedCollectionFuture == null) {
+ return const SizedBox.shrink();
+ }
+
+ return FutureBuilder<bool>(
+ future: _isFileInSharedCollectionFuture,
+ builder: (context, snapshot) {
+ if (snapshot.data != true) {
+ return const SizedBox.shrink();
+ }
+
+ return Padding(
+ padding: const EdgeInsets.only(top: 12),
+ child: Stack(
+ clipBehavior: Clip.none,
+ children: [
+ const HugeIcon(
+ icon: HugeIcons.strokeRoundedBubbleChat,
+ color: Colors.white,
+ ),
+ if (_commentCount > 0)
+ Positioned(
+ right: -4,
+ top: -4,
+ child: Container(
+ padding:
+ const EdgeInsets.symmetric(horizontal: 4, vertical: 1),
+ decoration: BoxDecoration(
+ color: Colors.white,
+ borderRadius: const BorderRadius.all(Radius.circular(16)),
+ border: Border.all(
+ color: Colors.black,
+ width: 2,
+ strokeAlign: BorderSide.strokeAlignOutside,
+ ),
+ ),
+ child: Text(
+ _commentCount > 99 ? '99+' : _commentCount.toString(),
+ style: const TextStyle(
+ color: Colors.black,
+ fontSize: 8,
+ fontWeight: FontWeight.w500,
+ ),
+ textAlign: TextAlign.center,
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ },
+ );
+ }
}