Skip to content

Commit ea46825

Browse files
committed
store [nfc]: Add a zulipFeatureLevel getter
This is more convenient than going through store.connection, and should reduce the temptation to go through store.account.
1 parent 581e377 commit ea46825

File tree

8 files changed

+16
-14
lines changed

8 files changed

+16
-14
lines changed

lib/model/autocomplete.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,13 +622,13 @@ class MentionAutocompleteView extends AutocompleteView<MentionAutocompleteQuery,
622622
if (tryOption(WildcardMentionOption.all)) break all;
623623
if (tryOption(WildcardMentionOption.everyone)) break all;
624624
if (isComposingChannelMessage) {
625-
final isChannelWildcardAvailable = store.account.zulipFeatureLevel >= 247; // TODO(server-9)
625+
final isChannelWildcardAvailable = store.zulipFeatureLevel >= 247; // TODO(server-9)
626626
if (isChannelWildcardAvailable && tryOption(WildcardMentionOption.channel)) break all;
627627
if (tryOption(WildcardMentionOption.stream)) break all;
628628
}
629629
}
630630

631-
final isTopicWildcardAvailable = store.account.zulipFeatureLevel >= 224; // TODO(server-8)
631+
final isTopicWildcardAvailable = store.zulipFeatureLevel >= 224; // TODO(server-8)
632632
if (isComposingChannelMessage && isTopicWildcardAvailable) {
633633
tryOption(WildcardMentionOption.topic);
634634
}

lib/model/compose.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ String userMention(User user, {bool silent = false, Map<int, User>? users}) {
140140
String wildcardMention(WildcardMentionOption wildcardOption, {
141141
required PerAccountStore store,
142142
}) {
143-
final isChannelWildcardAvailable = store.account.zulipFeatureLevel >= 247; // TODO(server-9)
144-
final isTopicWildcardAvailable = store.account.zulipFeatureLevel >= 224; // TODO(server-8)
143+
final isChannelWildcardAvailable = store.zulipFeatureLevel >= 247; // TODO(server-9)
144+
final isTopicWildcardAvailable = store.zulipFeatureLevel >= 224; // TODO(server-8)
145145

146146
String name = wildcardOption.canonicalString;
147147
switch (wildcardOption) {

lib/model/internal_link.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ String? decodeHashComponent(String str) {
6060
Uri narrowLink(PerAccountStore store, Narrow narrow, {int? nearMessageId}) {
6161
// TODO(server-7)
6262
final apiNarrow = resolveApiNarrowForServer(
63-
narrow.apiEncode(), store.connection.zulipFeatureLevel!);
63+
narrow.apiEncode(), store.zulipFeatureLevel);
6464
final fragment = StringBuffer('narrow');
6565
for (ApiNarrowElement element in apiNarrow) {
6666
fragment.write('/');

lib/model/store.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
405405
/// This returns null if [reference] fails to parse as a URL.
406406
Uri? tryResolveUrl(String reference) => _tryResolveUrl(realmUrl, reference);
407407

408+
/// Always equal to `connection.zulipFeatureLevel`
409+
/// and `account.zulipFeatureLevel`.
410+
int get zulipFeatureLevel => connection.zulipFeatureLevel!;
411+
408412
String get zulipVersion => account.zulipVersion;
409413
final RealmWildcardMentionPolicy realmWildcardMentionPolicy; // TODO(#668): update this realm setting
410414
final bool realmMandatoryTopics; // TODO(#668): update this realm setting

lib/widgets/action_sheet.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ void showTopicActionSheet(BuildContext context, {
182182
final optionButtons = <ActionSheetMenuItemButton>[];
183183

184184
// TODO(server-7): simplify this condition away
185-
final supportsUnmutingTopics = store.connection.zulipFeatureLevel! >= 170;
185+
final supportsUnmutingTopics = store.zulipFeatureLevel >= 170;
186186
// TODO(server-8): simplify this condition away
187-
final supportsFollowingTopics = store.connection.zulipFeatureLevel! >= 219;
187+
final supportsFollowingTopics = store.zulipFeatureLevel >= 219;
188188

189189
final visibilityOptions = <UserTopicVisibilityPolicy>[];
190190
final visibilityPolicy = store.topicVisibilityPolicy(channelId, topic);
@@ -477,7 +477,7 @@ void showMessageActionSheet({required BuildContext context, required Message mes
477477
final isComposeBoxOffered = messageListPage.composeBoxController != null;
478478

479479
final isMessageRead = message.flags.contains(MessageFlag.read);
480-
final markAsUnreadSupported = store.connection.zulipFeatureLevel! >= 155; // TODO(server-6)
480+
final markAsUnreadSupported = store.zulipFeatureLevel >= 155; // TODO(server-6)
481481
final showMarkAsUnreadButton = markAsUnreadSupported && isMessageRead;
482482

483483
final optionButtons = [

lib/widgets/actions.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ abstract final class ZulipAction {
2424
/// for details on the UI feedback, see there.
2525
static Future<void> markNarrowAsRead(BuildContext context, Narrow narrow) async {
2626
final store = PerAccountStoreWidget.of(context);
27-
final connection = store.connection;
2827
final zulipLocalizations = ZulipLocalizations.of(context);
29-
final useLegacy = connection.zulipFeatureLevel! < 155; // TODO(server-6)
28+
final useLegacy = store.zulipFeatureLevel < 155; // TODO(server-6)
3029
if (useLegacy) {
3130
try {
3231
await _legacyMarkNarrowAsRead(context, narrow);
@@ -78,8 +77,7 @@ abstract final class ZulipAction {
7877
Message message,
7978
Narrow narrow,
8079
) async {
81-
final connection = PerAccountStoreWidget.of(context).connection;
82-
assert(connection.zulipFeatureLevel! >= 155); // TODO(server-6)
80+
assert(PerAccountStoreWidget.of(context).zulipFeatureLevel >= 155); // TODO(server-6)
8381
final zulipLocalizations = ZulipLocalizations.of(context);
8482
await updateMessageFlagsStartingFromAnchor(
8583
context: context,

lib/widgets/autocomplete.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class _MentionAutocompleteItem extends StatelessWidget {
241241
required PerAccountStore store,
242242
}) {
243243
final isDmNarrow = narrow is DmNarrow;
244-
final isChannelWildcardAvailable = store.account.zulipFeatureLevel >= 247; // TODO(server-9)
244+
final isChannelWildcardAvailable = store.zulipFeatureLevel >= 247; // TODO(server-9)
245245
final localizations = ZulipLocalizations.of(context);
246246
final description = switch (wildcardOption) {
247247
WildcardMentionOption.all || WildcardMentionOption.everyone => isDmNarrow

lib/widgets/profile.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ProfilePage extends StatelessWidget {
4040
///
4141
/// Returns null if self-user isn't able to see [user]'s real email address.
4242
String? _getDisplayEmailFor(User user, {required PerAccountStore store}) {
43-
if (store.account.zulipFeatureLevel >= 163) { // TODO(server-7)
43+
if (store.zulipFeatureLevel >= 163) { // TODO(server-7)
4444
// A non-null value means self-user has access to [user]'s real email,
4545
// while a null value means it doesn't have access to the email.
4646
// Search for "delivery_email" in https://zulip.com/api/register-queue.

0 commit comments

Comments
 (0)