From 9f006f7bbdd68775066532ac71e5250b6f6af068 Mon Sep 17 00:00:00 2001 From: olorin99 Date: Wed, 29 Apr 2026 17:26:35 +1000 Subject: [PATCH] Enable using domains in feeds on mbin. --- lib/src/api/domains.dart | 4 ++++ lib/src/controller/controller.dart | 9 +++++++-- lib/src/screens/explore/explore_screen.dart | 3 +-- .../screens/settings/feed_settings_screen.dart | 16 ++++++++++------ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/src/api/domains.dart b/lib/src/api/domains.dart index 32fef2fd..fa0bb846 100644 --- a/lib/src/api/domains.dart +++ b/lib/src/api/domains.dart @@ -38,6 +38,10 @@ class MbinAPIDomains { return DomainModel.fromMbin(response.bodyJson); } + Future getByName(String domain) async { + return (await list(search: domain)).items.first; + } + Future putSubscribe(int domainId, bool state) async { final path = '/domain/$domainId/${state ? 'subscribe' : 'unsubscribe'}'; diff --git a/lib/src/controller/controller.dart b/lib/src/controller/controller.dart index 0d48a5d4..a3fb1527 100644 --- a/lib/src/controller/controller.dart +++ b/lib/src/controller/controller.dart @@ -830,7 +830,9 @@ class AppController with ChangeNotifier { .insertOnConflictUpdate( FeedInputsCompanion.insert( feed: name, - name: normalizeName(input.name, instanceHost), + name: input.sourceType == FeedSource.domain + ? input.name + : normalizeName(input.name, instanceHost), source: input.sourceType, ), ); @@ -1003,7 +1005,9 @@ class AppController with ChangeNotifier { } Future fetchCachedFeedInput(String name, FeedSource source) async { - final normalisedName = normalizeName(name, instanceHost); + final normalisedName = source == FeedSource.domain + ? name + : normalizeName(name, instanceHost); final cachedValue = (await (database.select(database.feedSourceCache)..where( (t) => @@ -1028,6 +1032,7 @@ class AppController with ChangeNotifier { instanceHost // tmp until proper getByName method can be made ? throw Exception('Wrong instance') : int.parse(name.split(':').first), + FeedSource.domain => (await api.domains.getByName(normalisedName)).id, _ => null, }; diff --git a/lib/src/screens/explore/explore_screen.dart b/lib/src/screens/explore/explore_screen.dart index f7774db2..d4099a4d 100644 --- a/lib/src/screens/explore/explore_screen.dart +++ b/lib/src/screens/explore/explore_screen.dart @@ -286,8 +286,7 @@ class _ExploreScreenState extends State { padding: chipPadding, ), const SizedBox(width: 4), - if (ac.serverSoftware == ServerSoftware.mbin && - _selected == null) ...[ + if (ac.serverSoftware == ServerSoftware.mbin) ...[ ChoiceChip( label: Text(l(context).domains), selected: type == ExploreType.domains, diff --git a/lib/src/screens/settings/feed_settings_screen.dart b/lib/src/screens/settings/feed_settings_screen.dart index 86ebdef9..2e2261e4 100644 --- a/lib/src/screens/settings/feed_settings_screen.dart +++ b/lib/src/screens/settings/feed_settings_screen.dart @@ -529,11 +529,17 @@ class _EditFeedScreenState extends State { ) .toSet(), onTap: (selected, item) { - var name = switch (item) { - final DetailedCommunityModel i => i.name, - final DetailedUserModel i => i.name, + final name = switch (item) { + final DetailedCommunityModel i => normalizeName( + i.name, + ac.instanceHost, + ), + final DetailedUserModel i => normalizeName( + i.name, + ac.instanceHost, + ), final DomainModel i => i.name, - final FeedModel i => i.name, + final FeedModel i => normalizeName(i.name, ac.instanceHost), _ => null, }; final source = switch (item) { @@ -550,8 +556,6 @@ class _EditFeedScreenState extends State { if (name == null || source == null) return; - name = normalizeName(name, ac.instanceHost); - if (selected) { addInput( FeedInput(name: name, sourceType: source, serverId: id),