Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server search - Bug fixes 11 Dec #2180

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/domain/model/search/server_side_search_categories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class ServerSideSearchCategories with EquatableMixin {
return Categories(
roomEvents: RoomEventsCriteria(
searchTerm: searchTerm,
groupings: Groupings(
groupBy: [Group(key: GroupKey.roomId)],
),
nqhhdev marked this conversation as resolved.
Show resolved Hide resolved
keys: [KeyKind.contentBody],
hoangdat marked this conversation as resolved.
Show resolved Hide resolved
orderBy: SearchOrder.recent,
filter: searchFilter,
),
Expand Down
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());
}
}
Loading