Merge branch 'soru/escape-routes' into 'main'

fix: Properly encode and decode vRouter paths

See merge request famedly/fluffychat!487
This commit is contained in:
Krille Fear 2021-08-22 10:05:30 +00:00
commit e05a99293a
22 changed files with 47 additions and 38 deletions

View File

@ -139,7 +139,7 @@ class AppRoutes {
nestedRoutes: [ nestedRoutes: [
VWidget( VWidget(
path: '', path: '',
widget: EmptyPage(), widget: Chat(),
buildTransition: _fadeTransition, buildTransition: _fadeTransition,
), ),
VWidget( VWidget(

View File

@ -620,7 +620,7 @@ class ChatController extends State<Chat> {
future: room.leave, future: room.leave,
); );
if (result.error == null) { if (result.error == null) {
VRouter.of(context).to('/rooms/${result.result}'); VRouter.of(context).toSegments(['rooms', result.result]);
} }
} }

View File

@ -60,7 +60,7 @@ class ChatListController extends State<ChatList> {
void editSpace(BuildContext context, String spaceId) async { void editSpace(BuildContext context, String spaceId) async {
Scaffold.of(context).openEndDrawer(); Scaffold.of(context).openEndDrawer();
await Matrix.of(context).client.getRoomById(spaceId).postLoad(); await Matrix.of(context).client.getRoomById(spaceId).postLoad();
VRouter.of(context).to('/spaces/$spaceId'); VRouter.of(context).toSegments(['spaces', spaceId]);
} }
List<Room> get spaces => List<Room> get spaces =>

View File

@ -32,7 +32,7 @@ class NewGroupController extends State<NewGroup> {
), ),
); );
if (roomID.error == null) { if (roomID.error == null) {
VRouter.of(context).to('/rooms/${roomID.result}/invite'); VRouter.of(context).toSegments(['rooms', roomID.result, 'invite']);
} }
} }

View File

@ -47,7 +47,7 @@ class NewPrivateChatController extends State<NewPrivateChat> {
); );
if (roomID.error == null) { if (roomID.error == null) {
VRouter.of(context).to('/rooms/${roomID.result}'); VRouter.of(context).toSegments(['rooms', roomID.result]);
} }
} }

View File

@ -34,7 +34,7 @@ class NewSpaceController extends State<NewSpace> {
), ),
); );
if (roomID.error == null) { if (roomID.error == null) {
VRouter.of(context).to('/rooms/${roomID.result}/details'); VRouter.of(context).toSegments(['rooms', roomID.result, 'details']);
} }
} }

View File

@ -77,7 +77,7 @@ class SearchController extends State<Search> {
), ),
); );
if (success.error == null) { if (success.error == null) {
VRouter.of(context).to('/rooms/${success.result}'); VRouter.of(context).toSegments(['rooms', success.result]);
} }
} }

View File

@ -88,7 +88,8 @@ class UserBottomSheetController extends State<UserBottomSheet> {
future: () => widget.user.startDirectChat(), future: () => widget.user.startDirectChat(),
); );
if (roomIdResult.error != null) return; if (roomIdResult.error != null) return;
VRouter.of(widget.outerContext).to('/rooms/${roomIdResult.result}'); VRouter.of(widget.outerContext)
.toSegments(['rooms', roomIdResult.result]);
Navigator.of(context, rootNavigator: false).pop(); Navigator.of(context, rootNavigator: false).pop();
break; break;
} }

View File

@ -52,11 +52,11 @@ class ChatDetailsView extends StatelessWidget {
SliverAppBar( SliverAppBar(
leading: IconButton( leading: IconButton(
icon: Icon(Icons.close_outlined), icon: Icon(Icons.close_outlined),
onPressed: () => VRouter.of(context) onPressed: () =>
.path VRouter.of(context).path.startsWith('/spaces/')
.startsWith('/spaces/') ? VRouter.of(context).pop()
? VRouter.of(context).pop() : VRouter.of(context)
: VRouter.of(context).to('/rooms/${controller.roomId}'), .toSegments(['rooms', controller.roomId]),
), ),
elevation: Theme.of(context).appBarTheme.elevation, elevation: Theme.of(context).appBarTheme.elevation,
expandedHeight: 300.0, expandedHeight: 300.0,
@ -264,7 +264,8 @@ class ChatDetailsView extends StatelessWidget {
.visibilityOfTheChatHistory), .visibilityOfTheChatHistory),
subtitle: Text( subtitle: Text(
room.historyVisibility.getLocalizedString( room.historyVisibility.getLocalizedString(
MatrixLocals(L10n.of(context))), MatrixLocals(L10n.of(context))) ??
'',
), ),
), ),
), ),

