♻️ Refactor room message sorting

This commit is contained in:
2025-09-23 14:21:37 +08:00
parent b2ac5fbef2
commit 8baf77bcf7
5 changed files with 33 additions and 25 deletions

View File

@@ -141,15 +141,27 @@ class AppDatabase extends _$AppDatabase {
Future<List<LocalChatMessage>> searchMessages(
String roomId,
String query,
) async {
String query, {
bool? withAttachments,
}) async {
var selectStatement = select(chatMessages)
..where((m) => m.roomId.equals(roomId));
if (query.isNotEmpty) {
final searchTerm = '%${query}%';
selectStatement =
selectStatement
..where((m) => m.content.like('%${query.toLowerCase()}%'));
selectStatement..where(
(m) =>
m.content.like(searchTerm) |
m.meta.like(searchTerm) |
m.attachments.like(searchTerm) |
m.type.like(searchTerm),
);
}
if (withAttachments == true) {
selectStatement =
selectStatement..where((m) => m.attachments.equals('[]').not());
}
final messages =