Skip to content

Commit

Permalink
TW-2111: Fix replies do not appear in search results.
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Dec 11, 2024
1 parent 3881846 commit 519c3d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
12 changes: 8 additions & 4 deletions lib/pages/search/server_search_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ class ServerSearchController with SearchDebouncerMixin {
...success.results ?? <Result>[],
]
.where(
(result) =>
result.isDisplayableResult(context: currentContext),
(result) => result.isDisplayableResult(
context: currentContext,
searchWord: _searchCategories!.searchTerm,
),
)
.toList(),
);
Expand All @@ -118,8 +120,10 @@ class ServerSearchController with SearchDebouncerMixin {
...success.results ?? <Result>[],
]
.where(
(result) =>
result.isDisplayableResult(context: currentContext),
(result) => result.isDisplayableResult(
context: currentContext,
searchWord: _searchCategories!.searchTerm,
),
)
.toList(),
);
Expand Down
22 changes: 18 additions & 4 deletions lib/utils/matrix_sdk_extensions/result_extension.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:matrix/matrix.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';

extension ResultExtension on Result {
Event? getEvent(BuildContext context) {
Expand All @@ -14,13 +16,25 @@ extension ResultExtension on Result {
return Event.fromMatrixEvent(result!, room);
}

bool isDisplayableResult({BuildContext? context}) {
bool isDisplayableResult({
BuildContext? context,
required String searchWord,
}) {
if (context == null) {
return false;
}
final event = getEvent(context);
return event != null &&
(event.relationshipType == null ||
event.relationshipType != RelationshipTypes.reply);
if (event == null) {
return false;
}
final bodyContent = event.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)!),
hideEdit: true,
hideReply: true,
plaintextBody: true,
removeMarkdown: true,
);

return bodyContent.toLowerCase().contains(searchWord.toLowerCase());
}
}

0 comments on commit 519c3d2

Please sign in to comment.