Skip to content

Commit 83f3f9e

Browse files
store: Add resolveRealmIconUrl
This helper will be used soon to display organization logo in various places.
1 parent c40a8d9 commit 83f3f9e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/model/store.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,11 @@ abstract class PerAccountStoreBase {
433433
// See `UpdateMachine.load`.
434434
Uri get realmIcon => account.realmIcon!;
435435

436+
/// Resolve [realmIcon] as a URL relative to [realmUrl].
437+
///
438+
/// This returns null if resolving fails.
439+
Uri? resolveRealmIconUrl() => _tryResolveUrl(realmUrl, realmIcon);
440+
436441
/// Resolve [reference] as a URL relative to [realmUrl].
437442
///
438443
/// This returns null if [reference] fails to parse as a URL.
@@ -476,6 +481,17 @@ Uri? tryResolveUrlStr(Uri baseUrl, String reference) {
476481
}
477482
}
478483

484+
const _tryResolveUrl = tryResolveUrl;
485+
486+
/// Like [Uri.resolve], but on failure return null instead of throwing.
487+
Uri? tryResolveUrl(Uri baseUrl, Uri reference) {
488+
try {
489+
return baseUrl.resolveUri(reference);
490+
} on FormatException {
491+
return null;
492+
}
493+
}
494+
479495
/// Store for the user's data for a given Zulip account.
480496
///
481497
/// This should always have a consistent snapshot of the state on the server,

0 commit comments

Comments
 (0)