diff --git a/lib/pages/chat_search/chat_search.dart b/lib/pages/chat_search/chat_search.dart index 9c642ff181..f9331b155e 100644 --- a/lib/pages/chat_search/chat_search.dart +++ b/lib/pages/chat_search/chat_search.dart @@ -59,6 +59,7 @@ class ChatSearchController extends State { ), ); serverSearchController.initSearch( + context: context, onSearchEncryptedMessage: sameTypeEventsBuilderController != null ? _listenSearchEncryptedMessage : null, diff --git a/lib/pages/search/search.dart b/lib/pages/search/search.dart index 963a16be99..411786c003 100644 --- a/lib/pages/search/search.dart +++ b/lib/pages/search/search.dart @@ -167,7 +167,9 @@ class SearchController extends State { SchedulerBinding.instance.addPostFrameCallback((_) async { if (mounted) { searchContactAndRecentChatController?.init(); - serverSearchController.initSearch(); + serverSearchController.initSearch( + context: context, + ); fetchPreSearchRecentContacts(); textEditingController.addListener(() { onSearchBarChanged(textEditingController.text); diff --git a/lib/pages/search/server_search_controller.dart b/lib/pages/search/server_search_controller.dart index 6543178f92..938426a5f3 100644 --- a/lib/pages/search/server_search_controller.dart +++ b/lib/pages/search/server_search_controller.dart @@ -10,6 +10,7 @@ import 'package:fluffychat/domain/usecase/search/server_search_interactor.dart'; import 'package:fluffychat/presentation/model/search/presentation_server_side_state.dart'; import 'package:fluffychat/presentation/model/search/presentation_server_side_empty_search.dart'; import 'package:fluffychat/presentation/model/search/presentation_server_side_search.dart'; +import 'package:fluffychat/utils/matrix_sdk_extensions/result_extension.dart'; import 'package:fluffychat/utils/string_extension.dart'; import 'package:flutter/material.dart'; import 'package:fluffychat/domain/app_state/search/server_search_state.dart'; @@ -18,6 +19,8 @@ import 'package:matrix/matrix.dart'; class ServerSearchController with SearchDebouncerMixin { final String? inRoomId; + BuildContext? currentContext; + ServerSearchController({ this.inRoomId, }); @@ -42,8 +45,10 @@ class ServerSearchController with SearchDebouncerMixin { _searchCategories?.searchTerm.isNotEmpty == true; void initSearch({ + BuildContext? context, Function(String)? onSearchEncryptedMessage, }) { + currentContext = context; initializeDebouncer((searchTerm) { if (onSearchEncryptedMessage != null) { onSearchEncryptedMessage(searchTerm); @@ -92,8 +97,13 @@ class ServerSearchController with SearchDebouncerMixin { ...(searchResultsNotifier.value as PresentationServerSideSearch) .searchResults, - ...success.results ?? [], - ], + ...success.results ?? [], + ] + .where( + (result) => + result.isDisplayableResult(context: currentContext), + ) + .toList(), ); } } diff --git a/lib/utils/matrix_sdk_extensions/result_extension.dart b/lib/utils/matrix_sdk_extensions/result_extension.dart index 7f06b3a7d7..b9e3040752 100644 --- a/lib/utils/matrix_sdk_extensions/result_extension.dart +++ b/lib/utils/matrix_sdk_extensions/result_extension.dart @@ -13,4 +13,14 @@ extension ResultExtension on Result { } return Event.fromMatrixEvent(result!, room); } + + bool isDisplayableResult({BuildContext? context}) { + if (context == null) { + return false; + } + final event = getEvent(context); + return event != null && + (event.relationshipType == null || + event.relationshipType != RelationshipTypes.reply); + } }