feat: store subscription posts with a read mark and split the library controller

This commit is contained in:
randogoth 2026-10-11 13:12:48 +03:00
parent b311b9f7dd
commit 953ae798eb
15 changed files with 1787 additions and 386 deletions

View file

@ -0,0 +1,35 @@
import 'package:signals/signals.dart';
import '../../database/database.dart';
/// Which pages the reader has bookmarked. Only the set of addresses is held
/// here, because that is all the chrome watches; the list itself is read from
/// the database whenever a page needs it.
class BookmarksController {
BookmarksController(this._db);
final MewsDatabase _db;
final bookmarkedUrls = signal(<String>{});
Future<void> load() async {
final rows = await _db.allBookmarks();
bookmarkedUrls.value = rows.map((row) => row.url).toSet();
}
bool isBookmarked(String url) => bookmarkedUrls.value.contains(url);
Future<void> toggle(String url, String? title) async {
if (isBookmarked(url)) {
await remove(url);
return;
}
await _db.addBookmark(url, title);
bookmarkedUrls.value = {...bookmarkedUrls.value, url};
}
Future<void> remove(String url) async {
await _db.removeBookmark(url);
bookmarkedUrls.value = {...bookmarkedUrls.value}..remove(url);
}
}