Skip to content

Commit c005b48

Browse files
committed
compose_box: Replace compose box with a banner when cannot post in a channel
Fixes: #674
1 parent e898bc8 commit c005b48

File tree

6 files changed

+278
-79
lines changed

6 files changed

+278
-79
lines changed

assets/l10n/app_en.arb

+4
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@
188188
"@errorBannerDeactivatedDmLabel": {
189189
"description": "Label text for error banner when sending a message to one or multiple deactivated users."
190190
},
191+
"errorBannerCannotPostInChannelLabel": "You do not have permission to post in this channel.",
192+
"@errorBannerCannotPostInChannelLabel": {
193+
"description": "Label text for error banner when sending a message in a channel with no posting permission."
194+
},
191195
"composeBoxAttachFilesTooltip": "Attach files",
192196
"@composeBoxAttachFilesTooltip": {
193197
"description": "Tooltip for compose box icon to attach a file to the message."

lib/widgets/compose_box.dart

+25-9
Original file line numberDiff line numberDiff line change
@@ -999,8 +999,21 @@ class _StreamComposeBoxState extends State<_StreamComposeBox> implements Compose
999999
super.dispose();
10001000
}
10011001

1002+
Widget? _errorBanner(BuildContext context) {
1003+
final store = PerAccountStoreWidget.of(context);
1004+
final selfUser = store.users[store.selfUserId]!;
1005+
final channel = store.streams[widget.narrow.streamId]!;
1006+
return channel.hasPostingPermission(selfUser, realmWaitingPeriodThreshold: store.realmWaitingPeriodThreshold)
1007+
? null : _ErrorBanner(label: ZulipLocalizations.of(context).errorBannerCannotPostInChannelLabel);
1008+
}
1009+
10021010
@override
10031011
Widget build(BuildContext context) {
1012+
final errorBanner = _errorBanner(context);
1013+
if (errorBanner != null) {
1014+
return _ComposeBoxContainer(child: errorBanner);
1015+
}
1016+
10041017
return _ComposeBoxLayout(
10051018
contentController: _contentController,
10061019
contentFocusNode: _contentFocusNode,
@@ -1072,16 +1085,19 @@ class _FixedDestinationComposeBoxState extends State<_FixedDestinationComposeBox
10721085
}
10731086

10741087
Widget? _errorBanner(BuildContext context) {
1075-
if (widget.narrow case DmNarrow(:final otherRecipientIds)) {
1076-
final store = PerAccountStoreWidget.of(context);
1077-
final hasDeactivatedUser = otherRecipientIds.any((id) =>
1078-
!(store.users[id]?.isActive ?? true));
1079-
if (hasDeactivatedUser) {
1080-
return _ErrorBanner(label: ZulipLocalizations.of(context)
1081-
.errorBannerDeactivatedDmLabel);
1082-
}
1088+
final store = PerAccountStoreWidget.of(context);
1089+
switch (widget.narrow) {
1090+
case TopicNarrow():
1091+
final selfUser = store.users[store.selfUserId]!;
1092+
final channel = store.streams[(widget.narrow as TopicNarrow).streamId]!;
1093+
return channel.hasPostingPermission(selfUser, realmWaitingPeriodThreshold: store.realmWaitingPeriodThreshold)
1094+
? null : _ErrorBanner(label: ZulipLocalizations.of(context).errorBannerCannotPostInChannelLabel);
1095+
case DmNarrow(:final otherRecipientIds):
1096+
final hasDeactivatedUser = otherRecipientIds.any((id) =>
1097+
!(store.users[id]?.isActive ?? true));
1098+
return hasDeactivatedUser ? _ErrorBanner(label: ZulipLocalizations.of(context)
1099+
.errorBannerDeactivatedDmLabel) : null;
10831100
}
1084-
return null;
10851101
}
10861102

10871103
@override

test/widgets/action_sheet_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
4343

4444
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
4545
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
46-
await store.addUser(eg.user(userId: message.senderId));
46+
await store.addUsers([eg.selfUser, eg.user(userId: message.senderId)]);
4747
if (message is StreamMessage) {
4848
final stream = eg.stream(streamId: message.streamId);
4949
await store.addStream(stream);

test/widgets/autocomplete_test.dart

+2
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ Future<Finder> setupToTopicInput(WidgetTester tester, {
7676
addTearDown(testBinding.reset);
7777
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
7878
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
79+
await store.addUser(eg.selfUser);
7980
final connection = store.connection as FakeApiConnection;
8081

8182
// prepare message list data
8283
final stream = eg.stream();
84+
await store.addStream(stream);
8385
final message = eg.streamMessage(stream: stream, sender: eg.selfUser);
8486
connection.prepare(json: GetMessagesResult(
8587
anchor: message.id,

0 commit comments

Comments
 (0)