Skip to content

Commit

Permalink
TW-1635: remove the messages contains reply from search result (#1819)
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn authored Jun 3, 2024
1 parent f779bb1 commit 6a3421e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/pages/chat_search/chat_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ChatSearchController extends State<ChatSearch> {
),
);
serverSearchController.initSearch(
context: context,
onSearchEncryptedMessage: sameTypeEventsBuilderController != null
? _listenSearchEncryptedMessage
: null,
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/search/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ class SearchController extends State<Search> {
SchedulerBinding.instance.addPostFrameCallback((_) async {
if (mounted) {
searchContactAndRecentChatController?.init();
serverSearchController.initSearch();
serverSearchController.initSearch(
context: context,
);
fetchPreSearchRecentContacts();
textEditingController.addListener(() {
onSearchBarChanged(textEditingController.text);
Expand Down
14 changes: 12 additions & 2 deletions lib/pages/search/server_search_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -18,6 +19,8 @@ import 'package:matrix/matrix.dart';
class ServerSearchController with SearchDebouncerMixin {
final String? inRoomId;

BuildContext? currentContext;

ServerSearchController({
this.inRoomId,
});
Expand All @@ -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);
Expand Down Expand Up @@ -92,8 +97,13 @@ class ServerSearchController with SearchDebouncerMixin {
...(searchResultsNotifier.value
as PresentationServerSideSearch)
.searchResults,
...success.results ?? [],
],
...success.results ?? <Result>[],
]
.where(
(result) =>
result.isDisplayableResult(context: currentContext),
)
.toList(),
);
}
}
Expand Down
10 changes: 10 additions & 0 deletions lib/utils/matrix_sdk_extensions/result_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 6a3421e

Please sign in to comment.