Skip to content

Commit 06be949

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 e913559 commit 06be949

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 = resolveDmElements(
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
@@ -376,6 +376,10 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
376376
/// This returns null if [reference] fails to parse as a URL.
377377
Uri? tryResolveUrl(String reference) => _tryResolveUrl(realmUrl, reference);
378378

379+
/// Always equal to `connection.zulipFeatureLevel`
380+
/// and `account.zulipFeatureLevel`.
381+
int get zulipFeatureLevel => connection.zulipFeatureLevel!;
382+
379383
String get zulipVersion => account.zulipVersion;
380384
final RealmWildcardMentionPolicy realmWildcardMentionPolicy; // TODO(#668): update this realm setting
381385
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
@@ -173,9 +173,9 @@ void showTopicActionSheet(BuildContext context, {
173173
final optionButtons = <ActionSheetMenuItemButton>[];
174174

175175
// TODO(server-7): simplify this condition away
176-
final supportsUnmutingTopics = store.connection.zulipFeatureLevel! >= 170;
176+
final supportsUnmutingTopics = store.zulipFeatureLevel >= 170;
177177
// TODO(server-8): simplify this condition away
178-
final supportsFollowingTopics = store.connection.zulipFeatureLevel! >= 219;
178+
final supportsFollowingTopics = store.zulipFeatureLevel >= 219;
179179

180180
final visibilityOptions = <UserTopicVisibilityPolicy>[];
181181
final visibilityPolicy = store.topicVisibilityPolicy(channelId, topic);
@@ -387,7 +387,7 @@ void showMessageActionSheet({required BuildContext context, required Message mes
387387
final isComposeBoxOffered = messageListPage.composeBoxController != null;
388388

389389
final isMessageRead = message.flags.contains(MessageFlag.read);
390-
final markAsUnreadSupported = store.connection.zulipFeatureLevel! >= 155; // TODO(server-6)
390+
final markAsUnreadSupported = store.zulipFeatureLevel >= 155; // TODO(server-6)
391391
final showMarkAsUnreadButton = markAsUnreadSupported && isMessageRead;
392392

393393
final optionButtons = [

lib/widgets/actions.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ Future<void> unregisterToken(GlobalStore globalStore, int accountId) async {
5555

5656
Future<void> markNarrowAsRead(BuildContext context, Narrow narrow) async {
5757
final store = PerAccountStoreWidget.of(context);
58-
final connection = store.connection;
5958
final zulipLocalizations = ZulipLocalizations.of(context);
60-
final useLegacy = connection.zulipFeatureLevel! < 155; // TODO(server-6)
59+
final useLegacy = store.zulipFeatureLevel < 155; // TODO(server-6)
6160
if (useLegacy) {
6261
try {
6362
await _legacyMarkNarrowAsRead(context, narrow);
@@ -104,8 +103,7 @@ Future<void> markNarrowAsUnreadFromMessage(
104103
Message message,
105104
Narrow narrow,
106105
) async {
107-
final connection = PerAccountStoreWidget.of(context).connection;
108-
assert(connection.zulipFeatureLevel! >= 155); // TODO(server-6)
106+
assert(PerAccountStoreWidget.of(context).zulipFeatureLevel >= 155); // TODO(server-6)
109107
final zulipLocalizations = ZulipLocalizations.of(context);
110108
await updateMessageFlagsStartingFromAnchor(
111109
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)