Skip to content

Commit 41ab0e9

Browse files
committed
compose_box: Replace compose box with a banner when cannot post in a channel
Fixes: #674
1 parent 83e3acd commit 41ab0e9

File tree

3 files changed

+256
-79
lines changed

3 files changed

+256
-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": "Error-banner text replacing the compose box when you do not have permission to send a message to the channel."
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

+28-18
Original file line numberDiff line numberDiff line change
@@ -1071,26 +1071,8 @@ class _FixedDestinationComposeBoxState extends State<_FixedDestinationComposeBox
10711071
super.dispose();
10721072
}
10731073

1074-
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-
}
1083-
}
1084-
return null;
1085-
}
1086-
10871074
@override
10881075
Widget build(BuildContext context) {
1089-
final errorBanner = _errorBanner(context);
1090-
if (errorBanner != null) {
1091-
return _ComposeBoxContainer(child: errorBanner);
1092-
}
1093-
10941076
return _ComposeBoxLayout(
10951077
contentController: _contentController,
10961078
contentFocusNode: _contentFocusNode,
@@ -1127,8 +1109,36 @@ class ComposeBox extends StatelessWidget {
11271109
}
11281110
}
11291111

1112+
Widget? _errorBanner(BuildContext context) {
1113+
final store = PerAccountStoreWidget.of(context);
1114+
final selfUser = store.users[store.selfUserId]!;
1115+
switch (narrow) {
1116+
case ChannelNarrow narrow:
1117+
final channel = store.streams[narrow.streamId]!;
1118+
return channel.hasPostingPermission(selfUser, byDate: DateTime.now(), realmWaitingPeriodThreshold: store.realmWaitingPeriodThreshold)
1119+
? null : _ErrorBanner(label: ZulipLocalizations.of(context).errorBannerCannotPostInChannelLabel);
1120+
case TopicNarrow narrow:
1121+
final channel = store.streams[narrow.streamId]!;
1122+
return channel.hasPostingPermission(selfUser, byDate: DateTime.now(), realmWaitingPeriodThreshold: store.realmWaitingPeriodThreshold)
1123+
? null : _ErrorBanner(label: ZulipLocalizations.of(context).errorBannerCannotPostInChannelLabel);
1124+
case DmNarrow(:final otherRecipientIds):
1125+
final hasDeactivatedUser = otherRecipientIds.any((id) =>
1126+
!(store.users[id]?.isActive ?? true));
1127+
return hasDeactivatedUser ? _ErrorBanner(label: ZulipLocalizations.of(context)
1128+
.errorBannerDeactivatedDmLabel) : null;
1129+
case CombinedFeedNarrow():
1130+
case MentionsNarrow():
1131+
return null;
1132+
}
1133+
}
1134+
11301135
@override
11311136
Widget build(BuildContext context) {
1137+
final errorBanner = _errorBanner(context);
1138+
if (errorBanner != null) {
1139+
return _ComposeBoxContainer(child: errorBanner);
1140+
}
1141+
11321142
final narrow = this.narrow;
11331143
switch (narrow) {
11341144
case ChannelNarrow():

0 commit comments

Comments
 (0)