This commit is contained in:
Fabian Freund
2025-02-03 15:09:04 +01:00
parent 36acd46318
commit 025ecaf2e3
132 changed files with 4431 additions and 1644 deletions
@@ -1,3 +1,5 @@
import 'package:lensai/extensions/nullable.dart';
class ChatEntity {
static final _namePattern = RegExp(r"^(.*?) - (.*?)\.md$");
@@ -14,7 +16,7 @@ class ChatEntity {
return ChatEntity._(
fileName,
name: match?.group(1),
dateTime: (match != null) ? DateTime.tryParse(match.group(2)!) : null,
dateTime: match.mapNotNull((match) => DateTime.tryParse(match.group(2)!)),
);
}
@@ -17,7 +17,6 @@ part 'search.g.dart';
class ChatArchiveSearchRepository extends _$ChatArchiveSearchRepository {
late Completer<void> _populatedCompleter;
late StreamController<List<ChatQueryResult>> _streamController;
late ChatSearchDatabase _searchDatabase;
Future<ChatCompanion?> _readChat(ChatEntity chat) async {
final contentResult = await ref
@@ -64,7 +63,9 @@ class ChatArchiveSearchRepository extends _$ChatArchiveSearchRepository {
}) async {
if (input.isNotEmpty) {
await _populatedCompleter.future;
await _searchDatabase.searchDao
await ref
.read(chatSearchDatabaseProvider)
.searchDao
.queryChats(
searchString: input,
snippetLength: snippetLength,
@@ -81,11 +82,12 @@ class ChatArchiveSearchRepository extends _$ChatArchiveSearchRepository {
Stream<List<ChatQueryResult>> build() async* {
_populatedCompleter = Completer();
_streamController = StreamController();
_searchDatabase = ref.watch(chatSearchDatabaseProvider);
final searchDatabase = ref.watch(chatSearchDatabaseProvider);
// populate with initial chats
await _searchDatabase.searchDao.deleteAllChats();
await _searchDatabase.searchDao.indexChats(await _availableChats());
await searchDatabase.searchDao.deleteAllChats();
await searchDatabase.searchDao.indexChats(await _availableChats());
_populatedCompleter.complete();
final changeStreamSubscription =
@@ -98,11 +100,11 @@ class ChatArchiveSearchRepository extends _$ChatArchiveSearchRepository {
if (chat.name != null) {
final companion = await _readChat(chat);
if (companion != null) {
await _searchDatabase.searchDao.upsertChat(companion);
await searchDatabase.searchDao.upsertChat(companion);
}
}
case ChangeType.REMOVE:
await _searchDatabase.searchDao.deleteChat(chat.fileName);
await searchDatabase.searchDao.deleteChat(chat.fileName);
}
});
@@ -7,7 +7,7 @@ part of 'search.dart';
// **************************************************************************
String _$chatArchiveSearchRepositoryHash() =>
r'd7174cfb877c61ee4e9580f44d7ffd11bf3b4b60';
r'6762958d43d2efc95f5d9848bfcae41436564f2b';
/// See also [ChatArchiveSearchRepository].
@ProviderFor(ChatArchiveSearchRepository)