Skip to content

Commit 35abf84

Browse files
committed
channel [nfc]: s/hasPostingPermission/selfCanSendMessage/; assume self-user
This new name aligns better with the API's naming of the modern group-based permission, can_send_message_group, which we might implement soon.
1 parent 536cbb7 commit 35abf84

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed

lib/model/channel.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,11 @@ mixin ChannelStore on UserStore {
181181
return false;
182182
}
183183

184-
bool hasPostingPermission({
184+
bool selfCanSendMessage({
185185
required ZulipStream inChannel,
186-
required User user,
187186
required DateTime byDate,
188187
}) {
189-
final role = user.role;
188+
final role = selfUser.role;
190189
// We let the users with [unknown] role to send the message, then the server
191190
// will decide to accept it or not based on its actual role.
192191
if (role == UserRole.unknown) return true;
@@ -196,7 +195,7 @@ mixin ChannelStore on UserStore {
196195
case ChannelPostPolicy.fullMembers: {
197196
if (!role.isAtLeast(UserRole.member)) return false;
198197
if (role == UserRole.member) {
199-
return hasPassedWaitingPeriod(user, byDate: byDate);
198+
return hasPassedWaitingPeriod(selfUser, byDate: byDate);
200199
}
201200
return true;
202201
}

lib/widgets/compose_box.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,8 +2153,8 @@ class _ComposeBoxState extends State<ComposeBox> with PerAccountStoreAwareStateM
21532153
case ChannelNarrow(:final streamId):
21542154
case TopicNarrow(:final streamId):
21552155
final channel = store.streams[streamId];
2156-
if (channel == null || !store.hasPostingPermission(inChannel: channel,
2157-
user: store.selfUser, byDate: DateTime.now())) {
2156+
if (channel == null || !store.selfCanSendMessage(inChannel: channel,
2157+
byDate: DateTime.now())) {
21582158
return _ErrorBanner(getLabel: (zulipLocalizations) =>
21592159
zulipLocalizations.errorBannerCannotPostInChannelLabel);
21602160
}

lib/widgets/share.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class SharePage extends StatelessWidget {
191191
body: TabBarView(children: [
192192
SubscriptionListPageBody(
193193
showTopicListButtonInActionSheet: false,
194-
hideChannelsIfUserCantPost: true,
194+
hideChannelsIfUserCantSendMessage: true,
195195
onChannelSelect: (narrow) => _handleNarrowSelect(context, narrow),
196196
// TODO(#412) add onTopicSelect, Currently when user lands on the
197197
// channel feed page from subscription list page and they tap

lib/widgets/subscription_list.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SubscriptionListPageBody extends StatefulWidget {
2020
const SubscriptionListPageBody({
2121
super.key,
2222
this.showTopicListButtonInActionSheet = true,
23-
this.hideChannelsIfUserCantPost = false,
23+
this.hideChannelsIfUserCantSendMessage = false,
2424
this.onChannelSelect,
2525
});
2626

@@ -30,7 +30,7 @@ class SubscriptionListPageBody extends StatefulWidget {
3030
// See discussion:
3131
// https://github.com/zulip/zulip-flutter/pull/1774#discussion_r2249032503
3232
final bool showTopicListButtonInActionSheet;
33-
final bool hideChannelsIfUserCantPost;
33+
final bool hideChannelsIfUserCantSendMessage;
3434

3535
/// Callback to invoke when the user selects a channel from the list.
3636
///
@@ -122,9 +122,8 @@ class _SubscriptionListPageBodyState extends State<SubscriptionListPageBody> wit
122122
final List<Subscription> unpinned = [];
123123
final now = DateTime.now();
124124
for (final subscription in store.subscriptions.values) {
125-
if (widget.hideChannelsIfUserCantPost) {
126-
if (!store.hasPostingPermission(inChannel: subscription,
127-
user: store.selfUser, byDate: now)) {
125+
if (widget.hideChannelsIfUserCantSendMessage) {
126+
if (!store.selfCanSendMessage(inChannel: subscription, byDate: now)) {
128127
continue;
129128
}
130129
}

test/model/channel_test.dart

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,12 @@ void main() {
493493
for (final (ChannelPostPolicy policy, UserRole role, bool canPost) in testCases) {
494494
test('"${role.name}" user ${canPost ? 'can' : "can't"} post in channel '
495495
'with "${policy.name}" policy', () {
496-
final store = eg.store();
497-
final actual = store.hasPostingPermission(
498-
inChannel: eg.stream(channelPostPolicy: policy), user: eg.user(role: role),
496+
final selfUserWithRole = eg.user(role: role);
497+
final store = eg.store(
498+
selfUser: selfUserWithRole,
499+
initialSnapshot: eg.initialSnapshot(realmUsers: [selfUserWithRole]));
500+
final actual = store.selfCanSendMessage(
501+
inChannel: eg.stream(channelPostPolicy: policy),
499502
// [byDate] is not actually relevant for these test cases; for the
500503
// ones which it is, they're practiced below.
501504
byDate: DateTime.now());
@@ -504,27 +507,34 @@ void main() {
504507
}
505508

506509
group('"member" user posting in a channel with "fullMembers" policy', () {
507-
PerAccountStore localStore({required int realmWaitingPeriodThreshold}) =>
508-
eg.store(initialSnapshot: eg.initialSnapshot(
509-
realmWaitingPeriodThreshold: realmWaitingPeriodThreshold));
510+
PerAccountStore localStore({
511+
required User selfUser,
512+
required int realmWaitingPeriodThreshold,
513+
}) => eg.store(
514+
selfUser: selfUser,
515+
initialSnapshot: eg.initialSnapshot(
516+
realmWaitingPeriodThreshold: realmWaitingPeriodThreshold,
517+
realmUsers: [selfUser]));
510518

511519
User memberUser({required String dateJoined}) => eg.user(
512520
role: UserRole.member, dateJoined: dateJoined);
513521

514522
test('a "full" member -> can post in the channel', () {
515-
final store = localStore(realmWaitingPeriodThreshold: 3);
516-
final hasPermission = store.hasPostingPermission(
523+
final store = localStore(
524+
selfUser: memberUser(dateJoined: '2024-11-25T10:00+00:00'),
525+
realmWaitingPeriodThreshold: 3);
526+
final hasPermission = store.selfCanSendMessage(
517527
inChannel: eg.stream(channelPostPolicy: ChannelPostPolicy.fullMembers),
518-
user: memberUser(dateJoined: '2024-11-25T10:00+00:00'),
519528
byDate: DateTime.utc(2024, 11, 28, 10, 00));
520529
check(hasPermission).isTrue();
521530
});
522531

523532
test('not a "full" member -> cannot post in the channel', () {
524-
final store = localStore(realmWaitingPeriodThreshold: 3);
525-
final actual = store.hasPostingPermission(
533+
final store = localStore(
534+
selfUser: memberUser(dateJoined: '2024-11-25T10:00+00:00'),
535+
realmWaitingPeriodThreshold: 3);
536+
final actual = store.selfCanSendMessage(
526537
inChannel: eg.stream(channelPostPolicy: ChannelPostPolicy.fullMembers),
527-
user: memberUser(dateJoined: '2024-11-25T10:00+00:00'),
528538
byDate: DateTime.utc(2024, 11, 28, 09, 59));
529539
check(actual).isFalse();
530540
});

0 commit comments

Comments
 (0)