File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -315,6 +315,11 @@ enum UserRole{
315
315
final int ? apiValue;
316
316
317
317
int ? toJson () => apiValue;
318
+
319
+ bool isAtLeast (UserRole threshold) {
320
+ // Roles with more privilege have lower [apiValue].
321
+ return (apiValue ?? 0 ) <= (threshold.apiValue ?? 0 );
322
+ }
318
323
}
319
324
320
325
/// As in `streams` in the initial snapshot.
@@ -382,6 +387,19 @@ class ZulipStream {
382
387
_$ZulipStreamFromJson (json);
383
388
384
389
Map <String , dynamic > toJson () => _$ZulipStreamToJson (this );
390
+
391
+ bool hasPostingPermission (User user, {required DateTime byDate, required int realmWaitingPeriodThreshold}) {
392
+ final role = user.role;
393
+ return switch (channelPostPolicy) {
394
+ ChannelPostPolicy .any => true ,
395
+ ChannelPostPolicy .fullMembers => role.isAtLeast (UserRole .member) && (role == UserRole .member
396
+ ? user.hasPassedWaitingPeriod (byDate, realmWaitingPeriodThreshold)
397
+ : true ),
398
+ ChannelPostPolicy .moderators => role.isAtLeast (UserRole .moderator),
399
+ ChannelPostPolicy .administrators => role.isAtLeast (UserRole .administrator),
400
+ ChannelPostPolicy .unknown => true ,
401
+ };
402
+ }
385
403
}
386
404
387
405
/// The name of a property of [ZulipStream] that gets updated
You can’t perform that action at this time.
0 commit comments