diff --git a/lib/src/controller/controller.dart b/lib/src/controller/controller.dart index 115a4731..fd186a98 100644 --- a/lib/src/controller/controller.dart +++ b/lib/src/controller/controller.dart @@ -236,10 +236,10 @@ class AppController with ChangeNotifier { ); if (_servers.isEmpty || _accounts.isEmpty || _selectedAccount.isEmpty) { - await saveServer(ServerSoftware.mbin, 'kbin.earth'); + await saveServer(defaultSoftware, defaultInstance); await setAccount( - '@kbin.earth', - const Account(handle: '@kbin.earth', isPushRegistered: false), + defaultAccount, + const Account(handle: defaultAccount, isPushRegistered: false), switchNow: true, ); } @@ -607,7 +607,7 @@ class AppController with ChangeNotifier { _rebuildProfile(); _accounts.remove(key); - _selectedAccount = _accounts.keys.firstOrNull ?? '@kbin.earth'; + _selectedAccount = _accounts.keys.firstOrNull ?? defaultAccount; // If there are no accounts left from a server, then remove the server's data final keyAccountServer = key.split('@').last; @@ -634,10 +634,10 @@ class AppController with ChangeNotifier { // Ensure default guest account remains if (_servers.isEmpty || _accounts.isEmpty || _selectedAccount.isEmpty) { - await saveServer(ServerSoftware.mbin, 'kbin.earth'); + await saveServer(defaultSoftware, defaultInstance); await setAccount( - '@kbin.earth', - const Account(handle: '@kbin.earth', isPushRegistered: false), + defaultAccount, + const Account(handle: defaultAccount, isPushRegistered: false), switchNow: true, ); } diff --git a/lib/src/controller/database/database.dart b/lib/src/controller/database/database.dart index 58930459..715ff151 100644 --- a/lib/src/controller/database/database.dart +++ b/lib/src/controller/database/database.dart @@ -30,6 +30,15 @@ import 'package:sembast/sembast_io.dart'; part 'database.g.dart'; +final ServerSoftware defaultSoftware = ServerSoftware.values.byName( + const String.fromEnvironment('defaultSoftware', defaultValue: 'mbin'), +); +const defaultInstance = String.fromEnvironment( + 'defaultInstance', + defaultValue: 'kbin.earth', +); +const defaultAccount = '@$defaultInstance'; + class CredentialsConverter extends TypeConverter with JsonTypeConverter2 { const CredentialsConverter(); @@ -58,7 +67,7 @@ class CredentialsConverter extends TypeConverter @TableIndex(name: 'account_unifiedpushToken', columns: {#unifiedpushToken}) class Accounts extends Table { TextColumn get handle => - text().withLength(min: 1).clientDefault(() => '@kbin.earth')(); + text().withLength(min: 1).clientDefault(() => defaultAccount)(); TextColumn get oauth => text().map(const CredentialsConverter()).nullable()(); TextColumn get jwt => text().nullable()(); BoolColumn get isPushRegistered => @@ -363,7 +372,7 @@ class MiscCache extends Table { )(); TextColumn get selectedAccount => text() .references(Accounts, #handle, onDelete: KeyAction.setDefault) - .clientDefault(() => '@kbin.earth')(); + .clientDefault(() => defaultAccount)(); TextColumn get webPushKeys => text().nullable()(); TextColumn get downloadsDir => text().nullable()(); BoolColumn get expandNavDrawer => diff --git a/lib/src/controller/router.dart b/lib/src/controller/router.dart index 19750786..f5618dcb 100644 --- a/lib/src/controller/router.dart +++ b/lib/src/controller/router.dart @@ -10,45 +10,55 @@ class AppRouter extends RootStackRouter { @override List get routes => [ - AutoRoute(page: AppHome.page, path: '/'), - AutoRoute(page: FeedRoute.page, path: '/feed'), - AutoRoute(page: ExploreRoute.page, path: '/explore'), + AutoRoute( + page: AppInstanceRoute.page, + path: '/:instance', + children: [ + AutoRoute(page: AppHome.page, path: ''), + AutoRoute(page: FeedRoute.page, path: 'feed'), + AutoRoute(page: ExploreRoute.page, path: 'explore'), - AutoRoute(page: ThreadRoute.page, path: '/thread/:id'), - AutoRoute(page: MicroblogRoute.page, path: '/microblog/:id'), - AutoRoute(page: PostCommentRoute.page, path: '/comment/:id'), - AutoRoute(page: ContentReplyRoute.page, path: '/reply'), + AutoRoute(page: ThreadRoute.page, path: 'c/:communityName/thread/:id'), + AutoRoute( + page: MicroblogRoute.page, + path: 'c/:communityName/microblog/:id', + ), + AutoRoute(page: PostCommentRoute.page, path: 'comment/:id'), + AutoRoute(page: ContentReplyRoute.page, path: 'reply'), - AutoRoute(page: UserRoute.page, path: '/user/:userId'), - AutoRoute(page: ModLogUserRoute.page, path: '/user/:userId/modlog'), - AutoRoute(page: MessageThreadRoute.page, path: '/user/:userId/message'), + AutoRoute(page: UserRoute.page, path: 'u/:username'), + AutoRoute(page: ModLogUserRoute.page, path: 'u/:username/modlog'), + AutoRoute(page: MessageThreadRoute.page, path: 'u/:username/message'), - AutoRoute(page: CommunityRoute.page, path: '/community/:communityId'), - AutoRoute( - page: ModLogCommunityRoute.page, - path: '/community/:communityId/modlog', - ), - AutoRoute( - page: CommunityModPanelRoute.page, - path: '/community/:communityId/mod', - ), - AutoRoute( - page: CommunityOwnerPanelRoute.page, - path: '/community/:communityId/owner', - ), + AutoRoute(page: CommunityRoute.page, path: 'c/:communityName'), + AutoRoute( + page: ModLogCommunityRoute.page, + path: 'c/:communityName/modlog', + ), + AutoRoute( + page: CommunityModPanelRoute.page, + path: 'c/:communityName/mod', + ), + AutoRoute( + page: CommunityOwnerPanelRoute.page, + path: 'c/:communityName/owner', + ), - AutoRoute(page: ModLogRoute.page, path: '/modlog'), - AutoRoute(page: DomainRoute.page, path: '/domain'), - AutoRoute(page: CreateRoute.page, path: '/create'), - AutoRoute(page: AdvancedImageRoute.page, path: '/image'), - AutoRoute(page: TagUsersRoute.page, path: '/tags/:tag'), - AutoRoute(page: TagEditorRoute.page, path: '/tags-editor/:tag'), - AutoRoute(page: BookmarkListRoute.page, path: '/bookmarks'), - AutoRoute(page: BookmarksRoute.page, path: '/bookmarks/:bookmarkList'), - AutoRoute(page: ProfileEditRoute.page, path: '/account/edit'), - AutoRoute(page: EditProfileRoute.page, path: '/profile/edit'), - AutoRoute(page: EditFilterListRoute.page, path: '/filter/:filterList'), - AutoRoute(page: EditFeedRoute.page, path: '/feed/:feed/edit'), + AutoRoute(page: ModLogRoute.page, path: 'modlog'), + AutoRoute(page: DomainRoute.page, path: 'domain'), + AutoRoute(page: CreateRoute.page, path: 'create'), + AutoRoute(page: AdvancedImageRoute.page, path: 'image'), + AutoRoute(page: TagUsersRoute.page, path: 'tags/:tag'), + AutoRoute(page: TagEditorRoute.page, path: 'tags-editor/:tag'), + AutoRoute(page: BookmarkListRoute.page, path: 'bookmarks'), + AutoRoute(page: BookmarksRoute.page, path: 'bookmarks/:bookmarkList'), + AutoRoute(page: ProfileEditRoute.page, path: 'account/edit'), + AutoRoute(page: EditProfileRoute.page, path: 'profile/edit'), + AutoRoute(page: EditFilterListRoute.page, path: 'filter/:filterList'), + AutoRoute(page: EditFeedRoute.page, path: 'feed/:feed/edit'), + ], + ), + RedirectRoute(path: '/', redirectTo: '/$defaultInstance'), //settings AutoRoute(page: BehaviorSettingsRoute.page, path: '/settings/behavior'), diff --git a/lib/src/screens/account/messages/message_thread_item.dart b/lib/src/screens/account/messages/message_thread_item.dart index abb70f91..f45a797c 100644 --- a/lib/src/screens/account/messages/message_thread_item.dart +++ b/lib/src/screens/account/messages/message_thread_item.dart @@ -100,7 +100,10 @@ class MessageThreadItem extends StatelessWidget { currMessage.sender.name, icon: currMessage.sender.avatar, onTap: () => context.router.push( - UserRoute(userId: currMessage.sender.id), + UserRoute( + username: currMessage.sender.name, + userId: currMessage.sender.id, + ), ), ), ], diff --git a/lib/src/screens/account/notification/notification_item.dart b/lib/src/screens/account/notification/notification_item.dart index 250ac637..94fa1d6f 100644 --- a/lib/src/screens/account/notification/notification_item.dart +++ b/lib/src/screens/account/notification/notification_item.dart @@ -193,7 +193,10 @@ class _NotificationItemState extends State { widget.item.creator!.name, icon: widget.item.creator!.avatar, onTap: () => context.router.push( - UserRoute(userId: widget.item.creator!.id), + UserRoute( + username: widget.item.creator!.name, + userId: widget.item.creator!.id, + ), ), ), ), @@ -208,6 +211,7 @@ class _NotificationItemState extends State { icon: bannedCommunity.icon, onTap: () => context.router.push( CommunityRoute( + communityName: bannedCommunity.name, communityId: bannedCommunity.id, ), ), diff --git a/lib/src/screens/account/self_feed.dart b/lib/src/screens/account/self_feed.dart index b10507cd..393d187d 100644 --- a/lib/src/screens/account/self_feed.dart +++ b/lib/src/screens/account/self_feed.dart @@ -66,6 +66,6 @@ class _SelfFeedState extends State final user = _meUser!; - return UserScreen(user.id, initData: _meUser); + return UserScreen(username: user.name, userId: user.id, initData: _meUser); } } diff --git a/lib/src/screens/app_home.dart b/lib/src/screens/app_home.dart index 9494074b..75b10d70 100644 --- a/lib/src/screens/app_home.dart +++ b/lib/src/screens/app_home.dart @@ -4,6 +4,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:interstellar/src/controller/controller.dart'; +import 'package:interstellar/src/controller/router.dart'; import 'package:interstellar/src/controller/router.gr.dart'; import 'package:interstellar/src/screens/account/inbox_screen.dart'; import 'package:interstellar/src/screens/account/notification/notification_badge.dart'; @@ -20,6 +21,21 @@ import 'package:interstellar/src/widgets/wrapper.dart'; import 'package:material_symbols_icons/symbols.dart'; import 'package:provider/provider.dart'; +@RoutePage() +class AppInstanceScreen extends StatelessWidget { + const AppInstanceScreen({ + @PathParam('instance') required this.instance, + super.key, + }); + + final String instance; + + @override + Widget build(BuildContext context) { + return const Scaffold(body: AutoRouter()); + } +} + @RoutePage() class AppHome extends StatefulWidget { const AppHome({super.key}); @@ -123,6 +139,7 @@ class _AppHomeState extends State { _accountKey = UniqueKey(); _inboxKey = UniqueKey(); }); + context.router.root.replace(AppInstanceRoute(instance: ac.instanceHost)); }; final notCompact = !Breakpoints.isCompact(context); diff --git a/lib/src/screens/explore/bookmarks_screen.dart b/lib/src/screens/explore/bookmarks_screen.dart index 955e127f..6064563c 100644 --- a/lib/src/screens/explore/bookmarks_screen.dart +++ b/lib/src/screens/explore/bookmarks_screen.dart @@ -205,6 +205,7 @@ class _BookmarksScreenState extends State { _pagingController.updateItem(newValue.id, newValue), onTap: () => pushPostPage( context, + communityName: item.community.name, postId: item.id, postType: item.type, initData: item, diff --git a/lib/src/screens/explore/community_mod_panel.dart b/lib/src/screens/explore/community_mod_panel.dart index c1fe392d..14f4f647 100644 --- a/lib/src/screens/explore/community_mod_panel.dart +++ b/lib/src/screens/explore/community_mod_panel.dart @@ -226,6 +226,7 @@ class _MagazineModPanelReportsState extends State { if (item.subjectPost != null) { pushPostPage( context, + communityName: item.subjectPost!.community.name, postId: item.subjectPost!.id, postType: item.subjectPost!.type, initData: item.subjectPost, @@ -255,7 +256,10 @@ class _MagazineModPanelReportsState extends State { item.reportedBy!.name, icon: item.reportedBy!.avatar, onTap: () => context.router.push( - UserRoute(userId: item.reportedBy!.id), + UserRoute( + username: item.reportedBy!.name, + userId: item.reportedBy!.id, + ), ), ), ], diff --git a/lib/src/screens/explore/community_screen.dart b/lib/src/screens/explore/community_screen.dart index 998542a5..6e322343 100644 --- a/lib/src/screens/explore/community_screen.dart +++ b/lib/src/screens/explore/community_screen.dart @@ -22,14 +22,16 @@ import 'package:provider/provider.dart'; @RoutePage() class CommunityScreen extends StatefulWidget { - const CommunityScreen( - @PathParam('communityId') this.communityId, { + const CommunityScreen({ + @PathParam('communityName') required this.communityName, + this.communityId, super.key, this.initData, this.onUpdate, }); - final int communityId; + final String communityName; + final int? communityId; final DetailedCommunityModel? initData; final void Function(DetailedCommunityModel)? onUpdate; @@ -47,14 +49,19 @@ class _CommunityScreenState extends State { _data = widget.initData; if (_data == null) { - context.read().api.community.get(widget.communityId).then(( - value, - ) { - if (!mounted) return; - setState(() { - _data = value; - }); - }); + (widget.communityId == null + ? context.read().api.community.getByName( + widget.communityName, + ) + : context.read().api.community.get( + widget.communityId!, + )) + .then((value) { + if (!mounted) return; + setState(() { + _data = value; + }); + }); } } @@ -62,6 +69,8 @@ class _CommunityScreenState extends State { Widget build(BuildContext context) { final ac = context.watch(); + if (_data == null) return Container(); + final globalName = _data == null ? null : _data!.name.contains('@') @@ -72,7 +81,7 @@ class _CommunityScreenState extends State { feed: FeedAggregator.fromSingleSource( name: _data?.name ?? '', source: FeedSource.community, - sourceId: widget.communityId, + sourceId: _data?.id, ), createPostCommunity: _data, details: _data == null diff --git a/lib/src/screens/explore/explore_screen_item.dart b/lib/src/screens/explore/explore_screen_item.dart index 29336a9d..944f6051 100644 --- a/lib/src/screens/explore/explore_screen_item.dart +++ b/lib/src/screens/explore/explore_screen_item.dart @@ -111,10 +111,20 @@ class ExploreScreenItem extends StatelessWidget { }; final navigate = switch (item) { final DetailedCommunityModel i => () => context.router.push( - CommunityRoute(communityId: i.id, initData: i, onUpdate: onUpdate), + CommunityRoute( + communityName: i.name, + communityId: i.id, + initData: i, + onUpdate: onUpdate, + ), ), final DetailedUserModel i => () => context.router.push( - UserRoute(userId: i.id, initData: i, onUpdate: onUpdate), + UserRoute( + username: i.name, + userId: i.id, + initData: i, + onUpdate: onUpdate, + ), ), final DomainModel i => () => context.router.push( DomainRoute(domainId: i.id, initData: i, onUpdate: onUpdate), @@ -195,6 +205,7 @@ class ExploreScreenItem extends StatelessWidget { child: InkWell( onTap: () => pushPostPage( context, + communityName: item.community.name, postId: item.id, postType: item.type, initData: item, diff --git a/lib/src/screens/explore/mod_log.dart b/lib/src/screens/explore/mod_log.dart index d3ab348d..68f690e6 100644 --- a/lib/src/screens/explore/mod_log.dart +++ b/lib/src/screens/explore/mod_log.dart @@ -19,10 +19,12 @@ import 'package:provider/provider.dart'; @RoutePage() class ModLogCommunityScreen extends StatelessWidget { const ModLogCommunityScreen({ - @PathParam('communityId') required this.communityId, + @PathParam('communityName') required this.communityName, + required this.communityId, super.key, }); + final String communityName; final int communityId; @override @@ -32,10 +34,12 @@ class ModLogCommunityScreen extends StatelessWidget { @RoutePage() class ModLogUserScreen extends StatelessWidget { const ModLogUserScreen({ - @PathParam('userId') required this.userId, + @PathParam('username') required this.username, + required this.userId, super.key, }); + final String username; final int userId; @override @@ -92,6 +96,7 @@ class _ModLogScreenState extends State { ? null : () => pushPostPage( context, + communityName: item.community.name, postId: item.postId, postType: PostType.thread, ), @@ -100,6 +105,7 @@ class _ModLogScreenState extends State { ? null : () => pushPostPage( context, + communityName: item.community.name, postId: item.postId, postType: PostType.thread, ), @@ -126,6 +132,7 @@ class _ModLogScreenState extends State { ? null : () => pushPostPage( context, + communityName: item.community.name, postId: item.postId, postType: PostType.thread, ), @@ -134,6 +141,7 @@ class _ModLogScreenState extends State { ? null : () => pushPostPage( context, + communityName: item.community.name, postId: item.postId, postType: PostType.thread, ), @@ -142,6 +150,7 @@ class _ModLogScreenState extends State { ? null : () => pushPostPage( context, + communityName: item.community.name, postId: item.postId, postType: PostType.thread, ), @@ -150,6 +159,7 @@ class _ModLogScreenState extends State { ? null : () => pushPostPage( context, + communityName: item.community.name, postId: item.postId, postType: PostType.thread, ), @@ -174,30 +184,45 @@ class _ModLogScreenState extends State { ModLogType.ban => item.user == null ? null - : () => context.router.push(UserRoute(userId: item.user!.id)), + : () => context.router.push( + UserRoute(username: item.user!.name, userId: item.user!.id), + ), ModLogType.unban => item.user == null ? null - : () => context.router.push(UserRoute(userId: item.user!.id)), + : () => context.router.push( + UserRoute(username: item.user!.name, userId: item.user!.id), + ), ModLogType.moderatorAdded => item.user == null ? null - : () => context.router.push(UserRoute(userId: item.user!.id)), + : () => context.router.push( + UserRoute(username: item.user!.name, userId: item.user!.id), + ), ModLogType.moderatorRemoved => item.user == null ? null - : () => context.router.push(UserRoute(userId: item.user!.id)), + : () => context.router.push( + UserRoute(username: item.user!.name, userId: item.user!.id), + ), ModLogType.communityAdded => () => context.router.push( - CommunityRoute(communityId: item.community.id), + CommunityRoute( + communityName: item.community.name, + communityId: item.community.id, + ), ), ModLogType.communityRemoved => () => context.router.push( - CommunityRoute(communityId: item.community.id), + CommunityRoute( + communityName: item.community.name, + communityId: item.community.id, + ), ), ModLogType.postLocked => item.postId == null ? null : () => pushPostPage( context, + communityName: item.community.name, postId: item.postId, postType: PostType.thread, ), @@ -206,6 +231,7 @@ class _ModLogScreenState extends State { ? null : () => pushPostPage( context, + communityName: item.community.name, postId: item.postId, postType: PostType.thread, ), diff --git a/lib/src/screens/explore/user_item.dart b/lib/src/screens/explore/user_item.dart index efc6c158..f054ee6b 100644 --- a/lib/src/screens/explore/user_item.dart +++ b/lib/src/screens/explore/user_item.dart @@ -24,7 +24,9 @@ class UserItemSimple extends StatelessWidget { return InkWell( onTap: noTap ? null - : () => context.router.push(UserRoute(userId: user.id)), + : () => context.router.push( + UserRoute(username: user.name, userId: user.id), + ), child: Padding( padding: const EdgeInsets.all(12), child: Row( diff --git a/lib/src/screens/explore/user_screen.dart b/lib/src/screens/explore/user_screen.dart index a9973dd1..229bb7e8 100644 --- a/lib/src/screens/explore/user_screen.dart +++ b/lib/src/screens/explore/user_screen.dart @@ -38,14 +38,16 @@ enum UserFeedType { thread, microblog, comment, reply, follower, following } @RoutePage() class UserScreen extends StatefulWidget { - const UserScreen( - @PathParam('userId') this.userId, { + const UserScreen({ + @PathParam('username') required this.username, + this.userId, super.key, this.initData, this.onUpdate, }); - final int userId; + final String username; + final int? userId; final DetailedUserModel? initData; final void Function(DetailedUserModel)? onUpdate; @@ -76,11 +78,11 @@ class _UserScreenState extends State { _sort = context.read().profile.feedDefaultExploreSort; if (_data == null) { - context - .read() - .api - .users - .get(widget.userId) + (widget.userId == null + ? context.read().api.users.getByName( + widget.username, + ) + : context.read().api.users.get(widget.userId!)) .then((value) async { if (!context.mounted) return value; @@ -626,6 +628,7 @@ class _UserScreenBodyState extends State (newValue) => _pagingController.updateItem(item, newValue), onTap: () => pushPostPage( context, + communityName: item.community.name, postId: item.id, postType: item.type, initData: item, diff --git a/lib/src/screens/feed/create_screen.dart b/lib/src/screens/feed/create_screen.dart index cd52ed04..2512a84b 100644 --- a/lib/src/screens/feed/create_screen.dart +++ b/lib/src/screens/feed/create_screen.dart @@ -601,6 +601,7 @@ class _CreateScreenState extends State { context.router.pop(); context.router.push( CommunityRoute( + communityName: newCommunity.name, communityId: newCommunity.id, initData: newCommunity, ), diff --git a/lib/src/screens/feed/feed_screen.dart b/lib/src/screens/feed/feed_screen.dart index 15853585..9608573f 100644 --- a/lib/src/screens/feed/feed_screen.dart +++ b/lib/src/screens/feed/feed_screen.dart @@ -850,6 +850,7 @@ class _FeedScreenBodyState extends State void onPostTap() { pushPostPage( context, + communityName: item.community.name, initData: item, userCanModerate: widget.userCanModerate, onUpdate: (newValue) => diff --git a/lib/src/screens/feed/nav_drawer.dart b/lib/src/screens/feed/nav_drawer.dart index a496a611..4f027aa3 100644 --- a/lib/src/screens/feed/nav_drawer.dart +++ b/lib/src/screens/feed/nav_drawer.dart @@ -193,7 +193,11 @@ class _NavDrawerState extends State { if (!context.mounted) return; context.router.push( - UserRoute(userId: user.id, initData: user), + UserRoute( + username: user.name, + userId: user.id, + initData: user, + ), ); case '!': @@ -203,6 +207,7 @@ class _NavDrawerState extends State { context.router.push( CommunityRoute( + communityName: community.name, communityId: community.id, initData: community, ), @@ -299,6 +304,7 @@ class _NavDrawerState extends State { ), onTap: () => context.router.push( CommunityRoute( + communityName: community.name, communityId: community.id, initData: community, onUpdate: (newValue) => setState(() { @@ -371,6 +377,7 @@ class _NavDrawerState extends State { ), onTap: () => context.router.push( UserRoute( + username: user.name, userId: user.id, initData: user, onUpdate: (newValue) => setState(() { diff --git a/lib/src/screens/feed/post_comment_screen.dart b/lib/src/screens/feed/post_comment_screen.dart index cbf11f2b..810313bc 100644 --- a/lib/src/screens/feed/post_comment_screen.dart +++ b/lib/src/screens/feed/post_comment_screen.dart @@ -70,6 +70,7 @@ class _PostCommentScreenState extends State { child: OutlinedButton( onPressed: () => pushPostPage( context, + communityName: comment.community.name, postId: comment.postId, postType: comment.postType, ), diff --git a/lib/src/screens/feed/post_page.dart b/lib/src/screens/feed/post_page.dart index fccababd..99fc0903 100644 --- a/lib/src/screens/feed/post_page.dart +++ b/lib/src/screens/feed/post_page.dart @@ -26,6 +26,7 @@ import 'package:provider/provider.dart'; @RoutePage() class ThreadPage extends StatelessWidget { const ThreadPage({ + @PathParam('communityName') this.communityName, @PathParam('id') required this.postId, super.key, this.initData, @@ -33,6 +34,7 @@ class ThreadPage extends StatelessWidget { this.userCanModerate = false, }); + final String? communityName; final int postId; final PostModel? initData; final void Function(PostModel)? onUpdate; @@ -51,6 +53,7 @@ class ThreadPage extends StatelessWidget { @RoutePage() class MicroblogPage extends StatelessWidget { const MicroblogPage({ + @PathParam('communityName') this.communityName, @PathParam('id') required this.postId, super.key, this.initData, @@ -58,6 +61,7 @@ class MicroblogPage extends StatelessWidget { this.userCanModerate = false, }); + final String? communityName; final int postId; final PostModel? initData; final void Function(PostModel)? onUpdate; @@ -75,6 +79,7 @@ class MicroblogPage extends StatelessWidget { Future pushPostPage( BuildContext context, { + String? communityName, int? postId, PostType? postType, PostModel? initData, @@ -87,12 +92,14 @@ Future pushPostPage( context.router.push( type == PostType.thread ? ThreadRoute( + communityName: communityName, postId: id, initData: initData, userCanModerate: userCanModerate, onUpdate: onUpdate, ) : MicroblogRoute( + communityName: communityName, postId: id, initData: initData, userCanModerate: userCanModerate, @@ -566,8 +573,11 @@ class _PostPageState extends State { subtitle: l( context, ).commentsX(crossPost.numComments), - onTap: () async => - pushPostPage(context, initData: crossPost), + onTap: () async => pushPostPage( + context, + communityName: crossPost.community.name, + initData: crossPost, + ), ), ) .toList(), @@ -609,8 +619,11 @@ class _PostPageState extends State { showCrossPostMenu(context, crossPost), icon: const Icon(Symbols.more_vert_rounded), ), - onTap: () => - pushPostPage(context, initData: crossPost), + onTap: () => pushPostPage( + context, + communityName: crossPost.community.name, + initData: crossPost, + ), onLongPress: () => showCrossPostMenu(context, crossPost), ), diff --git a/lib/src/screens/settings/about_screen.dart b/lib/src/screens/settings/about_screen.dart index 3132281f..c907e1e9 100644 --- a/lib/src/screens/settings/about_screen.dart +++ b/lib/src/screens/settings/about_screen.dart @@ -96,6 +96,7 @@ class _AboutScreenState extends State { context.router.push( CommunityRoute( + communityName: community.name, communityId: community.id, initData: community, ), @@ -126,6 +127,7 @@ class _AboutScreenState extends State { context.router.push( CommunityRoute( + communityName: community.name, communityId: community.id, initData: community, ), diff --git a/lib/src/widgets/community_picker.dart b/lib/src/widgets/community_picker.dart index 25eaf857..f96266da 100644 --- a/lib/src/widgets/community_picker.dart +++ b/lib/src/widgets/community_picker.dart @@ -48,6 +48,7 @@ class _CommunityPickerState extends State { : IconButton( onPressed: () => context.router.push( CommunityRoute( + communityName: widget.value!.name, communityId: widget.value!.id, initData: widget.value, onUpdate: (newValue) => widget.onChange(newValue), diff --git a/lib/src/widgets/content_item/content_info.dart b/lib/src/widgets/content_item/content_info.dart index 4411f15c..194ffe2b 100644 --- a/lib/src/widgets/content_item/content_info.dart +++ b/lib/src/widgets/content_item/content_info.dart @@ -148,8 +148,9 @@ class ContentInfo extends StatelessWidget { user!.name, displayName: user!.displayName, icon: user!.avatar, - onTap: () => - context.router.push(UserRoute(userId: user!.id)), + onTap: () => context.router.push( + UserRoute(username: user!.name, userId: user!.id), + ), ), ), UserStatusIcons(cakeDay: user!.createdAt, isBot: user!.isBot), @@ -179,7 +180,10 @@ class ContentInfo extends StatelessWidget { community!.name, icon: community!.icon, onTap: () => context.router.push( - CommunityRoute(communityId: community!.id), + CommunityRoute( + communityName: community!.name, + communityId: community!.id, + ), ), ), ); diff --git a/lib/src/widgets/markdown/markdown_mention.dart b/lib/src/widgets/markdown/markdown_mention.dart index 43ee0516..ad009d24 100644 --- a/lib/src/widgets/markdown/markdown_mention.dart +++ b/lib/src/widgets/markdown/markdown_mention.dart @@ -177,8 +177,9 @@ class MentionWidgetState extends State { setState(() { _icon = user.avatar; - _onClick = () => - context.router.push(UserRoute(userId: user.id, initData: user)); + _onClick = () => context.router.push( + UserRoute(username: user.name, userId: user.id, initData: user), + ); }); } else if (modifier == '!') { if (!communityMentionCache.containsKey(cacheKey)) { @@ -197,7 +198,11 @@ class MentionWidgetState extends State { setState(() { _icon = community.icon; _onClick = () => context.router.push( - CommunityRoute(communityId: community.id, initData: community), + CommunityRoute( + communityName: community.name, + communityId: community.id, + initData: community, + ), ); }); } diff --git a/lib/src/widgets/menus/community_menu.dart b/lib/src/widgets/menus/community_menu.dart index 4719088e..09905a51 100644 --- a/lib/src/widgets/menus/community_menu.dart +++ b/lib/src/widgets/menus/community_menu.dart @@ -91,6 +91,7 @@ Future showCommunityMenu( title: l(context).openItem(name), onTap: () => context.router.push( CommunityRoute( + communityName: detailedCommunity?.name ?? community!.name, communityId: detailedCommunity?.id ?? community!.id, initData: detailedCommunity, ), @@ -166,6 +167,7 @@ Future showCommunityMenu( title: l(context).modlog, onTap: () => context.router.push( ModLogCommunityRoute( + communityName: detailedCommunity?.name ?? community!.name, communityId: detailedCommunity?.id ?? community!.id, ), ), diff --git a/lib/src/widgets/menus/user_menu.dart b/lib/src/widgets/menus/user_menu.dart index adec7cfe..98ab47d0 100644 --- a/lib/src/widgets/menus/user_menu.dart +++ b/lib/src/widgets/menus/user_menu.dart @@ -89,8 +89,9 @@ Future showUserMenu( if (navigateOption) ContextMenuItem( title: l(context).openItem(user.name), - onTap: () => - context.router.push(UserRoute(userId: user.id, initData: user)), + onTap: () => context.router.push( + UserRoute(username: user.name, userId: user.id, initData: user), + ), ), ContextMenuItem( title: l(context).feeds_addTo, @@ -126,7 +127,9 @@ Future showUserMenu( if (ac.serverSoftware == ServerSoftware.lemmy) ContextMenuItem( title: l(context).modlog, - onTap: () => context.router.push(ModLogUserRoute(userId: user.id)), + onTap: () => context.router.push( + ModLogUserRoute(username: user.name, userId: user.id), + ), ), ], ).openMenu(context); diff --git a/lib/src/widgets/tags/tag_screen.dart b/lib/src/widgets/tags/tag_screen.dart index 4e9a90e1..9a6519dd 100644 --- a/lib/src/widgets/tags/tag_screen.dart +++ b/lib/src/widgets/tags/tag_screen.dart @@ -244,7 +244,11 @@ class TagUsersScreenState extends State { unawaited( context.router.push( - UserRoute(userId: user.id, initData: user), + UserRoute( + username: user.name, + userId: user.id, + initData: user, + ), ), ); },