Skip to content

Commit c19bb77

Browse files
committed
model: Add hasPostingPermission helper method to ZulipStream
1 parent 4be9343 commit c19bb77

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/api/model/model.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,19 @@ class ZulipStream {
376376
_$ZulipStreamFromJson(json);
377377

378378
Map<String, dynamic> toJson() => _$ZulipStreamToJson(this);
379+
380+
bool hasPostingPermission(User user, {required int realmWaitingPeriodThreshold}) {
381+
final role = user.role;
382+
return switch (channelPostPolicy) {
383+
ChannelPostPolicy.any => true,
384+
ChannelPostPolicy.fullMembers => role != UserRole.guest && (role == UserRole.member
385+
? user.isFullMember(realmWaitingPeriodThreshold)
386+
: true),
387+
ChannelPostPolicy.moderators => role != UserRole.guest && role != UserRole.member,
388+
ChannelPostPolicy.administrators => role == UserRole.administrator || role == UserRole.owner || role == UserRole.unknown,
389+
ChannelPostPolicy.unknown => true,
390+
};
391+
}
379392
}
380393

381394
/// Policy for which users can post to the stream.

0 commit comments

Comments
 (0)