diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index e43afda5ee..52254918ca 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -805,6 +805,21 @@ class ChatController extends State { inputFocus.requestFocus(); } + /* + * this function scrolls to event given by queryParameters, only if + * last route was search + */ + void scrollToEventAfterSearch(BuildContext context, String? from, String to) { + if (mounted && timeline != null) { + if (from != null && from.endsWith('/search')) { + final event = VRouter.of(context).queryParameters['event']; + if (event != null) { + scrollToEventId(event); + } + } + } + } + void scrollToEventId(String eventId) async { var eventIndex = timeline!.events.indexWhere((e) => e.eventId == eventId); if (eventIndex == -1) { diff --git a/lib/pages/chat/chat_view.dart b/lib/pages/chat/chat_view.dart index f86fd0f45e..96a69ca31c 100644 --- a/lib/pages/chat/chat_view.dart +++ b/lib/pages/chat/chat_view.dart @@ -179,6 +179,9 @@ class ChatView extends StatelessWidget { redirector.stopRedirection(); } }, + afterUpdate: (BuildContext context, String? from, String to) async { + controller.scrollToEventAfterSearch(context, from, to); + }, child: GestureDetector( onTapDown: controller.setReadMarker, behavior: HitTestBehavior.opaque, diff --git a/lib/pages/chat_search/chat_search.dart b/lib/pages/chat_search/chat_search.dart index c403e101dc..0c2d8c91a3 100644 --- a/lib/pages/chat_search/chat_search.dart +++ b/lib/pages/chat_search/chat_search.dart @@ -233,12 +233,10 @@ class ChatSearchController extends State { } void scrollToEventId(String eventId) { - VRouter.of(context).path.startsWith('/spaces/') - ? VRouter.of(context).pop() - : VRouter.of(context).toSegments( - ['rooms', roomId!], - queryParameters: {'event': eventId}, - ); + VRouter.of(context).toSegments( + ['rooms', roomId!], + queryParameters: {'event': eventId}, + ); } void scrollToTop() {