feat: check every subscription in the background and add the posts page

This commit is contained in:
randogoth 2026-10-11 13:20:00 +03:00
parent 953ae798eb
commit 1b426ccd8b
15 changed files with 688 additions and 58 deletions

View file

@ -1,6 +1,7 @@
import '../../database/database.dart';
import '../../l10n/strings.dart';
import '../../mews/document.dart';
import '../controllers/subscriptions_controller.dart';
import 'mews_urls.dart';
import 'page_blocks.dart';
@ -10,11 +11,13 @@ import 'page_blocks.dart';
Future<MewsPage> buildHubPage(
Uri url, {
required MewsDatabase db,
required SubscriptionsController subscriptions,
required Strings strings,
}) async {
final bookmarks = await db.countBookmarks();
final sites = await db.countSubscriptions();
final visits = await db.countHistory();
final unread = await db.unreadCount();
return internalPage(
url: url,
@ -22,6 +25,14 @@ Future<MewsPage> buildHubPage(
body: [
HeadingBlock(1, [MewsText(strings.t('hub-title'))]),
itemList([
itemRow(
href: MewsUrls.posts,
label: strings.t('nav-posts'),
note: countText(strings, unread,
none: 'count-unread-none',
one: 'count-unread-one',
many: 'count-unread-many'),
),
itemRow(
href: MewsUrls.bookmarks,
label: strings.t('nav-bookmarks'),
@ -48,6 +59,14 @@ Future<MewsPage> buildHubPage(
),
itemRow(href: MewsUrls.settings, label: strings.t('nav-settings')),
]),
ParagraphBlock([
if (subscriptions.refreshing.value)
MewsEmphasis(EmphasisStyle.emphasis,
[MewsText(strings.t('posts-checking'))])
else
MewsLink(MewsUrls.action('refresh-subscriptions'),
[MewsText(strings.t('action-refresh'))]),
]),
],
);
}

View file

@ -13,6 +13,7 @@ abstract final class MewsUrls {
static const scheme = 'mews';
static const hub = 'mews:hub';
static const posts = 'mews:posts';
static const bookmarks = 'mews:bookmarks';
static const subscriptions = 'mews:subscriptions';
static const history = 'mews:history';

View file

@ -11,9 +11,14 @@ import 'mews_urls.dart';
/// constant here rather than a message.
const actionSeparator = ' ';
/// One choice in a group of mutually exclusive values.
/// A link with its label: a choice in a group, or an action on a row. For an
/// action [current] is always false.
typedef Choice = ({String href, String label, bool current});
/// An action link on a row.
Choice action(String href, String label) =>
(href: href, label: label, current: false);
/// One entry in the strip of internal pages.
typedef NavItem = ({String url, String labelId});
@ -21,6 +26,7 @@ typedef NavItem = ({String url, String labelId});
/// never shifts under the reader.
const navItems = <NavItem>[
(url: MewsUrls.hub, labelId: 'nav-hub'),
(url: MewsUrls.posts, labelId: 'nav-posts'),
(url: MewsUrls.bookmarks, labelId: 'nav-bookmarks'),
(url: MewsUrls.subscriptions, labelId: 'nav-subscriptions'),
(url: MewsUrls.history, labelId: 'nav-history'),
@ -61,18 +67,59 @@ MewsListItem itemRow({
required String label,
String? date,
String? note,
bool strong = false,
List<Choice> actions = const [],
}) {
final text = date == null ? label : '$date $label';
return MewsListItem([
ParagraphBlock([
MewsLink(href, [MewsText(date == null ? label : '$date $label')]),
MewsLink(href, [
if (strong)
MewsEmphasis(EmphasisStyle.strong, [MewsText(text)])
else
MewsText(text),
]),
if (note != null) ...[
const MewsLineBreak(),
MewsEmphasis(EmphasisStyle.emphasis, [MewsText(note)]),
],
if (actions.isNotEmpty) ...[
const MewsLineBreak(),
..._separated(
[for (final action in actions) MewsLink(action.href, [MewsText(action.label)])]),
],
]),
]);
}
/// Joins runs with the separator between them, never around them.
List<MewsInline> _separated(List<MewsInline> runs) {
final out = <MewsInline>[];
for (final run in runs) {
if (out.isNotEmpty) out.add(const MewsText(actionSeparator));
out.add(run);
}
return out;
}
/// A group of mutually exclusive values on one line, for a short group that
/// would waste a list. The chosen value is plain text, the rest are links.
List<MewsBlock> choiceLine({required String label, required List<Choice> options}) {
return [
ParagraphBlock([
MewsEmphasis(EmphasisStyle.emphasis, [MewsText(label)]),
const MewsText(actionSeparator),
..._separated([
for (final option in options)
if (option.current)
MewsEmphasis(EmphasisStyle.strong, [MewsText(option.label)])
else
MewsLink(option.href, [MewsText(option.label)]),
]),
]),
];
}
/// A group of mutually exclusive values: the current one plain, the rest links.
ListBlock choiceRow(List<Choice> options) {
return ListBlock(

View file

@ -0,0 +1,104 @@
import '../../database/database.dart';
import '../../l10n/strings.dart';
import '../../mews/document.dart';
import 'mews_urls.dart';
import 'page_blocks.dart';
/// Every post from every subscribed site in one list (spec 6.1), newest first
/// unless the reader orders it otherwise. Unread posts stand out, and opening
/// one marks it read.
Future<MewsPage> buildPostsPage(
Uri url, {
required MewsDatabase db,
required Strings strings,
required bool refreshing,
}) async {
final sort = EntrySort.parse(url.queryParameters['sort']);
final unreadOnly = url.queryParameters['show'] == 'unread';
final entries =
await db.riverEntries(sort: sort, unreadOnly: unreadOnly);
final unread = await db.unreadCount();
final title = strings.t('posts-title');
return internalPage(
url: url,
title: title,
body: [
...chrome(title: title, current: url, strings: strings),
ParagraphBlock([
MewsEmphasis(EmphasisStyle.emphasis, [
MewsText(countText(strings, unread,
none: 'count-unread-none',
one: 'count-unread-one',
many: 'count-unread-many')),
]),
const MewsText(actionSeparator),
if (refreshing)
MewsEmphasis(EmphasisStyle.emphasis,
[MewsText(strings.t('posts-checking'))])
else
MewsLink(MewsUrls.action('refresh-subscriptions'),
[MewsText(strings.t('action-refresh'))]),
]),
...choiceLine(
label: strings.t('posts-sort-label'),
options: [
for (final option in const [
(EntrySort.date, 'posts-sort-date'),
(EntrySort.source, 'posts-sort-source'),
(EntrySort.unread, 'posts-sort-unread'),
])
(
href: MewsUrls.page(url, {'sort': option.$1.name}),
label: strings.t(option.$2),
current: option.$1 == sort,
),
],
),
...choiceLine(
label: strings.t('posts-show-label'),
options: [
(
href: MewsUrls.page(url, {'show': null}),
label: strings.t('posts-show-all'),
current: !unreadOnly,
),
(
href: MewsUrls.page(url, {'show': 'unread'}),
label: strings.t('posts-show-unread'),
current: unreadOnly,
),
],
),
const RuleBlock(),
if (entries.isEmpty)
ParagraphBlock([
MewsText(strings
.t(unreadOnly ? 'posts-none-unread' : 'posts-empty')),
])
else
itemList([
for (final entry in entries)
itemRow(
href: entry.url,
label: entry.title,
date: dayText(entry.date),
note: entry.siteName,
strong: entry.unread,
actions: [
if (entry.unread)
action(
MewsUrls.action('mark-read',
{'site': entry.siteUrl, 'url': entry.url}),
strings.t('posts-mark-read'))
else
action(
MewsUrls.action('mark-unread',
{'site': entry.siteUrl, 'url': entry.url}),
strings.t('posts-mark-unread')),
],
),
]),
],
);
}