From 720d5d29274a7864e7a2c040e2c8a2ef6ea5792f Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Wed, 11 Dec 2024 07:47:11 +0900 Subject: [PATCH] fix: add fallbacks for the server background images (#494) --- .../widget/misskey_server_background.dart | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/view/widget/misskey_server_background.dart b/lib/view/widget/misskey_server_background.dart index 29f29516..48e47e3f 100644 --- a/lib/view/widget/misskey_server_background.dart +++ b/lib/view/widget/misskey_server_background.dart @@ -18,10 +18,29 @@ class MisskeyServerBackground extends HookConsumerWidget { final Widget child; String? getBackgroundImageUrl(JoinMisskeyInstanceInfo? server) { - return server?.meta?['backgroundImageUrl'] as String? ?? - (server != null && server.icon - ? 'https://instanceapp.misskey.page/instance-icons/${server.url}.webp' - : null); + if (server == null) { + return null; + } + if (server.meta?['backgroundImageUrl'] case final String url + when url.isNotEmpty) { + return url; + } + if (server.background) { + return 'https://instanceapp.misskey.page/instance-backgrounds/${server.url}.webp'; + } + if (server.meta?['bannerUrl'] case final String url when url.isNotEmpty) { + return url; + } + if (server.banner) { + return 'https://instanceapp.misskey.page/instance-banners/${server.url}.webp'; + } + if (server.meta?['iconUrl'] case final String url when url.isNotEmpty) { + return url; + } + if (server.icon) { + return 'https://instanceapp.misskey.page/instance-icons/${server.url}.webp'; + } + return null; } @override