Skip to content

Commit 87ab7e9

Browse files
committed
channel: Implement modern group-based permission check for can-send-message
Fixes zulip#1862.
1 parent f0d7dca commit 87ab7e9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/model/channel.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,21 @@ mixin ChannelStore on UserStore {
191191
bool selfCanSendMessage({
192192
required ZulipStream inChannel,
193193
required DateTime byDate,
194+
}) {
195+
// (selfHasPermissionForGroupSetting isn't equipped to handle the old-server
196+
// fallback logic for this specific permission; it's dynamic and depends on
197+
// channelPostPolicy, so we do our own null check here.)
198+
if (inChannel.canSendMessageGroup != null) {
199+
return selfHasPermissionForGroupSetting(inChannel.canSendMessageGroup!,
200+
GroupSettingType.stream, 'can_send_message_group');
201+
} else {
202+
return _selfPassesLegacyChannelPostPolicy(inChannel: inChannel, atDate: byDate);
203+
}
204+
}
205+
206+
bool _selfPassesLegacyChannelPostPolicy({
207+
required ZulipStream inChannel,
208+
required DateTime atDate,
194209
}) {
195210
final role = selfUser.role;
196211
// We let the users with [unknown] role to send the message, then the server
@@ -202,7 +217,7 @@ mixin ChannelStore on UserStore {
202217
case ChannelPostPolicy.fullMembers: {
203218
if (!role.isAtLeast(UserRole.member)) return false;
204219
if (role == UserRole.member) {
205-
return selfHasPassedWaitingPeriod(byDate: byDate);
220+
return selfHasPassedWaitingPeriod(byDate: atDate);
206221
}
207222
return true;
208223
}

0 commit comments

Comments
 (0)