Skip to content

Commit 9118729

Browse files
committed
model: Add hasPostingPermission helper method to ZulipStream
1 parent b467f4c commit 9118729

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
@@ -372,6 +372,19 @@ class ZulipStream {
372372
_$ZulipStreamFromJson(json);
373373

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

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

0 commit comments

Comments
 (0)