From 99cd4ceca8cc0442aac5e26bc7986e82c5356499 Mon Sep 17 00:00:00 2001 From: Joel Hernandez Date: Sun, 11 Aug 2019 21:23:33 +0200 Subject: [PATCH] :sparkles: add post & comment mention notification tiles --- lib/services/localization.dart | 12 +++ .../notification_tile/notification_tile.dart | 18 ++++ .../post_comment_notification_tile.dart | 2 - ...omment_user_mention_notification_tile.dart | 90 +++++++++++++++++++ .../post_user_mention_notification_tile.dart | 79 ++++++++++++++++ 5 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 lib/widgets/tiles/notification_tile/widgets/post_comment_user_mention_notification_tile.dart create mode 100644 lib/widgets/tiles/notification_tile/widgets/post_user_mention_notification_tile.dart diff --git a/lib/services/localization.dart b/lib/services/localization.dart index b0f0377dd..c56043f5b 100644 --- a/lib/services/localization.dart +++ b/lib/services/localization.dart @@ -2879,6 +2879,18 @@ class LocalizationService { name: 'notifications__reacted_to_post_comment_tile'); } + String get notifications__mentioned_in_post_comment_tile { + return Intl.message("[name] [username] mentioned you on a comment.", + desc: "Eg.: James @jamest mentioned you on a comment.", + name: 'notifications__mentioned_in_post_comment_tile'); + } + + String get notifications__mentioned_in_post_tile { + return Intl.message("[name] [username] mentioned you on a post.", + desc: "Eg.: James @jamest mentioned you on a post.", + name: 'notifications__mentioned_in_post_tile'); + } + String get notifications__following_you_tile { return Intl.message("[name] [username] is now following you.", desc: "Eg.: James @jamest is now following you.", diff --git a/lib/widgets/tiles/notification_tile/notification_tile.dart b/lib/widgets/tiles/notification_tile/notification_tile.dart index c1d8eba1e..561a3e01e 100644 --- a/lib/widgets/tiles/notification_tile/notification_tile.dart +++ b/lib/widgets/tiles/notification_tile/notification_tile.dart @@ -6,7 +6,9 @@ import 'package:Okuna/models/notifications/notification.dart'; import 'package:Okuna/models/notifications/post_comment_notification.dart'; import 'package:Okuna/models/notifications/post_comment_reaction_notification.dart'; import 'package:Okuna/models/notifications/post_comment_reply_notification.dart'; +import 'package:Okuna/models/notifications/post_comment_user_mention_notification.dart'; import 'package:Okuna/models/notifications/post_reaction_notification.dart'; +import 'package:Okuna/models/notifications/post_user_mention_notification.dart'; import 'package:Okuna/models/theme.dart'; import 'package:Okuna/provider.dart'; import 'package:Okuna/services/theme.dart'; @@ -18,7 +20,9 @@ import 'package:Okuna/widgets/tiles/notification_tile/widgets/follow_notificatio import 'package:Okuna/widgets/tiles/notification_tile/widgets/post_comment_notification_tile.dart'; import 'package:Okuna/widgets/tiles/notification_tile/widgets/post_comment_reaction_notification_tile.dart'; import 'package:Okuna/widgets/tiles/notification_tile/widgets/post_comment_reply_notification_tile.dart'; +import 'package:Okuna/widgets/tiles/notification_tile/widgets/post_comment_user_mention_notification_tile.dart'; import 'package:Okuna/widgets/tiles/notification_tile/widgets/post_reaction_notification_tile.dart'; +import 'package:Okuna/widgets/tiles/notification_tile/widgets/post_user_mention_notification_tile.dart'; import 'package:flutter/material.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; @@ -117,6 +121,20 @@ class OBNotificationTile extends StatelessWidget { onPressed: finalOnPressed, ); break; + case PostCommentUserMentionNotification: + notificationTile = OBPostCommentUserMentionNotificationTile( + notification: notification, + postCommentUserMentionNotification: notificationContentObject, + onPressed: finalOnPressed, + ); + break; + case PostUserMentionNotification: + notificationTile = OBPostUserMentionNotificationTile( + notification: notification, + postUserMentionNotification: notificationContentObject, + onPressed: finalOnPressed, + ); + break; default: print('Unsupported notification content object type'); return const SizedBox(); diff --git a/lib/widgets/tiles/notification_tile/widgets/post_comment_notification_tile.dart b/lib/widgets/tiles/notification_tile/widgets/post_comment_notification_tile.dart index 6400ccf5e..f521827bd 100644 --- a/lib/widgets/tiles/notification_tile/widgets/post_comment_notification_tile.dart +++ b/lib/widgets/tiles/notification_tile/widgets/post_comment_notification_tile.dart @@ -30,9 +30,7 @@ class OBPostCommentNotificationTile extends StatelessWidget { Widget build(BuildContext context) { PostComment postComment = postCommentNotification.postComment; Post post = postComment.post; - String postCommenterUsername = postComment.getCommenterUsername(); String postCommentText = postComment.text; - String postCommenterName = postComment.getCommenterName(); int postCreatorId = postCommentNotification.getPostCreatorId(); OpenbookProviderState openbookProvider = OpenbookProvider.of(context); diff --git a/lib/widgets/tiles/notification_tile/widgets/post_comment_user_mention_notification_tile.dart b/lib/widgets/tiles/notification_tile/widgets/post_comment_user_mention_notification_tile.dart new file mode 100644 index 000000000..c3bb87473 --- /dev/null +++ b/lib/widgets/tiles/notification_tile/widgets/post_comment_user_mention_notification_tile.dart @@ -0,0 +1,90 @@ +import 'package:Okuna/models/notifications/notification.dart'; +import 'package:Okuna/models/notifications/post_comment_user_mention_notification.dart'; +import 'package:Okuna/models/post.dart'; +import 'package:Okuna/models/post_comment.dart'; +import 'package:Okuna/models/post_comment_user_mention.dart'; +import 'package:Okuna/provider.dart'; +import 'package:Okuna/services/localization.dart'; +import 'package:Okuna/widgets/avatars/avatar.dart'; +import 'package:Okuna/widgets/theming/actionable_smart_text.dart'; +import 'package:Okuna/widgets/theming/secondary_text.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_advanced_networkimage/provider.dart'; + +import 'notification_tile_skeleton.dart'; +import 'notification_tile_title.dart'; + +class OBPostCommentUserMentionNotificationTile extends StatelessWidget { + final OBNotification notification; + final PostCommentUserMentionNotification postCommentUserMentionNotification; + static final double postCommentImagePreviewSize = 40; + final VoidCallback onPressed; + + const OBPostCommentUserMentionNotificationTile( + {Key key, + @required this.notification, + @required this.postCommentUserMentionNotification, + this.onPressed}) + : super(key: key); + + @override + Widget build(BuildContext context) { + PostCommentUserMention postCommentUserMention = + postCommentUserMentionNotification.postCommentUserMention; + PostComment postComment = postCommentUserMention.postComment; + Post post = postComment.post; + + Widget postCommentImagePreview; + if (post.hasImage()) { + postCommentImagePreview = ClipRRect( + borderRadius: BorderRadius.circular(8.0), + child: Image( + image: AdvancedNetworkImage(post.getImage(), useDiskCache: true), + height: postCommentImagePreviewSize, + width: postCommentImagePreviewSize, + fit: BoxFit.cover, + ), + ); + } + OpenbookProviderState openbookProvider = OpenbookProvider.of(context); + var utilsService = openbookProvider.utilsService; + + Function navigateToMentionerProfile = () { + openbookProvider.navigationService.navigateToUserProfile( + user: postCommentUserMention.postComment.commenter, context: context); + }; + LocalizationService _localizationService = openbookProvider.localizationService; + + return OBNotificationTileSkeleton( + onTap: () { + if (onPressed != null) onPressed(); + OpenbookProviderState openbookProvider = OpenbookProvider.of(context); + + PostComment parentComment = postComment.parentComment; + if(parentComment!=null){ + openbookProvider.navigationService.navigateToPostCommentRepliesLinked( + postComment: postComment, + context: context, + parentComment: parentComment); + }else { + openbookProvider.navigationService.navigateToPostCommentsLinked( + postComment: postComment, context: context); + } + }, + leading: OBAvatar( + onPressed: navigateToMentionerProfile, + size: OBAvatarSize.medium, + avatarUrl: postCommentUserMention.postComment.commenter.getProfileAvatar(), + ), + title: OBNotificationTileTitle( + text: TextSpan(text: _localizationService.notifications__mentioned_in_post_comment_tile), + onUsernamePressed: navigateToMentionerProfile, + user: postCommentUserMention.postComment.commenter, + ), + subtitle: OBSecondaryText( + utilsService.timeAgo(notification.created), + size: OBTextSize.small, + ), + ); + } +} diff --git a/lib/widgets/tiles/notification_tile/widgets/post_user_mention_notification_tile.dart b/lib/widgets/tiles/notification_tile/widgets/post_user_mention_notification_tile.dart new file mode 100644 index 000000000..c726d9e7c --- /dev/null +++ b/lib/widgets/tiles/notification_tile/widgets/post_user_mention_notification_tile.dart @@ -0,0 +1,79 @@ +import 'package:Okuna/models/notifications/notification.dart'; +import 'package:Okuna/models/notifications/post_user_mention_notification.dart'; +import 'package:Okuna/models/post.dart'; +import 'package:Okuna/models/post_user_mention.dart'; +import 'package:Okuna/provider.dart'; +import 'package:Okuna/services/localization.dart'; +import 'package:Okuna/widgets/avatars/avatar.dart'; +import 'package:Okuna/widgets/theming/actionable_smart_text.dart'; +import 'package:Okuna/widgets/theming/secondary_text.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_advanced_networkimage/provider.dart'; + +import 'notification_tile_skeleton.dart'; +import 'notification_tile_title.dart'; + +class OBPostUserMentionNotificationTile extends StatelessWidget { + final OBNotification notification; + final PostUserMentionNotification postUserMentionNotification; + static final double postImagePreviewSize = 40; + final VoidCallback onPressed; + + const OBPostUserMentionNotificationTile( + {Key key, + @required this.notification, + @required this.postUserMentionNotification, + this.onPressed}) + : super(key: key); + + @override + Widget build(BuildContext context) { + PostUserMention postUserMention = + postUserMentionNotification.postUserMention; + Post post = postUserMention.post; + + Widget postImagePreview; + if (post.hasImage()) { + postImagePreview = ClipRRect( + borderRadius: BorderRadius.circular(8.0), + child: Image( + image: AdvancedNetworkImage(post.getImage(), useDiskCache: true), + height: postImagePreviewSize, + width: postImagePreviewSize, + fit: BoxFit.cover, + ), + ); + } + OpenbookProviderState openbookProvider = OpenbookProvider.of(context); + var utilsService = openbookProvider.utilsService; + + Function navigateToMentionerProfile = () { + openbookProvider.navigationService.navigateToUserProfile( + user: postUserMention.post.creator, context: context); + }; + LocalizationService _localizationService = openbookProvider.localizationService; + + return OBNotificationTileSkeleton( + onTap: () { + if (onPressed != null) onPressed(); + OpenbookProviderState openbookProvider = OpenbookProvider.of(context); + openbookProvider.navigationService + .navigateToPost(post: postUserMention.post, context: context); + }, + leading: OBAvatar( + onPressed: navigateToMentionerProfile, + size: OBAvatarSize.medium, + avatarUrl: postUserMention.post.creator.getProfileAvatar(), + ), + title: OBNotificationTileTitle( + text: TextSpan(text: _localizationService.notifications__mentioned_in_post_tile), + onUsernamePressed: navigateToMentionerProfile, + user: postUserMention.post.creator, + ), + subtitle: OBSecondaryText( + utilsService.timeAgo(notification.created), + size: OBTextSize.small, + ), + ); + } +}