Skip to content

Commit 00bb86e

Browse files
committed
store [nfc]: Move tryResolveUrl up to base, and use it more
1 parent aa0c600 commit 00bb86e

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

lib/model/emoji.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ class EmojiStoreImpl extends PerAccountStoreBase with EmojiStore {
192192
required String? stillUrl,
193193
required String emojiName,
194194
}) {
195-
final resolvedUrl = tryResolveUrl(realmUrl, sourceUrl);
195+
final resolvedUrl = this.tryResolveUrl(sourceUrl);
196196
if (resolvedUrl == null) return TextEmojiDisplay(emojiName: emojiName);
197197

198198
Uri? resolvedStillUrl;
199199
if (stillUrl != null) {
200-
resolvedStillUrl = tryResolveUrl(realmUrl, stillUrl);
200+
resolvedStillUrl = this.tryResolveUrl(stillUrl);
201201
if (resolvedStillUrl == null) return TextEmojiDisplay(emojiName: emojiName);
202202
}
203203

lib/model/store.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,11 @@ abstract class PerAccountStoreBase {
368368
/// Always equal to `account.realmUrl` and `connection.realmUrl`.
369369
Uri get realmUrl => connection.realmUrl;
370370

371+
/// Resolve [reference] as a URL relative to [realmUrl].
372+
///
373+
/// This returns null if [reference] fails to parse as a URL.
374+
Uri? tryResolveUrl(String reference) => _tryResolveUrl(realmUrl, reference);
375+
371376
////////////////////////////////
372377
// Data attached to the self-account on the realm.
373378

@@ -381,6 +386,17 @@ abstract class PerAccountStoreBase {
381386
Account get account => _globalStore.getAccount(accountId)!;
382387
}
383388

389+
const _tryResolveUrl = tryResolveUrl;
390+
391+
/// Like [Uri.resolve], but on failure return null instead of throwing.
392+
Uri? tryResolveUrl(Uri baseUrl, String reference) {
393+
try {
394+
return baseUrl.resolve(reference);
395+
} on FormatException {
396+
return null;
397+
}
398+
}
399+
384400
/// Store for the user's data for a given Zulip account.
385401
///
386402
/// This should always have a consistent snapshot of the state on the server,
@@ -522,11 +538,6 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
522538
////////////////////////////////
523539
// Data attached to the realm or the server.
524540

525-
/// Resolve [reference] as a URL relative to [realmUrl].
526-
///
527-
/// This returns null if [reference] fails to parse as a URL.
528-
Uri? tryResolveUrl(String reference) => _tryResolveUrl(realmUrl, reference);
529-
530541
/// Always equal to `connection.zulipFeatureLevel`
531542
/// and `account.zulipFeatureLevel`.
532543
int get zulipFeatureLevel => connection.zulipFeatureLevel!;
@@ -899,17 +910,6 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
899910
String toString() => '${objectRuntimeType(this, 'PerAccountStore')}#${shortHash(this)}';
900911
}
901912

902-
const _tryResolveUrl = tryResolveUrl;
903-
904-
/// Like [Uri.resolve], but on failure return null instead of throwing.
905-
Uri? tryResolveUrl(Uri baseUrl, String reference) {
906-
try {
907-
return baseUrl.resolve(reference);
908-
} on FormatException {
909-
return null;
910-
}
911-
}
912-
913913
/// A [GlobalStoreBackend] that uses a live, persistent local database.
914914
///
915915
/// Used as part of a [LiveGlobalStore].

0 commit comments

Comments
 (0)