File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -314,6 +314,10 @@ enum UserRole{
314
314
final int ? apiValue;
315
315
316
316
int ? toJson () => apiValue;
317
+
318
+ bool isAtLeast (UserRole role) {
319
+ return (apiValue ?? 0 ) <= (role.apiValue ?? 0 );
320
+ }
317
321
}
318
322
319
323
/// As in `streams` in the initial snapshot.
@@ -381,6 +385,19 @@ class ZulipStream {
381
385
_$ZulipStreamFromJson (json);
382
386
383
387
Map <String , dynamic > toJson () => _$ZulipStreamToJson (this );
388
+
389
+ bool hasPostingPermission (User user, {required DateTime byDate, required int realmWaitingPeriodThreshold}) {
390
+ final role = user.role;
391
+ return switch (channelPostPolicy) {
392
+ ChannelPostPolicy .any => true ,
393
+ ChannelPostPolicy .fullMembers => role.isAtLeast (UserRole .member) && (role == UserRole .member
394
+ ? user.hasPassedWaitingPeriod (byDate, realmWaitingPeriodThreshold)
395
+ : true ),
396
+ ChannelPostPolicy .moderators => role.isAtLeast (UserRole .moderator),
397
+ ChannelPostPolicy .administrators => role.isAtLeast (UserRole .administrator),
398
+ ChannelPostPolicy .unknown => true ,
399
+ };
400
+ }
384
401
}
385
402
386
403
/// Policy for which users can post to the stream.
You can’t perform that action at this time.
0 commit comments