View File

@ -23,7 +23,7 @@ class ChatEncryptionSettingsView extends StatelessWidget {
leading: IconButton( leading: IconButton(
icon: Icon(Icons.close_outlined), icon: Icon(Icons.close_outlined),
onPressed: () => onPressed: () =>
VRouter.of(context).to('/rooms/${controller.roomId}'), VRouter.of(context).toSegments(['rooms', controller.roomId]),
), ),
title: Text(L10n.of(context).tapOnDeviceToVerify), title: Text(L10n.of(context).tapOnDeviceToVerify),
bottom: PreferredSize( bottom: PreferredSize(

View File

@ -22,8 +22,8 @@ class ChatPermissionsSettingsView extends StatelessWidget {
? null ? null
: IconButton( : IconButton(
icon: Icon(Icons.close_outlined), icon: Icon(Icons.close_outlined),
onPressed: () => onPressed: () => VRouter.of(context)
VRouter.of(context).to('/rooms/${controller.roomId}'), .toSegments(['rooms', controller.roomId]),
), ),
title: Text(L10n.of(context).editChatPermissions), title: Text(L10n.of(context).editChatPermissions),
), ),

View File

@ -98,8 +98,8 @@ class ChatView extends StatelessWidget {
'${controller.room.getUserByMXIDSync(controller.room.directChatMatrixID).mention} ', '${controller.room.getUserByMXIDSync(controller.room.directChatMatrixID).mention} ',
), ),
) )
: () => VRouter.of(context) : () => VRouter.of(context).toSegments(
.to('/rooms/${controller.room.id}/details'), ['rooms', controller.room.id, 'details']),
title: Text( title: Text(
controller.room.getLocalizedDisplayname( controller.room.getLocalizedDisplayname(
MatrixLocals(L10n.of(context))), MatrixLocals(L10n.of(context))),

View File

@ -25,8 +25,8 @@ class InvitationSelectionView extends StatelessWidget {
? null ? null
: IconButton( : IconButton(
icon: Icon(Icons.close_outlined), icon: Icon(Icons.close_outlined),
onPressed: () => onPressed: () => VRouter.of(context)
VRouter.of(context).to('/rooms/${controller.roomId}'), .toSegments(['rooms', controller.roomId]),
), ),
titleSpacing: 0, titleSpacing: 0,
title: DefaultAppBarSearchField( title: DefaultAppBarSearchField(

View File

@ -238,7 +238,8 @@ class SearchView extends StatelessWidget {
.startDirectChat(foundProfile.userId), .startDirectChat(foundProfile.userId),
); );
if (roomID.error == null) { if (roomID.error == null) {
VRouter.of(context).to('/rooms/${roomID.result}'); VRouter.of(context)
.toSegments(['rooms', roomID.result]);
} }
}, },
leading: Avatar( leading: Avatar(

View File

@ -44,8 +44,8 @@ class MultipleEmotesSettingsView extends StatelessWidget {
return ListTile( return ListTile(
title: Text(packName), title: Text(packName),
onTap: () async { onTap: () async {
VRouter.of(context) VRouter.of(context).toSegments(
.to('/rooms/${room.id}/details/emotes/${keys[i]}'); ['rooms', room.id, 'details', 'emotes', keys[i]]);
}, },
); );
}); });

View File

@ -283,7 +283,7 @@ class BackgroundPush {
if (router == null) { if (router == null) {
return; return;
} }
router.currentState.to('/rooms/$roomId'); router.currentState.toSegments(['rooms', roomId]);
} catch (e, s) { } catch (e, s) {
Logs().e('[Push] Failed to open room', e, s); Logs().e('[Push] Failed to open room', e, s);
} }

