feat: read subscriptions from an Atom feed when a page lists no dated links
This commit is contained in:
parent
b0b86ef5b1
commit
fa51d5793d
9 changed files with 411 additions and 4 deletions
|
|
@ -43,9 +43,14 @@ class SubscriptionsController {
|
|||
}
|
||||
await _db.addSubscription(page.url, page.title, page.atomFeedHref);
|
||||
subscribedUrls.value = {...subscribedUrls.value, page.url};
|
||||
// The posts already on the page are the site's back catalogue, not news,
|
||||
// so they are stored read and only later posts are flagged.
|
||||
// Whatever the site has already published is its back catalogue, not
|
||||
// news, so it is stored read and only later posts are flagged. A site
|
||||
// that publishes only through a feed is seeded the same way.
|
||||
await _db.addEntries(page.url, page.entries, read: true);
|
||||
final feed = page.atomFeedHref;
|
||||
if (page.entries.isEmpty && feed != null) {
|
||||
await _checkFeed(page.url, feed, read: true);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> remove(String siteUrl) async {
|
||||
|
|
@ -127,6 +132,13 @@ class SubscriptionsController {
|
|||
await _db.describeSubscription(siteUrl,
|
||||
title: page.title, atomHref: page.atomFeedHref);
|
||||
await _db.addEntries(siteUrl, page.entries);
|
||||
// Dated links are the normative way a site publishes (spec 6.1), so
|
||||
// the feed is only read when the page itself listed nothing. A site
|
||||
// where both agree is then fetched once, not twice.
|
||||
final feed = page.atomFeedHref;
|
||||
if (page.entries.isEmpty && feed != null) {
|
||||
await _checkFeed(siteUrl, feed);
|
||||
}
|
||||
if (!notModified) {
|
||||
// Keep the cache current so the site also reads offline, but do not
|
||||
// record a visit: the reader did not open it.
|
||||
|
|
@ -144,4 +156,14 @@ class SubscriptionsController {
|
|||
}
|
||||
await _db.touchSubscription(siteUrl, DateTime.now());
|
||||
}
|
||||
|
||||
/// Reads a site's Atom feed (spec 6.2). Entries are keyed by address, so a
|
||||
/// post listed by both the page and the feed is stored once.
|
||||
Future<void> _checkFeed(String siteUrl, String feedUrl,
|
||||
{bool read = false}) async {
|
||||
final result = await _fetch.send(FetchFeed(url: feedUrl));
|
||||
if (result case FetchFeedOk(:final entries)) {
|
||||
await _db.addEntries(siteUrl, entries, read: read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue