@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
5
5
6
6
import 'package:flutter_bloc/flutter_bloc.dart' ;
7
7
import 'package:flutter_gen/gen_l10n/app_localizations.dart' ;
8
+ import 'package:lemmy_api_client/v3.dart' ;
8
9
import 'package:swipeable_page_route/swipeable_page_route.dart' ;
9
10
10
11
import 'package:thunder/account/bloc/account_bloc.dart' ;
@@ -29,8 +30,11 @@ class FeedFAB extends StatelessWidget {
29
30
30
31
@override
31
32
build (BuildContext context) {
33
+ final theme = Theme .of (context);
32
34
final ThunderState state = context.watch <ThunderBloc >().state;
33
35
final FeedState feedState = context.watch <FeedBloc >().state;
36
+ final AuthState authState = context.read <AuthBloc >().state;
37
+ final AccountState accountState = context.read <AccountBloc >().state;
34
38
35
39
// A list of actions that are not supported through the general feed
36
40
List <FeedFabAction > unsupportedGeneralFeedFabActions = [];
@@ -46,9 +50,18 @@ class FeedFAB extends StatelessWidget {
46
50
// Check to see if we are in the general feeds
47
51
bool isGeneralFeed = feedState.status != FeedStatus .initial && feedState.feedType == FeedType .general;
48
52
bool isCommunityFeed = feedState.status != FeedStatus .initial && feedState.feedType == FeedType .community;
49
-
50
53
bool isNavigatedFeed = Navigator .canPop (context);
51
54
55
+ bool isPostLocked = false ;
56
+
57
+ if (authState.isLoggedIn && isCommunityFeed) {
58
+ final CommunityView communityView = feedState.fullCommunityView! .communityView;
59
+
60
+ if (communityView.community.postingRestrictedToMods && ! accountState.moderates.any ((CommunityModeratorView cmv) => cmv.community.id == communityView.community.id)) {
61
+ isPostLocked = true ;
62
+ }
63
+ }
64
+
52
65
// Check single-press action
53
66
if (isGeneralFeed && unsupportedGeneralFeedFabActions.contains (singlePressAction)) {
54
67
singlePressAction = FeedFabAction .openFab; // Default to open fab on unsupported actions
@@ -77,8 +90,9 @@ class FeedFAB extends StatelessWidget {
77
90
? GestureFab (
78
91
heroTag: heroTag,
79
92
distance: 60 ,
93
+ fabBackgroundColor: (singlePressAction == FeedFabAction .newPost && isPostLocked) ? theme.colorScheme.errorContainer : null ,
80
94
icon: Icon (
81
- singlePressAction.icon,
95
+ (singlePressAction == FeedFabAction .newPost && isPostLocked) ? Icons .lock : singlePressAction.icon,
82
96
semanticLabel: singlePressAction.title,
83
97
size: 35 ,
84
98
),
@@ -105,7 +119,7 @@ class FeedFAB extends StatelessWidget {
105
119
triggerScrollToTop (context);
106
120
break ;
107
121
case FeedFabAction .newPost:
108
- triggerNewPost (context);
122
+ triggerNewPost (context, isPostingLocked : isPostLocked );
109
123
break ;
110
124
default :
111
125
break ;
@@ -134,13 +148,13 @@ class FeedFAB extends StatelessWidget {
134
148
triggerScrollToTop (context);
135
149
break ;
136
150
case FeedFabAction .newPost:
137
- triggerNewPost (context);
151
+ triggerNewPost (context, isPostingLocked : isPostLocked );
138
152
break ;
139
153
default :
140
154
break ;
141
155
}
142
156
},
143
- children: getEnabledActions (context),
157
+ children: getEnabledActions (context, isPostingLocked : isPostLocked ),
144
158
)
145
159
: Stack (
146
160
// This creates an invisible touch target to summon the FAB
@@ -162,7 +176,8 @@ class FeedFAB extends StatelessWidget {
162
176
);
163
177
}
164
178
165
- List <ActionButton > getEnabledActions (BuildContext context) {
179
+ List <ActionButton > getEnabledActions (BuildContext context, {bool isPostingLocked = false }) {
180
+ final theme = Theme .of (context);
166
181
final ThunderState state = context.watch <ThunderBloc >().state;
167
182
168
183
bool enableBackToTop = state.enableBackToTop;
@@ -221,10 +236,11 @@ class FeedFAB extends StatelessWidget {
221
236
if (enableNewPost)
222
237
ActionButton (
223
238
title: FeedFabAction .newPost.title,
224
- icon: Icon (FeedFabAction .newPost.icon),
239
+ icon: Icon (isPostingLocked ? Icons .lock : FeedFabAction .newPost.icon),
240
+ backgroundColor: isPostingLocked ? theme.colorScheme.errorContainer : null ,
225
241
onPressed: () {
226
242
HapticFeedback .lightImpact ();
227
- triggerNewPost (context);
243
+ triggerNewPost (context, isPostingLocked : isPostingLocked );
228
244
},
229
245
),
230
246
];
@@ -263,39 +279,44 @@ class FeedFAB extends StatelessWidget {
263
279
context.read <FeedBloc >().add (ScrollToTopEvent ());
264
280
}
265
281
266
- Future <void > triggerNewPost (BuildContext context) async {
267
- FeedBloc feedBloc = context. read < FeedBloc >() ;
282
+ Future <void > triggerNewPost (BuildContext context, { bool isPostingLocked = false } ) async {
283
+ final l10n = AppLocalizations . of (context) ! ;
268
284
269
285
if (! context.read <AuthBloc >().state.isLoggedIn) {
270
- showSnackbar (context, AppLocalizations .of (context)! .mustBeLoggedInPost);
271
- } else {
272
- ThunderBloc thunderBloc = context.read <ThunderBloc >();
273
- AccountBloc accountBloc = context.read <AccountBloc >();
274
-
275
- final ThunderState thunderState = context.read <ThunderBloc >().state;
276
- final bool reduceAnimations = thunderState.reduceAnimations;
277
-
278
- Navigator .of (context).push (
279
- SwipeablePageRoute (
280
- transitionDuration: reduceAnimations ? const Duration (milliseconds: 100 ) : null ,
281
- canOnlySwipeFromEdge: true ,
282
- backGestureDetectionWidth: 45 ,
283
- builder: (context) {
284
- return MultiBlocProvider (
285
- providers: [
286
- BlocProvider <FeedBloc >.value (value: feedBloc),
287
- BlocProvider <ThunderBloc >.value (value: thunderBloc),
288
- BlocProvider <AccountBloc >.value (value: accountBloc),
289
- ],
290
- child: CreatePostPage (
291
- communityId: feedBloc.state.communityId,
292
- communityView: feedBloc.state.fullCommunityView? .communityView,
293
- scaffoldMessengerKey: scaffoldMessengerKey,
294
- ),
295
- );
296
- },
297
- ),
298
- );
286
+ return showSnackbar (context, l10n.mustBeLoggedInPost);
287
+ }
288
+
289
+ if (isPostingLocked) {
290
+ return showSnackbar (context, l10n.onlyModsCanPostInCommunity);
299
291
}
292
+
293
+ FeedBloc feedBloc = context.read <FeedBloc >();
294
+ ThunderBloc thunderBloc = context.read <ThunderBloc >();
295
+ AccountBloc accountBloc = context.read <AccountBloc >();
296
+
297
+ final ThunderState thunderState = context.read <ThunderBloc >().state;
298
+ final bool reduceAnimations = thunderState.reduceAnimations;
299
+
300
+ Navigator .of (context).push (
301
+ SwipeablePageRoute (
302
+ transitionDuration: reduceAnimations ? const Duration (milliseconds: 100 ) : null ,
303
+ canOnlySwipeFromEdge: true ,
304
+ backGestureDetectionWidth: 45 ,
305
+ builder: (context) {
306
+ return MultiBlocProvider (
307
+ providers: [
308
+ BlocProvider <FeedBloc >.value (value: feedBloc),
309
+ BlocProvider <ThunderBloc >.value (value: thunderBloc),
310
+ BlocProvider <AccountBloc >.value (value: accountBloc),
311
+ ],
312
+ child: CreatePostPage (
313
+ communityId: feedBloc.state.communityId,
314
+ communityView: feedBloc.state.fullCommunityView? .communityView,
315
+ scaffoldMessengerKey: scaffoldMessengerKey,
316
+ ),
317
+ );
318
+ },
319
+ ),
320
+ );
300
321
}
301
322
}
0 commit comments