View File

@ -110,10 +110,10 @@ class UrlLauncher {
if (room != null) { if (room != null) {
// we have the room, so....just open it // we have the room, so....just open it
if (event != null) { if (event != null) {
VRouter.of(context) VRouter.of(context).toSegments(['rooms', room.id],
.to('/rooms/${room.id}', queryParameters: {'event': event}); queryParameters: {'event': event});
} else { } else {
VRouter.of(context).to('/rooms/${room.id}'); VRouter.of(context).toSegments(['rooms', room.id]);
} }
return; return;
} }
@ -138,9 +138,10 @@ class UrlLauncher {
context: context, context: context,
future: () => Future.delayed(const Duration(seconds: 2))); future: () => Future.delayed(const Duration(seconds: 2)));
if (event != null) { if (event != null) {
VRouter.of(context).to('/rooms/${response.result}/$event'); VRouter.of(context).toSegments(['rooms', response.result],
queryParameters: {'event': event});
} else { } else {
VRouter.of(context).to('/rooms/${response.result}'); VRouter.of(context).toSegments(['rooms', response.result]);
} }
} }
} else { } else {
@ -155,7 +156,7 @@ class UrlLauncher {
); );
var roomId = matrix.client.getDirectChatFromUserId(user.id); var roomId = matrix.client.getDirectChatFromUserId(user.id);
if (roomId != null) { if (roomId != null) {
VRouter.of(context).to('/rooms/$roomId'); VRouter.of(context).toSegments(['rooms', roomId]);
return; return;
} }
@ -173,7 +174,7 @@ class UrlLauncher {
.result; .result;
if (roomId != null) { if (roomId != null) {
VRouter.of(context).to('/rooms/$roomId'); VRouter.of(context).toSegments(['rooms', roomId]);
} }
} }
} }

View File

@ -95,7 +95,8 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
widget.room.setPushRuleState(PushRuleState.notify)); widget.room.setPushRuleState(PushRuleState.notify));
break; break;
case 'details': case 'details':
VRouter.of(context).to('/rooms/${widget.room.id}/details'); VRouter.of(context)
.toSegments(['rooms', widget.room.id, 'details']);
break; break;
} }
}, },

View File

@ -102,8 +102,12 @@ class _ContactListTile extends StatelessWidget {
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
) )
: null), : null),
onTap: () => VRouter.of(context).to( onTap: () => VRouter.of(context).toSegments([
'/rooms/${Matrix.of(context).client.getDirectChatFromUserId(contact.senderId)}'), 'rooms',
Matrix.of(context)
.client
.getDirectChatFromUserId(contact.senderId)
]),
); );
}); });
} }

View File

@ -21,7 +21,7 @@ class _EncryptionButtonState extends State<EncryptionButton> {
void _enableEncryptionAction() async { void _enableEncryptionAction() async {
if (widget.room.encrypted) { if (widget.room.encrypted) {
VRouter.of(context).to('/rooms/${widget.room.id}/encryption'); VRouter.of(context).toSegments(['rooms', widget.room.id, 'encryption']);
return; return;
} }
if (widget.room.joinRules == JoinRules.public) { if (widget.room.joinRules == JoinRules.public) {

View File

@ -112,7 +112,7 @@ class ChatListItem extends StatelessWidget {
} }
Matrix.of(context).shareContent = null; Matrix.of(context).shareContent = null;
} }
VRouter.of(context).to('/rooms/${room.id}'); VRouter.of(context).toSegments(['rooms', room.id]);
} }
} }
} }

View File

@ -18,7 +18,7 @@ class PublicRoomListItem extends StatelessWidget {
future: () => _joinRoomAndWait(context), future: () => _joinRoomAndWait(context),
); );
if (success.error == null) { if (success.error == null) {
VRouter.of(context).toNamed('/rooms/${success.result}'); VRouter.of(context).toSegments(['rooms', success.result]);
} }
} }