Skip to content

action_sheet: Add 'Channel feed' button to channel action sheet #1794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@
"@actionSheetOptionListOfTopics": {
"description": "Label for navigating to a channel's topic-list page."
},
"actionSheetOptionChannelFeed": "Channel feed",
"@actionSheetOptionChannelFeed": {
"description": "Label for navigating to a channel's channel-feed page."
},
"actionSheetOptionUnsubscribe": "Unsubscribe",
"@actionSheetOptionUnsubscribe": {
"description": "Label in the channel action sheet for unsubscribing from the channel."
Expand Down
10 changes: 8 additions & 2 deletions lib/generated/l10n/zulip_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ abstract class ZulipLocalizations {
/// **'To upload files, please grant Zulip additional permissions in Settings.'**
String get permissionsDeniedReadExternalStorage;

/// Label in the channel context menu for subscribing to the channel.
/// Label in the channel action sheet for subscribing to the channel.
///
/// In en, this message translates to:
/// **'Subscribe'**
Expand Down Expand Up @@ -305,7 +305,13 @@ abstract class ZulipLocalizations {
/// **'List of topics'**
String get actionSheetOptionListOfTopics;

/// Label in the channel context menu for unsubscribing from the channel.
/// Label for navigating to a channel's channel-feed page.
///
/// In en, this message translates to:
/// **'Channel feed'**
String get actionSheetOptionChannelFeed;

/// Label in the channel action sheet for unsubscribing from the channel.
///
/// In en, this message translates to:
/// **'Unsubscribe'**
Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_ar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
@override
String get actionSheetOptionListOfTopics => 'List of topics';

@override
String get actionSheetOptionChannelFeed => 'Channel feed';

@override
String get actionSheetOptionUnsubscribe => 'Unsubscribe';

Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_de.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class ZulipLocalizationsDe extends ZulipLocalizations {
@override
String get actionSheetOptionListOfTopics => 'Themenliste';

@override
String get actionSheetOptionChannelFeed => 'Channel feed';

@override
String get actionSheetOptionUnsubscribe => 'Unsubscribe';

Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
@override
String get actionSheetOptionListOfTopics => 'List of topics';

@override
String get actionSheetOptionChannelFeed => 'Channel feed';

@override
String get actionSheetOptionUnsubscribe => 'Unsubscribe';

Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_fr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class ZulipLocalizationsFr extends ZulipLocalizations {
@override
String get actionSheetOptionListOfTopics => 'List of topics';

@override
String get actionSheetOptionChannelFeed => 'Channel feed';

@override
String get actionSheetOptionUnsubscribe => 'Unsubscribe';

Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_it.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class ZulipLocalizationsIt extends ZulipLocalizations {
@override
String get actionSheetOptionListOfTopics => 'Elenco degli argomenti';

@override
String get actionSheetOptionChannelFeed => 'Channel feed';

@override
String get actionSheetOptionUnsubscribe => 'Unsubscribe';

Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_ja.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
@override
String get actionSheetOptionListOfTopics => 'トピック一覧';

@override
String get actionSheetOptionChannelFeed => 'Channel feed';

@override
String get actionSheetOptionUnsubscribe => 'Unsubscribe';

Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_nb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class ZulipLocalizationsNb extends ZulipLocalizations {
@override
String get actionSheetOptionListOfTopics => 'List of topics';

@override
String get actionSheetOptionChannelFeed => 'Channel feed';

@override
String get actionSheetOptionUnsubscribe => 'Unsubscribe';

Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_pl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class ZulipLocalizationsPl extends ZulipLocalizations {
@override
String get actionSheetOptionListOfTopics => 'Lista wątków';

@override
String get actionSheetOptionChannelFeed => 'Channel feed';

@override
String get actionSheetOptionUnsubscribe => 'Unsubscribe';

Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class ZulipLocalizationsRu extends ZulipLocalizations {
@override
String get actionSheetOptionListOfTopics => 'Список тем';

@override
String get actionSheetOptionChannelFeed => 'Channel feed';

@override
String get actionSheetOptionUnsubscribe => 'Unsubscribe';

Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_sk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class ZulipLocalizationsSk extends ZulipLocalizations {
@override
String get actionSheetOptionListOfTopics => 'List of topics';

@override
String get actionSheetOptionChannelFeed => 'Channel feed';

@override
String get actionSheetOptionUnsubscribe => 'Unsubscribe';

Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_sl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class ZulipLocalizationsSl extends ZulipLocalizations {
@override
String get actionSheetOptionListOfTopics => 'Seznam tem';

@override
String get actionSheetOptionChannelFeed => 'Channel feed';

@override
String get actionSheetOptionUnsubscribe => 'Unsubscribe';

Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_uk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class ZulipLocalizationsUk extends ZulipLocalizations {
@override
String get actionSheetOptionListOfTopics => 'Список тем';

@override
String get actionSheetOptionChannelFeed => 'Channel feed';

@override
String get actionSheetOptionUnsubscribe => 'Unsubscribe';

Expand Down
3 changes: 3 additions & 0 deletions lib/generated/l10n/zulip_localizations_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class ZulipLocalizationsZh extends ZulipLocalizations {
@override
String get actionSheetOptionListOfTopics => 'List of topics';

@override
String get actionSheetOptionChannelFeed => 'Channel feed';

@override
String get actionSheetOptionUnsubscribe => 'Unsubscribe';

Expand Down
33 changes: 33 additions & 0 deletions lib/widgets/action_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,18 @@ enum BottomSheetDismissButtonStyle {
/// Show a sheet of actions you can take on a channel.
///
/// Needs a [PageRoot] ancestor.
/// May or may not have a [MessageListPage] ancestor;
/// some callers are on that page and some aren't.
void showChannelActionSheet(BuildContext context, {
required int channelId,
}) {
final pageContext = PageRoot.contextOf(context);
final store = PerAccountStoreWidget.of(pageContext);
final messageListPageState = MessageListPage.maybeAncestorOf(pageContext);

final messageListPageNarrow = messageListPageState?.narrow;
final isOnChannelFeed = messageListPageNarrow is ChannelNarrow
&& messageListPageNarrow.streamId == channelId;

final unreadCount = store.unreads.countInChannelNarrow(channelId);
final isSubscribed = store.subscriptions[channelId] != null;
Expand All @@ -255,6 +262,8 @@ void showChannelActionSheet(BuildContext context, {
if (unreadCount > 0)
MarkChannelAsReadButton(pageContext: pageContext, channelId: channelId),
TopicListButton(pageContext: pageContext, channelId: channelId),
if (!isOnChannelFeed)
ChannelFeedButton(pageContext: pageContext, channelId: channelId),
CopyChannelLinkButton(channelId: channelId, pageContext: pageContext)
],
if (isSubscribed)
Expand Down Expand Up @@ -355,6 +364,30 @@ class TopicListButton extends ActionSheetMenuItemButton {
}
}

class ChannelFeedButton extends ActionSheetMenuItemButton {
const ChannelFeedButton({
super.key,
required this.channelId,
required super.pageContext,
});

final int channelId;

@override
IconData get icon => ZulipIcons.message_feed;

@override
String label(ZulipLocalizations zulipLocalizations) {
return zulipLocalizations.actionSheetOptionChannelFeed;
}

@override
void onPressed() {
Navigator.push(pageContext,
MessageListPage.buildRoute(context: pageContext, narrow: ChannelNarrow(channelId)));
}
}

class CopyChannelLinkButton extends ActionSheetMenuItemButton {
const CopyChannelLinkButton({
super.key,
Expand Down
22 changes: 19 additions & 3 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,30 @@ class MessageListPage extends StatefulWidget {
///
/// Uses the inefficient [BuildContext.findAncestorStateOfType];
/// don't call this in a build method.
// If we do find ourselves wanting this in a build method, it won't be hard
// to enable that: we'd just need to add an [InheritedWidget] here.
///
/// See also:
/// * [maybeAncestorOf], which returns null instead of throwing
/// when an ancestor [MessageListPageState] is not found.
static MessageListPageState ancestorOf(BuildContext context) {
final state = context.findAncestorStateOfType<_MessageListPageState>();
final state = maybeAncestorOf(context);
assert(state != null, 'No MessageListPage ancestor');
return state!;
}

/// The [MessageListPageState] above this context in the tree, if any.
///
/// Uses the inefficient [BuildContext.findAncestorStateOfType];
/// don't call this in a build method.
///
/// See also:
/// * [ancestorOf], which throws instead of returning null
/// when an ancestor [MessageListPageState] is not found.
// If we do find ourselves wanting this in a build method, it won't be hard
// to enable that: we'd just need to add an [InheritedWidget] here.
static MessageListPageState? maybeAncestorOf(BuildContext context) {
return context.findAncestorStateOfType<_MessageListPageState>();
}

final Narrow initNarrow;
final int? initAnchorMessageId; // TODO(#1564) highlight target upon load

Expand Down
Loading