Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to subscribe/unsubscribe to community from long-press action #1028

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased
### Added
- Added ability to subscribe/unsubscribe to community from long press action on posts
- Added option to hide top app bar on scroll

### Fixed
Expand Down
61 changes: 44 additions & 17 deletions lib/community/utils/post_card_action_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ import 'package:thunder/utils/global_context.dart';

enum PostCardAction {
visitProfile,
blockUser,
visitCommunity,
subscribeToCommunity,
unsubscribeFromCommunity,
blockCommunity,
visitInstance,
blockInstance,
sharePost,
shareMedia,
shareLink,
blockInstance,
blockCommunity,
upvote,
downvote,
save,
toggleRead,
share,
blockUser,
}

class ExtendedPostCardActions {
Expand All @@ -70,66 +72,80 @@ class ExtendedPostCardActions {
final bool Function(bool isUserLoggedIn)? shouldEnable;
}

final l10n = AppLocalizations.of(GlobalContext.context)!;

final List<ExtendedPostCardActions> postCardActionItems = [
ExtendedPostCardActions(
postCardAction: PostCardAction.visitProfile,
icon: Icons.person_search_rounded,
label: AppLocalizations.of(GlobalContext.context)!.visitUserProfile,
label: l10n.visitUserProfile,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.blockUser,
icon: Icons.block,
label: AppLocalizations.of(GlobalContext.context)!.blockUser,
label: l10n.blockUser,
shouldEnable: (isUserLoggedIn) => isUserLoggedIn,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.visitCommunity,
icon: Icons.home_work_rounded,
label: AppLocalizations.of(GlobalContext.context)!.visitCommunity,
label: l10n.visitCommunity,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.subscribeToCommunity,
icon: Icons.add_circle_outline_rounded,
label: l10n.subscribeToCommunity,
shouldEnable: (isUserLoggedIn) => isUserLoggedIn,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.unsubscribeFromCommunity,
icon: Icons.remove_circle_outline_rounded,
label: l10n.unsubscribeFromCommunity,
shouldEnable: (isUserLoggedIn) => isUserLoggedIn,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.blockCommunity,
icon: Icons.block_rounded,
label: AppLocalizations.of(GlobalContext.context)!.blockCommunity,
label: l10n.blockCommunity,
shouldEnable: (isUserLoggedIn) => isUserLoggedIn,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.visitInstance,
icon: Icons.language,
label: AppLocalizations.of(GlobalContext.context)!.visitInstance,
label: l10n.visitInstance,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.blockInstance,
icon: Icons.block_rounded,
label: AppLocalizations.of(GlobalContext.context)!.blockInstance,
label: l10n.blockInstance,
shouldEnable: (isUserLoggedIn) => isUserLoggedIn,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.sharePost,
icon: Icons.share_rounded,
label: AppLocalizations.of(GlobalContext.context)!.sharePost,
label: l10n.sharePost,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.shareMedia,
icon: Icons.image_rounded,
label: AppLocalizations.of(GlobalContext.context)!.shareMedia,
label: l10n.shareMedia,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.shareLink,
icon: Icons.link_rounded,
label: AppLocalizations.of(GlobalContext.context)!.shareLink,
label: l10n.shareLink,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.upvote,
label: AppLocalizations.of(GlobalContext.context)!.upvote,
label: l10n.upvote,
icon: Icons.arrow_upward_rounded,
color: Colors.orange,
getForegroundColor: (postView) => postView.myVote == 1 ? Colors.orange : null,
shouldEnable: (isUserLoggedIn) => isUserLoggedIn,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.downvote,
label: AppLocalizations.of(GlobalContext.context)!.downvote,
label: l10n.downvote,
icon: Icons.arrow_downward_rounded,
color: Colors.blue,
getForegroundColor: (postView) => postView.myVote == -1 ? Colors.blue : null,
Expand All @@ -138,7 +154,7 @@ final List<ExtendedPostCardActions> postCardActionItems = [
),
ExtendedPostCardActions(
postCardAction: PostCardAction.save,
label: AppLocalizations.of(GlobalContext.context)!.save,
label: l10n.save,
icon: Icons.star_border_rounded,
color: Colors.purple,
getForegroundColor: (postView) => postView.saved ? Colors.purple : null,
Expand All @@ -147,7 +163,7 @@ final List<ExtendedPostCardActions> postCardActionItems = [
),
ExtendedPostCardActions(
postCardAction: PostCardAction.toggleRead,
label: AppLocalizations.of(GlobalContext.context)!.toggelRead,
label: l10n.toggelRead,
icon: Icons.mail_outline_outlined,
color: Colors.teal.shade300,
getOverrideIcon: (postView) => postView.read ? Icons.mark_email_unread_rounded : Icons.mark_email_read_outlined,
Expand All @@ -156,7 +172,7 @@ final List<ExtendedPostCardActions> postCardActionItems = [
ExtendedPostCardActions(
postCardAction: PostCardAction.share,
icon: Icons.share_rounded,
label: AppLocalizations.of(GlobalContext.context)!.share,
label: l10n.share,
)
];

Expand All @@ -177,6 +193,11 @@ void showPostActionBottomModalSheet(
postCardActionItemsToUse.removeWhere((ExtendedPostCardActions postCardActionItem) => postCardActionItem.postCardAction == PostCardAction.blockInstance);
}

// Hide the option to block a community if the user is subscribed to it
if (actionsToInclude.contains(PostCardAction.blockCommunity) && postViewMedia.postView.subscribed != SubscribedType.notSubscribed) {
postCardActionItemsToUse.removeWhere((ExtendedPostCardActions postCardActionItem) => postCardActionItem.postCardAction == PostCardAction.blockCommunity);
}

multiActionsToInclude ??= [];
final multiPostCardActionItemsToUse = postCardActionItems.where((extendedAction) => multiActionsToInclude!.any((action) => extendedAction.postCardAction == action)).toList();

Expand Down Expand Up @@ -332,5 +353,11 @@ void onSelected(BuildContext context, PostCardAction postCardAction, PostViewMed
case PostCardAction.blockUser:
context.read<UserBloc>().add(BlockUserEvent(personId: postViewMedia.postView.creator.id, blocked: true));
break;
case PostCardAction.subscribeToCommunity:
context.read<CommunityBloc>().add(CommunityActionEvent(communityAction: CommunityAction.follow, communityId: postViewMedia.postView.community.id, value: true));
break;
case PostCardAction.unsubscribeFromCommunity:
context.read<CommunityBloc>().add(CommunityActionEvent(communityAction: CommunityAction.follow, communityId: postViewMedia.postView.community.id, value: false));
break;
}
}
1 change: 1 addition & 0 deletions lib/community/widgets/post_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class _PostCardState extends State<PostCard> {
PostCardAction.blockUser,
PostCardAction.blockInstance,
PostCardAction.visitCommunity,
widget.postViewMedia.postView.subscribed == SubscribedType.notSubscribed ? PostCardAction.subscribeToCommunity : PostCardAction.unsubscribeFromCommunity,
PostCardAction.blockCommunity,
],
multiActionsToInclude: [
Expand Down
1 change: 1 addition & 0 deletions lib/community/widgets/post_card_view_comfortable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class PostCardViewComfortable extends StatelessWidget {
PostCardAction.blockUser,
PostCardAction.blockInstance,
PostCardAction.visitCommunity,
postViewMedia.postView.subscribed == SubscribedType.notSubscribed ? PostCardAction.subscribeToCommunity : PostCardAction.unsubscribeFromCommunity,
PostCardAction.blockCommunity,
],
multiActionsToInclude: [
Expand Down
8 changes: 8 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,10 @@
"@submit": {},
"subscribe": "Subscribe",
"@subscribe": {},
"subscribeToCommunity": "Subscribe to Community",
"@subscribeToCommunity": {
"description": "Action for subscribing to a community"
},
"subscribed": "Subscribed",
"@subscribed": {},
"subscriptions": "Subscriptions",
Expand Down Expand Up @@ -981,6 +985,10 @@
"@unexpectedError": {},
"unsubscribe": "Unsubscribe",
"@unsubscribe": {},
"unsubscribeFromCommunity": "Unsubscribe from Community",
"@unsubscribeFromCommunity": {
"description": "Action for unsubscribing from a community"
},
"unsubscribePending": "Unsubscribe (subscription pending)",
"@unsubscribePending": {},
"unsubscribed": "Unsubscribed",
Expand Down
Loading