π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add comments screen (dummy UI) with pagination
ashilknac708233e15d
diff --git a/mobile/apps/photos/lib/models/social/social_data_provider.dart b/mobile/apps/photos/lib/models/social/social_data_provider.dartindex ad88dfa25c..88453f7ae2 100644--- a/mobile/apps/photos/lib/models/social/social_data_provider.dart+++ b/mobile/apps/photos/lib/models/social/social_data_provider.dart@@ -30,6 +30,34 @@ class SocialDataProvider {return _db.getReactionsForComment(commentID);}+ Future<Comment?> getCommentById(String id) {+ return _db.getCommentById(id);+ }++ Future<List<Comment>> getCommentsForFilePaginated(+ int fileID, {+ int limit = 20,+ int offset = 0,+ }) {+ return _db.getCommentsForFilePaginated(+ fileID,+ limit: limit,+ offset: offset,+ );+ }++ Future<List<Comment>> getCommentsForCollectionPaginated(+ int collectionID, {+ int limit = 20,+ int offset = 0,+ }) {+ return _db.getCommentsForCollectionPaginated(+ collectionID,+ limit: limit,+ offset: offset,+ );+ }+// Collection-level queriesFuture<List<Comment>> getCommentsForCollection(int collectionID) {diff --git a/mobile/apps/photos/lib/ui/social/comments_screen.dart b/mobile/apps/photos/lib/ui/social/comments_screen.dartnew file mode 100644index 0000000000..285271add7--- /dev/null+++ b/mobile/apps/photos/lib/ui/social/comments_screen.dart@@ -0,0 +1,221 @@+import "package:flutter/material.dart";+import "package:photos/core/configuration.dart";+import "package:photos/models/social/comment.dart";+import "package:photos/models/social/reaction.dart";+import "package:photos/models/social/social_data_provider.dart";+import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/social/widgets/comment_bubble_widget.dart";+import "package:photos/ui/social/widgets/comment_input_widget.dart";+import "package:uuid/uuid.dart";++class CommentsScreen extends StatefulWidget {+ final int collectionID;+ final int? fileID;++ const CommentsScreen({+ required this.collectionID,+ this.fileID,+ super.key,+ });++ @override+ State<CommentsScreen> createState() => _CommentsScreenState();+}++class _CommentsScreenState extends State<CommentsScreen> {+ final List<Comment> _comments = [];++ Comment? _replyingTo;+ bool _isLoading = true;+ bool _isLoadingMore = false;+ bool _hasMoreComments = true;+ int _offset = 0;++ late final TextEditingController _textController;+ late final FocusNode _inputFocusNode;+ late final ScrollController _scrollController;+ late final int _currentUserID;++ static const int _pageSize = 20;++ @override+ void initState() {+ super.initState();+ _textController = TextEditingController();+ _inputFocusNode = FocusNode();+ _scrollController = ScrollController()..addListener(_onScroll);+ _currentUserID = Configuration.instance.getUserID()!;+ _loadInitialComments();+ }++ @override+ void dispose() {+ _textController.dispose();+ _inputFocusNode.dispose();+ _scrollController.dispose();+ super.dispose();+ }++ Future<void> _loadInitialComments() async {+ setState(() => _isLoading = true);++ final comments = widget.fileID != null+ ? await SocialDataProvider.instance.getCommentsForFilePaginated(+ widget.fileID!,+ limit: _pageSize,+ offset: 0,+ )+ : await SocialDataProvider.instance.getCommentsForCollectionPaginated(+ widget.collectionID,+ limit: _pageSize,+ offset: 0,+ );++ setState(() {+ _comments.addAll(comments);+ _offset = comments.length;+ _hasMoreComments = comments.length == _pageSize;+ _isLoading = false;+ });+ }++ Future<void> _loadMoreComments() async {+ if (_isLoadingMore || !_hasMoreComments) return;++ setState(() => _isLoadingMore = true);++ final comments = widget.fileID != null+ ? await SocialDataProvider.instance.getCommentsForFilePaginated(+ widget.fileID!,+ limit: _pageSize,+ offset: _offset,+ )+ : await SocialDataProvider.instance.getCommentsForCollectionPaginated(+ widget.collectionID,+ limit: _pageSize,+ offset: _offset,+ );++ setState(() {+ _comments.addAll(comments);+ _offset += comments.length;+ _hasMoreComments = comments.length == _pageSize;+ _isLoadingMore = false;+ });+ }++ void _onScroll() {+ if (_scrollController.position.pixels >=+ _scrollController.position.maxScrollExtent - 200) {+ _loadMoreComments();+ }+ }++ Future<Comment?> _getParentComment(String parentCommentId) {+ return SocialDataProvider.instance.getCommentById(parentCommentId);+ }++ Future<List<Reaction>> _getReactionsForComment(String commentId) {+ return SocialDataProvider.instance.getReactionsForComment(commentId);+ }++ void _onReplyTap(Comment comment) {+ setState(() => _replyingTo = comment);+ _inputFocusNode.requestFocus();+ }++ void _dismissReply() {+ setState(() => _replyingTo = null);+ }++ Future<void> _sendComment() async {+ final text = _textController.text.trim();+ if (text.isEmpty) return;++ final now = DateTime.now().millisecondsSinceEpoch;+ final newComment = Comment(+ id: const Uuid().v4(),+ collectionID: widget.collectionID,+ fileID: widget.fileID,+ data: text,+ parentCommentID: _replyingTo?.id,+ userID: _currentUserID,+ createdAt: now,+ updatedAt: now,+ );++ // Optimistic update+ setState(() {+ _comments.insert(0, newComment);+ _replyingTo = null;+ });+ _textController.clear();++ // Persist+ await SocialDataProvider.instance.addComment(newComment);+ }++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ final textTheme = getEnteTextTheme(context);++ return Scaffold(+ appBar: AppBar(+ leading: IconButton(+ icon: const Icon(Icons.close),+ onPressed: () => Navigator.of(context).pop(),+ ),+ title: Text(+ "${_comments.length} comments",+ style: textTheme.body,+ ),+ backgroundColor: colorScheme.backgroundBase,+ elevation: 0,+ ),+ body: Column(+ children: [+ Expanded(+ child: _isLoading+ ? const Center(child: CircularProgressIndicator())+ : ListView.builder(+ controller: _scrollController,+ reverse: true,+ itemCount: _comments.length + (_hasMoreComments ? 1 : 0),+ itemBuilder: (context, index) {+ if (index == _comments.length) {+ return const Center(+ child: Padding(+ padding: EdgeInsets.all(16),+ child: CircularProgressIndicator(),+ ),+ );+ }+ final comment = _comments[index];+ return CommentBubbleWidget(+ comment: comment,+ isOwnComment: comment.userID == _currentUserID,+ currentUserID: _currentUserID,+ collectionID: widget.collectionID,+ onFetchParent: comment.isReply+ ? () => _getParentComment(comment.parentCommentID!)+ : null,+ onFetchReactions: () =>+ _getReactionsForComment(comment.id),+ onReplyTap: () => _onReplyTap(comment),+ );+ },+ ),+ ),+ CommentInputWidget(+ replyingTo: _replyingTo,+ onDismissReply: _dismissReply,+ controller: _textController,+ focusNode: _inputFocusNode,+ onSend: _sendComment,+ ),+ ],+ ),+ );+ }+}diff --git a/mobile/apps/photos/lib/ui/social/widgets/comment_actions_capsule.dart b/mobile/apps/photos/lib/ui/social/widgets/comment_actions_capsule.dartnew file mode 100644index 0000000000..8205ab3fdf--- /dev/null+++ b/mobile/apps/photos/lib/ui/social/widgets/comment_actions_capsule.dart@@ -0,0 +1,67 @@+import "package:flutter/material.dart";+import "package:photos/theme/ente_theme.dart";++class CommentActionsCapsule extends StatelessWidget {+ final bool isLiked;+ final int likeCount;+ final VoidCallback onLikeTap;+ final VoidCallback onReplyTap;++ const CommentActionsCapsule({+ required this.isLiked,+ required this.likeCount,+ required this.onLikeTap,+ required this.onReplyTap,+ super.key,+ });++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ final textTheme = getEnteTextTheme(context);++ return Container(+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),+ decoration: BoxDecoration(+ color: colorScheme.fillFaint,+ borderRadius: BorderRadius.circular(16),+ ),+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ GestureDetector(+ onTap: onLikeTap,+ child: Row(+ children: [+ Icon(+ isLiked ? Icons.favorite : Icons.favorite_border,+ size: 16,+ color:+ isLiked ? colorScheme.primary500 : colorScheme.textMuted,+ ),+ if (likeCount > 0) ...[+ const SizedBox(width: 2),+ Text(+ likeCount.toString(),+ style: textTheme.mini.copyWith(+ color: colorScheme.textMuted,+ ),+ ),+ ],+ ],+ ),+ ),+ const SizedBox(width: 12),+ GestureDetector(+ onTap: onReplyTap,+ child: Icon(+ Icons.reply,+ size: 16,+ color: colorScheme.textMuted,+ ),+ ),+ ],+ ),+ );+ }+}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.dartnew file mode 100644index 0000000000..7e93f28a76--- /dev/null+++ b/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart@@ -0,0 +1,184 @@+import "package:flutter/material.dart";+import "package:photos/models/social/comment.dart";+import "package:photos/models/social/reaction.dart";+import "package:photos/models/social/social_data_provider.dart";+import "package:photos/theme/colors.dart";+import "package:photos/theme/ente_theme.dart";+import "package:photos/theme/text_style.dart";+import "package:photos/ui/social/widgets/comment_actions_capsule.dart";+import "package:photos/utils/social/relative_time_formatter.dart";++class CommentBubbleWidget extends StatefulWidget {+ final Comment comment;+ final bool isOwnComment;+ final int currentUserID;+ final int collectionID;+ final Future<Comment?> Function()? onFetchParent;+ final Future<List<Reaction>> Function() onFetchReactions;+ final VoidCallback onReplyTap;++ const CommentBubbleWidget({+ required this.comment,+ required this.isOwnComment,+ required this.currentUserID,+ required this.collectionID,+ this.onFetchParent,+ required this.onFetchReactions,+ required this.onReplyTap,+ super.key,+ });++ @override+ State<CommentBubbleWidget> createState() => _CommentBubbleWidgetState();+}++class _CommentBubbleWidgetState extends State<CommentBubbleWidget> {+ Comment? _parentComment;+ List<Reaction> _reactions = [];+ bool _isLiked = false;+ bool _isLoadingParent = false;+ bool _isLoadingReactions = false;++ @override+ void initState() {+ super.initState();+ _loadData();+ }++ Future<void> _loadData() async {+ // Load parent if reply+ if (widget.comment.isReply && widget.onFetchParent != null) {+ setState(() => _isLoadingParent = true);+ _parentComment = await widget.onFetchParent!();+ if (mounted) setState(() => _isLoadingParent = false);+ }++ // Load reactions+ setState(() => _isLoadingReactions = true);+ _reactions = await widget.onFetchReactions();+ _isLiked = _reactions.any(+ (r) => r.userID == widget.currentUserID && !r.isDeleted,+ );+ if (mounted) setState(() => _isLoadingReactions = false);+ }++ Future<void> _toggleLike() async {+ // Optimistic update+ setState(() => _isLiked = !_isLiked);++ await SocialDataProvider.instance.toggleReaction(+ userID: widget.currentUserID,+ collectionID: widget.collectionID,+ commentID: widget.comment.id,+ );++ // Refresh reactions+ _reactions = await widget.onFetchReactions();+ if (mounted) setState(() {});+ }++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ final textTheme = getEnteTextTheme(context);++ return Padding(+ padding: EdgeInsets.only(+ left: widget.isOwnComment ? 48 : 16,+ right: widget.isOwnComment ? 16 : 48,+ top: 8,+ bottom: 8,+ ),+ child: Column(+ crossAxisAlignment: widget.isOwnComment+ ? CrossAxisAlignment.end+ : CrossAxisAlignment.start,+ children: [+ // Parent quote (if reply)+ if (widget.comment.isReply) _buildParentQuote(colorScheme, textTheme),++ // Comment bubble+ Container(+ padding: const EdgeInsets.all(12),+ decoration: BoxDecoration(+ color: widget.isOwnComment+ ? colorScheme.primary500.withValues(alpha: 0.15)+ : colorScheme.fillFaint,+ borderRadius: BorderRadius.only(+ topLeft: const Radius.circular(16),+ topRight: const Radius.circular(16),+ bottomLeft: Radius.circular(widget.isOwnComment ? 16 : 4),+ bottomRight: Radius.circular(widget.isOwnComment ? 4 : 16),+ ),+ ),+ child: Text(+ widget.comment.data,+ style: textTheme.body,+ ),+ ),++ const SizedBox(height: 4),++ // Timestamp and actions row+ Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Text(+ formatRelativeTime(widget.comment.createdAt),+ style: textTheme.mini.copyWith(color: colorScheme.textMuted),+ ),+ const SizedBox(width: 8),+ if (!_isLoadingReactions)+ CommentActionsCapsule(+ isLiked: _isLiked,+ likeCount: _reactions.where((r) => !r.isDeleted).length,+ onLikeTap: _toggleLike,+ onReplyTap: widget.onReplyTap,+ ),+ ],+ ),+ ],+ ),+ );+ }++ Widget _buildParentQuote(+ EnteColorScheme colorScheme,+ EnteTextTheme textTheme,+ ) {+ if (_isLoadingParent) {+ return Container(+ margin: const EdgeInsets.only(bottom: 4),+ padding: const EdgeInsets.all(8),+ child: const SizedBox(+ width: 16,+ height: 16,+ child: CircularProgressIndicator(strokeWidth: 2),+ ),+ );+ }++ final parentText = _parentComment?.data ?? "Original comment unavailable";++ return Container(+ margin: const EdgeInsets.only(bottom: 4),+ decoration: BoxDecoration(+ color: colorScheme.primary500.withValues(alpha: 0.1),+ borderRadius: BorderRadius.circular(8),+ border: Border(+ left: BorderSide(+ color: colorScheme.primary500,+ width: 3,+ ),+ ),+ ),+ padding: const EdgeInsets.all(8),+ child: Text(+ parentText,+ style: textTheme.small.copyWith(color: colorScheme.textMuted),+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ ),+ );+ }+}diff --git a/mobile/apps/photos/lib/ui/social/widgets/comment_input_widget.dart b/mobile/apps/photos/lib/ui/social/widgets/comment_input_widget.dartnew file mode 100644index 0000000000..fa9a9f8bd1--- /dev/null+++ b/mobile/apps/photos/lib/ui/social/widgets/comment_input_widget.dart@@ -0,0 +1,103 @@+import "package:flutter/material.dart";+import "package:photos/models/social/comment.dart";+import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/social/widgets/reply_preview_widget.dart";++class CommentInputWidget extends StatelessWidget {+ final Comment? replyingTo;+ final VoidCallback? onDismissReply;+ final TextEditingController controller;+ final FocusNode focusNode;+ final VoidCallback onSend;++ const CommentInputWidget({+ this.replyingTo,+ this.onDismissReply,+ required this.controller,+ required this.focusNode,+ required this.onSend,+ super.key,+ });++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ final textTheme = getEnteTextTheme(context);+ final bottomPadding = MediaQuery.viewInsetsOf(context).bottom;++ return Container(+ padding: EdgeInsets.only(+ bottom: bottomPadding > 0+ ? bottomPadding+ : MediaQuery.of(context).padding.bottom,+ left: 16,+ right: 16,+ top: 8,+ ),+ decoration: BoxDecoration(+ color: colorScheme.backgroundElevated,+ border: Border(top: BorderSide(color: colorScheme.strokeFaint)),+ ),+ child: SafeArea(+ top: false,+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ if (replyingTo != null)+ ReplyPreviewWidget(+ replyingTo: replyingTo!,+ onDismiss: onDismissReply!,+ ),+ Row(+ children: [+ Expanded(+ child: TextField(+ controller: controller,+ focusNode: focusNode,+ decoration: InputDecoration(+ hintText: "Say something nice!",+ hintStyle: textTheme.body.copyWith(+ color: colorScheme.textMuted,+ ),+ border: InputBorder.none,+ filled: true,+ fillColor: colorScheme.fillFaint,+ contentPadding: const EdgeInsets.symmetric(+ horizontal: 16,+ vertical: 12,+ ),+ enabledBorder: OutlineInputBorder(+ borderRadius: BorderRadius.circular(24),+ borderSide: BorderSide.none,+ ),+ focusedBorder: OutlineInputBorder(+ borderRadius: BorderRadius.circular(24),+ borderSide: BorderSide.none,+ ),+ ),+ ),+ ),+ const SizedBox(width: 8),+ GestureDetector(+ onTap: onSend,+ child: Container(+ padding: const EdgeInsets.all(10),+ decoration: BoxDecoration(+ color: colorScheme.primary500,+ shape: BoxShape.circle,+ ),+ child: const Icon(+ Icons.send,+ size: 20,+ color: Colors.white,+ ),+ ),+ ),+ ],+ ),+ ],+ ),+ ),+ );+ }+}diff --git a/mobile/apps/photos/lib/ui/social/widgets/reply_preview_widget.dart b/mobile/apps/photos/lib/ui/social/widgets/reply_preview_widget.dartnew file mode 100644index 0000000000..7351fe69c4--- /dev/null+++ b/mobile/apps/photos/lib/ui/social/widgets/reply_preview_widget.dart@@ -0,0 +1,59 @@+import "package:flutter/material.dart";+import "package:photos/models/social/comment.dart";+import "package:photos/theme/ente_theme.dart";++class ReplyPreviewWidget extends StatelessWidget {+ final Comment replyingTo;+ final VoidCallback onDismiss;++ const ReplyPreviewWidget({+ required this.replyingTo,+ required this.onDismiss,+ super.key,+ });++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ final textTheme = getEnteTextTheme(context);++ return Container(+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),+ decoration: BoxDecoration(+ color: colorScheme.fillFaint,+ borderRadius: const BorderRadius.vertical(top: Radius.circular(8)),+ ),+ child: Row(+ children: [+ Expanded(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ mainAxisSize: MainAxisSize.min,+ children: [+ Text(+ "Replying to User #${replyingTo.userID}...",+ style: textTheme.small.copyWith(color: colorScheme.textMuted),+ ),+ const SizedBox(height: 2),+ Text(+ replyingTo.data,+ style: textTheme.mini.copyWith(color: colorScheme.textFaint),+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ ),+ ],+ ),+ ),+ GestureDetector(+ onTap: onDismiss,+ child: Icon(+ Icons.close,+ size: 18,+ color: colorScheme.textMuted,+ ),+ ),+ ],+ ),+ );+ }+}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 873eae87ce..19f48ed578 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@@ -1,25 +1,27 @@import "dart:async";-import 'dart:io';+import "dart:io";-import 'package:flutter/cupertino.dart';-import 'package:flutter/material.dart';+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";import "package:photos/generated/l10n.dart";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/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';+import "package:photos/ui/collections/collection_action_sheet.dart";+import "package:photos/ui/social/comments_screen.dart";+import "package:photos/utils/delete_file_util.dart";+import "package:photos/utils/navigation_util.dart";import "package:photos/utils/panorama_util.dart";-import 'package:photos/utils/share_util.dart';+import "package:photos/utils/share_util.dart";class FileBottomBar extends StatefulWidget {final EnteFile file;@@ -352,46 +354,68 @@ class FileBottomBarState extends State<FileBottomBar> {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,+ return GestureDetector(+ onTap: _openCommentsScreen,+ child: 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,),- ),- child: Text(- _commentCount > 99 ? '99+' : _commentCount.toString(),- style: const TextStyle(- color: Colors.black,- fontSize: 8,- fontWeight: FontWeight.w500,+ 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,),- textAlign: TextAlign.center,),),- ),- ],+ ],+ ),),);},);}++ void _openCommentsScreen() {+ final file = widget.file;+ if (file.collectionID == null) return;++ routeToPage(+ context,+ CommentsScreen(+ collectionID: file.collectionID!,+ fileID: file.uploadedFileID,+ ),+ ).then((_) {+ // Refresh comment count when returning from comments screen+ _updateSocialState();+ });+ }}diff --git a/mobile/apps/photos/lib/utils/social/relative_time_formatter.dart b/mobile/apps/photos/lib/utils/social/relative_time_formatter.dartnew file mode 100644index 0000000000..1aa9b06d05--- /dev/null+++ b/mobile/apps/photos/lib/utils/social/relative_time_formatter.dart@@ -0,0 +1,20 @@+import "package:intl/intl.dart";++String formatRelativeTime(int timestampMillis) {+ final now = DateTime.now();+ final dateTime = DateTime.fromMillisecondsSinceEpoch(timestampMillis);+ final difference = now.difference(dateTime);++ if (difference.inMinutes < 1) {+ return "just now";+ } else if (difference.inMinutes < 60) {+ return "${difference.inMinutes}m ago";+ } else if (difference.inHours < 24) {+ return "${difference.inHours}hr ago";+ } else if (difference.inDays < 7) {+ return "${difference.inDays}d ago";+ } else {+ final sameYear = dateTime.year == now.year;+ return DateFormat(sameYear ? "MMM d" : "MMM d, yyyy").format(dateTime);+ }+}