Skip to content

Commit b94beb5

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

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/model/store.dart

Lines changed: 14 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.
@@ -474,6 +479,15 @@ Uri? _tryResolveUrlStr(Uri baseUrl, String reference) {
474479
}
475480
}
476481

482+
/// Like [Uri.resolve], but on failure return null instead of throwing.
483+
Uri? _tryResolveUrl(Uri baseUrl, Uri reference) {
484+
try {
485+
return baseUrl.resolveUri(reference);
486+
} on FormatException {
487+
return null;
488+
}
489+
}
490+
477491
/// Store for the user's data for a given Zulip account.
478492
///
479493
/// This should always have a consistent snapshot of the state on the server,

0 commit comments

Comments
 (0)