Skip to content
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
5 changes: 5 additions & 0 deletions lib/community/utils/post_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ void triggerPostAction({
required Function(int, int) onVoteAction,
required Function(int, bool) onSaveAction,
required Function(int, bool) onToggleReadAction,
required Function(int, bool) onHideAction,
required int voteType,
bool? saved,
bool? read,
bool? hidden,
required PostViewMedia postViewMedia,
}) {
switch (swipeAction) {
Expand All @@ -44,6 +46,9 @@ void triggerPostAction({
case SwipeAction.toggleRead:
onToggleReadAction(postViewMedia.postView.post.id, !(read ?? false));
break;
case SwipeAction.hide:
onHideAction(postViewMedia.postView.post.id, !(hidden ?? false));
break;
default:
break;
}
Expand Down
32 changes: 30 additions & 2 deletions lib/community/utils/post_card_action_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ enum PostCardAction {
downvote,
save,
toggleRead,
hide,
share,
delete,
moderatorActions,
Expand Down Expand Up @@ -243,6 +244,15 @@ final List<ExtendedPostCardActions> postCardActionItems = [
getOverrideIcon: (postView) => postView.read ? Icons.mark_email_unread_rounded : Icons.mark_email_read_outlined,
shouldEnable: (isUserLoggedIn) => isUserLoggedIn,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.hide,
label: l10n.hide,
getOverrideLabel: (context, postView) => postView.hidden == true ? l10n.unhide : l10n.hide,
icon: Icons.visibility_off_rounded,
getColor: (context) => context.read<ThunderBloc>().state.hideColor.color,
getOverrideIcon: (postView) => postView.hidden == true ? Icons.visibility_rounded : Icons.visibility_off_rounded,
shouldEnable: (isUserLoggedIn) => isUserLoggedIn,
),
ExtendedPostCardActions(
postCardAction: PostCardAction.share,
icon: Icons.share_rounded,
Expand Down Expand Up @@ -299,6 +309,7 @@ void showPostActionBottomModalSheet(
PostActionBottomSheetPage page = PostActionBottomSheetPage.general,
void Function(int userId)? onBlockedUser,
void Function(int userId)? onBlockedCommunity,
void Function(int postId)? onPostHidden,
}) {
final bool isOwnPost = postViewMedia.postView.creator.id == context.read<AuthBloc>().state.account?.userId;
final bool isModerator =
Expand Down Expand Up @@ -326,11 +337,17 @@ void showPostActionBottomModalSheet(
PostCardAction.downvote,
PostCardAction.save,
PostCardAction.toggleRead,
PostCardAction.hide,
PostCardAction.share,
if (isOwnPost) PostCardAction.delete,
].contains(extendedAction.postCardAction))
.toList();

// Remove hide if unsupported
if (defaultMultiPostCardActions.any((extendedAction) => extendedAction.postCardAction == PostCardAction.hide) && !LemmyClient.instance.supportsFeature(LemmyFeature.hidePosts)) {
defaultMultiPostCardActions.removeWhere((ExtendedPostCardActions postCardActionItem) => postCardActionItem.postCardAction == PostCardAction.hide);
}

// Generate the list of moderator actions
final List<ExtendedPostCardActions> moderatorPostCardActions = postCardActionItems
.where((extendedAction) => [
Expand Down Expand Up @@ -403,7 +420,7 @@ void showPostActionBottomModalSheet(
].contains(extendedAction.postCardAction))
.toList();

// Remove block if unsupported
// Remove block if unsupported
if (instanceActions.any((extendedAction) => extendedAction.postCardAction == PostCardAction.blockInstance) && !LemmyClient.instance.supportsFeature(LemmyFeature.blockInstance)) {
instanceActions.removeWhere((ExtendedPostCardActions postCardActionItem) => postCardActionItem.postCardAction == PostCardAction.blockInstance);
}
Expand Down Expand Up @@ -435,6 +452,7 @@ void showPostActionBottomModalSheet(
outerContext: context,
onBlockedUser: onBlockedUser,
onBlockedCommunity: onBlockedCommunity,
onPostHidden: onPostHidden,
),
);
}
Expand Down Expand Up @@ -464,6 +482,9 @@ class PostCardActionPicker extends StatefulWidget {
/// Callback used to notify that we blocked a community
final Function(int userId)? onBlockedCommunity;

/// Callback used to notify that we hid a post
final Function(int postId)? onPostHidden;

const PostCardActionPicker({
super.key,
required this.postViewMedia,
Expand All @@ -474,6 +495,7 @@ class PostCardActionPicker extends StatefulWidget {
required this.outerContext,
required this.onBlockedUser,
required this.onBlockedCommunity,
required this.onPostHidden,
});

@override
Expand Down Expand Up @@ -559,7 +581,7 @@ class _PostCardActionPickerState extends State<PostCardActionPicker> {
...widget.multiPostCardActions[page ?? widget.page]!.where((a) => a.shouldShow?.call(context, widget.postViewMedia.postView) ?? true).map(
(a) {
return PickerItemData(
label: a.label,
label: a.getOverrideLabel?.call(context, widget.postViewMedia.postView) ?? a.label,
icon: a.getOverrideIcon?.call(widget.postViewMedia.postView) ?? a.icon,
backgroundColor: a.getColor?.call(context),
foregroundColor: a.getForegroundColor?.call(context, widget.postViewMedia.postView),
Expand Down Expand Up @@ -696,6 +718,12 @@ class _PostCardActionPickerState extends State<PostCardActionPicker> {
action = () =>
widget.outerContext.read<FeedBloc>().add(FeedItemActionedEvent(postAction: PostAction.read, postId: widget.postViewMedia.postView.post.id, value: !widget.postViewMedia.postView.read));
break;
case PostCardAction.hide:
action = () => widget.outerContext
.read<FeedBloc>()
.add(FeedItemActionedEvent(postAction: PostAction.hide, postId: widget.postViewMedia.postView.post.id, value: !(widget.postViewMedia.postView.hidden ?? false)));
widget.onPostHidden?.call(widget.postViewMedia.postView.post.id);
break;
case PostCardAction.share:
pop = false;
action = () => setState(() => page = PostActionBottomSheetPage.share);
Expand Down
3 changes: 3 additions & 0 deletions lib/community/widgets/community_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class _CommunityDrawerState extends State<CommunityDrawer> {
sortType: authState.getSiteResponse?.myUser?.localUserView.localUser.defaultSortType ?? thunderState.sortTypeForInstance,
communityId: community.id,
reset: true,
showHidden: thunderState.showHiddenPosts,
),
);
},
Expand Down Expand Up @@ -339,6 +340,7 @@ class FavoriteCommunities extends StatelessWidget {
sortType: authState.getSiteResponse?.myUser?.localUserView.localUser.defaultSortType ?? thunderState.sortTypeForInstance,
communityId: community.id,
reset: true,
showHidden: thunderState.showHiddenPosts,
),
);
},
Expand Down Expand Up @@ -400,6 +402,7 @@ class ModeratedCommunities extends StatelessWidget {
sortType: authState.getSiteResponse?.myUser?.localUserView.localUser.defaultSortType ?? thunderState.sortTypeForInstance,
communityId: community.id,
reset: true,
showHidden: thunderState.showHiddenPosts,
),
);
},
Expand Down
34 changes: 32 additions & 2 deletions lib/community/widgets/post_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:thunder/community/widgets/post_card_view_compact.dart';
import 'package:thunder/core/auth/bloc/auth_bloc.dart';
import 'package:thunder/core/enums/swipe_action.dart';
import 'package:thunder/core/models/post_view_media.dart';
import 'package:thunder/core/singletons/lemmy_client.dart';
import 'package:thunder/feed/bloc/feed_bloc.dart';
import 'package:thunder/feed/view/feed_page.dart';
import 'package:thunder/feed/widgets/widgets.dart';
Expand All @@ -26,6 +27,7 @@ class PostCard extends StatefulWidget {
final Function(int) onVoteAction;
final Function(bool) onSaveAction;
final Function(bool) onReadAction;
final Function(bool) onHideAction;
final Function(double) onUpAction;
final Function() onDownAction;

Expand All @@ -38,6 +40,7 @@ class PostCard extends StatefulWidget {
required this.onVoteAction,
required this.onSaveAction,
required this.onReadAction,
required this.onHideAction,
required this.onUpAction,
required this.onDownAction,
required this.listingType,
Expand Down Expand Up @@ -87,6 +90,7 @@ class _PostCardState extends State<PostCard> {
int? myVote = widget.postViewMedia.postView.myVote;
bool saved = widget.postViewMedia.postView.saved;
bool read = widget.postViewMedia.postView.read;
bool? hidden = widget.postViewMedia.postView.hidden;

return Listener(
behavior: HitTestBehavior.opaque,
Expand All @@ -103,9 +107,11 @@ class _PostCardState extends State<PostCard> {
onSaveAction: (int postId, bool saved) => widget.onSaveAction(saved),
onVoteAction: (int postId, int vote) => widget.onVoteAction(vote),
onToggleReadAction: (int postId, bool read) => widget.onReadAction(read),
onHideAction: (int postId, bool hide) => widget.onHideAction(hide),
voteType: myVote ?? 0,
saved: saved,
read: read,
hidden: hidden,
postViewMedia: widget.postViewMedia,
);
}
Expand Down Expand Up @@ -147,16 +153,34 @@ class _PostCardState extends State<PostCard> {

if (details.progress > firstActionThreshold && details.progress < secondActionThreshold && details.direction == DismissDirection.startToEnd) {
updatedSwipeAction = state.leftPrimaryPostGesture;

// Change the hide action to none of not supported by instance
if (updatedSwipeAction == SwipeAction.hide && !LemmyClient.instance.supportsFeature(LemmyFeature.hidePosts)) {
updatedSwipeAction = SwipeAction.none;
}

if (updatedSwipeAction != swipeAction) HapticFeedback.mediumImpact();
} else if (details.progress > secondActionThreshold && details.direction == DismissDirection.startToEnd) {
if (state.leftSecondaryPostGesture != SwipeAction.none) {
updatedSwipeAction = state.leftSecondaryPostGesture;
} else {
updatedSwipeAction = state.leftPrimaryPostGesture;
}

// Change the hide action to none of not supported by instance
if (updatedSwipeAction == SwipeAction.hide && !LemmyClient.instance.supportsFeature(LemmyFeature.hidePosts)) {
updatedSwipeAction = SwipeAction.none;
}

if (updatedSwipeAction != swipeAction) HapticFeedback.mediumImpact();
} else if (details.progress > firstActionThreshold && details.progress < secondActionThreshold && details.direction == DismissDirection.endToStart) {
updatedSwipeAction = state.rightPrimaryPostGesture;

// Change the hide action to none of not supported by instance
if (updatedSwipeAction == SwipeAction.hide && !LemmyClient.instance.supportsFeature(LemmyFeature.hidePosts)) {
updatedSwipeAction = SwipeAction.none;
}

if (updatedSwipeAction != swipeAction) HapticFeedback.mediumImpact();
} else if (details.progress > secondActionThreshold && details.direction == DismissDirection.endToStart) {
if (state.rightSecondaryPostGesture != SwipeAction.none) {
Expand All @@ -165,6 +189,11 @@ class _PostCardState extends State<PostCard> {
updatedSwipeAction = state.rightPrimaryPostGesture;
}

// Change the hide action to none of not supported by instance
if (updatedSwipeAction == SwipeAction.hide && !LemmyClient.instance.supportsFeature(LemmyFeature.hidePosts)) {
updatedSwipeAction = SwipeAction.none;
}

if (updatedSwipeAction != swipeAction) HapticFeedback.mediumImpact();
} else {
updatedSwipeAction = null;
Expand All @@ -184,7 +213,7 @@ class _PostCardState extends State<PostCard> {
duration: const Duration(milliseconds: 200),
child: SizedBox(
width: MediaQuery.of(context).size.width * (state.tabletMode ? 0.5 : 1) * dismissThreshold,
child: swipeAction == null ? Container() : Icon((swipeAction ?? SwipeAction.none).getIcon(read: read)),
child: swipeAction == null ? Container() : Icon((swipeAction ?? SwipeAction.none).getIcon(read: read, hidden: hidden)),
),
)
: AnimatedContainer(
Expand All @@ -195,7 +224,7 @@ class _PostCardState extends State<PostCard> {
duration: const Duration(milliseconds: 200),
child: SizedBox(
width: (MediaQuery.of(context).size.width * (state.tabletMode ? 0.5 : 1)) * dismissThreshold,
child: swipeAction == null ? Container() : Icon((swipeAction ?? SwipeAction.none).getIcon(read: read)),
child: swipeAction == null ? Container() : Icon((swipeAction ?? SwipeAction.none).getIcon(read: read, hidden: hidden)),
),
),
child: InkWell(
Expand Down Expand Up @@ -236,6 +265,7 @@ class _PostCardState extends State<PostCard> {
widget.postViewMedia,
onBlockedUser: (userId) => context.read<FeedBloc>().add(FeedDismissBlockedEvent(userId: userId)),
onBlockedCommunity: (communityId) => context.read<FeedBloc>().add(FeedDismissBlockedEvent(communityId: communityId)),
onPostHidden: (postId) => context.read<FeedBloc>().add(FeedDismissHiddenPostEvent(postId: postId)),
),
onTap: () async {
PostView postView = widget.postViewMedia.postView;
Expand Down
3 changes: 3 additions & 0 deletions lib/community/widgets/post_card_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class PostCardList extends StatefulWidget {
final Function(int, int) onVoteAction;
final Function(int, bool) onSaveAction;
final Function(int, bool) onToggleReadAction;
final Function(int, bool) onHideAction;

const PostCardList({
super.key,
Expand All @@ -47,6 +48,7 @@ class PostCardList extends StatefulWidget {
required this.onVoteAction,
required this.onSaveAction,
required this.onToggleReadAction,
required this.onHideAction,
this.sortType,
this.blockedCommunity,
this.tagline = '',
Expand Down Expand Up @@ -168,6 +170,7 @@ class _PostCardListState extends State<PostCardList> {
onVoteAction: (int voteType) => widget.onVoteAction(postViewMedia.postView.post.id, voteType),
onSaveAction: (bool saved) => widget.onSaveAction(postViewMedia.postView.post.id, saved),
onReadAction: (bool read) => widget.onToggleReadAction(postViewMedia.postView.post.id, read),
onHideAction: (bool hide) => widget.onHideAction(postViewMedia.postView.post.id, hide),
onUpAction: (double verticalDragDistance) {},
onDownAction: () {},
listingType: widget.listingType,
Expand Down
23 changes: 23 additions & 0 deletions lib/community/widgets/post_card_view_comfortable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:thunder/core/enums/view_mode.dart';
import 'package:thunder/core/models/post_view_media.dart';
import 'package:thunder/core/theme/bloc/theme_bloc.dart';
import 'package:thunder/feed/bloc/feed_bloc.dart';
import 'package:thunder/feed/feed.dart';
import 'package:thunder/feed/view/feed_page.dart';
import 'package:thunder/shared/media_view.dart';
import 'package:thunder/shared/text/scalable_text.dart';
Expand Down Expand Up @@ -113,6 +114,15 @@ class PostCardViewComfortable extends StatelessWidget {
child: Text.rich(
TextSpan(
children: [
if (postViewMedia.postView.hidden == true)
WidgetSpan(
child: Icon(
Icons.visibility_off_rounded,
color: indicateRead && postViewMedia.postView.read ? context.read<ThunderBloc>().state.hideColor.color.withOpacity(0.55) : context.read<ThunderBloc>().state.hideColor.color,
size: 16 * textScaleFactor,
semanticLabel: l10n.hidden,
),
),
if (postViewMedia.postView.post.locked) ...[
WidgetSpan(
child: Icon(
Expand Down Expand Up @@ -197,6 +207,18 @@ class PostCardViewComfortable extends StatelessWidget {
child: Text.rich(
TextSpan(
children: [
if (postViewMedia.postView.hidden == true) ...[
WidgetSpan(
child: Icon(
Icons.visibility_off_rounded,
color:
indicateRead && postViewMedia.postView.read ? context.read<ThunderBloc>().state.hideColor.color.withOpacity(0.55) : context.read<ThunderBloc>().state.hideColor.color,
size: 16 * textScaleFactor,
semanticLabel: l10n.hidden,
),
),
const WidgetSpan(child: SizedBox(width: 2)),
],
if (postViewMedia.postView.post.locked) ...[
WidgetSpan(
child: Icon(
Expand Down Expand Up @@ -328,6 +350,7 @@ class PostCardViewComfortable extends StatelessWidget {
postViewMedia,
onBlockedUser: (userId) => context.read<FeedBloc>().add(FeedDismissBlockedEvent(userId: userId)),
onBlockedCommunity: (communityId) => context.read<FeedBloc>().add(FeedDismissBlockedEvent(communityId: communityId)),
onPostHidden: (postId) => context.read<FeedBloc>().add(FeedDismissHiddenPostEvent(postId: postId)),
);
HapticFeedback.mediumImpact();
}),
Expand Down
14 changes: 14 additions & 0 deletions lib/community/widgets/post_card_view_compact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:lemmy_api_client/v3.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:html_unescape/html_unescape_small.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import 'package:thunder/account/bloc/account_bloc.dart';
import 'package:thunder/community/widgets/post_card_metadata.dart';
Expand Down Expand Up @@ -39,6 +40,7 @@ class PostCardViewCompact extends StatelessWidget {

@override
Widget build(BuildContext context) {
final AppLocalizations l10n = AppLocalizations.of(context)!;
final theme = Theme.of(context);
final ThunderState state = context.watch<ThunderBloc>().state;

Expand Down Expand Up @@ -77,6 +79,18 @@ class PostCardViewCompact extends StatelessWidget {
Text.rich(
TextSpan(
children: [
if (postViewMedia.postView.hidden == true) ...[
WidgetSpan(
child: Icon(
Icons.visibility_off_rounded,
color:
indicateRead && postViewMedia.postView.read ? context.read<ThunderBloc>().state.hideColor.color.withOpacity(0.55) : context.read<ThunderBloc>().state.hideColor.color,
size: 16 * textScaleFactor,
semanticLabel: l10n.hidden,
),
),
const WidgetSpan(child: SizedBox(width: 2)),
],
if (postViewMedia.postView.post.locked) ...[
WidgetSpan(
child: Icon(
Expand Down
Loading