prepare for multiple apps
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_author.dart';
|
||||
|
||||
class FeedAuthorsConverter extends TypeConverter<List<FeedAuthor>, String> {
|
||||
const FeedAuthorsConverter();
|
||||
|
||||
@override
|
||||
List<FeedAuthor> fromSql(String fromDb) {
|
||||
final authors = jsonDecode(fromDb) as List<dynamic>;
|
||||
return authors
|
||||
.map((author) => FeedAuthor.fromJson(author as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
String toSql(List<FeedAuthor> value) {
|
||||
return jsonEncode(value.map((author) => author.toJson()).toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_category.dart';
|
||||
|
||||
class FeedCategoriesConverter
|
||||
extends TypeConverter<List<FeedCategory>, String> {
|
||||
const FeedCategoriesConverter();
|
||||
|
||||
@override
|
||||
List<FeedCategory> fromSql(String fromDb) {
|
||||
final categories = jsonDecode(fromDb) as List<dynamic>;
|
||||
return categories
|
||||
.map(
|
||||
(category) => FeedCategory.fromJson(category as Map<String, dynamic>),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
String toSql(List<FeedCategory> value) {
|
||||
return jsonEncode(value.map((category) => category.toJson()).toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
|
||||
|
||||
class FeedDataConverter extends JsonConverter<FeedData, Map<String, dynamic>> {
|
||||
const FeedDataConverter();
|
||||
|
||||
@override
|
||||
FeedData fromJson(Map<String, dynamic> json) {
|
||||
return FeedData.fromJson(json);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson(FeedData object) {
|
||||
return object.toJson();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_link.dart';
|
||||
|
||||
class FeedLinksConverter extends TypeConverter<List<FeedLink>, String> {
|
||||
const FeedLinksConverter();
|
||||
|
||||
@override
|
||||
List<FeedLink> fromSql(String fromDb) {
|
||||
final links = jsonDecode(fromDb) as List<dynamic>;
|
||||
return links
|
||||
.map((link) => FeedLink.fromJson(link as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
String toSql(List<FeedLink> value) {
|
||||
return jsonEncode(value.map((link) => link.toJson()).toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/daos/article.drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/database.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article_query_result.dart';
|
||||
|
||||
@DriftAccessor()
|
||||
class ArticleDao extends DatabaseAccessor<FeedDatabase> with $ArticleDaoMixin {
|
||||
ArticleDao(super.attachedDatabase);
|
||||
|
||||
Selectable<FeedArticle> getFeedArticles(Uri? url) {
|
||||
final select = db.articleView.select();
|
||||
|
||||
if (url != null) {
|
||||
select.where((article) => article.feedId.equalsValue(url));
|
||||
}
|
||||
|
||||
return select..orderBy([
|
||||
(row) => OrderingTerm(
|
||||
expression: coalesce([row.updated, row.created]),
|
||||
mode: OrderingMode.desc,
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
Selectable<FeedArticle> getUnprocessedArticles() {
|
||||
return db.articleView.select()..where(
|
||||
(article) =>
|
||||
(article.contentHtml.isNotNull() &
|
||||
(article.contentMarkdown.isNull() |
|
||||
article.contentPlain.isNull())) |
|
||||
(article.summaryHtml.isNotNull() &
|
||||
(article.summaryMarkdown.isNull() |
|
||||
article.summaryPlain.isNull())),
|
||||
);
|
||||
}
|
||||
|
||||
SingleOrNullSelectable<FeedArticle> getArticleById(String articleId) {
|
||||
return db.articleView.select()..where((row) => row.id.equals(articleId));
|
||||
}
|
||||
|
||||
Future<void> updateArticleContent(List<FeedArticle> articles) {
|
||||
return db.transaction(() async {
|
||||
await Future.wait(
|
||||
articles.map((newArticle) {
|
||||
final statement = db.article.update()
|
||||
..where((article) => article.id.equals(newArticle.id));
|
||||
|
||||
return statement.write(
|
||||
ArticleCompanion(
|
||||
summaryHtml: Value(newArticle.summaryHtml),
|
||||
summaryMarkdown: Value(newArticle.summaryMarkdown),
|
||||
summaryPlain: Value(newArticle.summaryPlain),
|
||||
contentHtml: Value(newArticle.contentHtml),
|
||||
contentMarkdown: Value(newArticle.contentMarkdown),
|
||||
contentPlain: Value(newArticle.contentPlain),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> upsertArticles(List<FeedArticle> articles) {
|
||||
return db.transaction(() async {
|
||||
await Future.wait(
|
||||
articles
|
||||
.map(
|
||||
(article) => db.article.insertOne(
|
||||
article,
|
||||
onConflict: DoUpdate(
|
||||
(old) {
|
||||
return ArticleCompanion(
|
||||
authors: Value(article.authors),
|
||||
contentHtml: Value(article.contentHtml),
|
||||
contentMarkdown: Value(article.contentMarkdown),
|
||||
contentPlain: Value(article.contentPlain),
|
||||
links: Value(article.links),
|
||||
summaryHtml: Value(article.summaryHtml),
|
||||
summaryMarkdown: Value(article.summaryMarkdown),
|
||||
summaryPlain: Value(article.summaryPlain),
|
||||
tags: Value(article.tags),
|
||||
title: Value(article.title),
|
||||
updated: Value(article.updated),
|
||||
);
|
||||
},
|
||||
where: (old) =>
|
||||
old.updated.isNotNull() &
|
||||
old.updated.isSmallerThanValue(
|
||||
article.updated ?? DateTime(0),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<int> updateArticleRead(String articleId, DateTime? read) {
|
||||
final statement = db.article.update()
|
||||
..where((article) => article.id.equals(articleId));
|
||||
|
||||
return statement.write(ArticleCompanion(lastRead: Value(read)));
|
||||
}
|
||||
|
||||
Selectable<(String, int)> getUnreadArticleCount() {
|
||||
final count = countAll();
|
||||
|
||||
final countByFeed = db.article.selectOnly()
|
||||
..addColumns([db.article.feedId, count])
|
||||
..where(
|
||||
db.article.lastRead.isNull() |
|
||||
(db.article.updated.isNotNull() &
|
||||
db.article.lastRead.isSmallerThan(db.article.lastRead)),
|
||||
)
|
||||
..groupBy([db.article.feedId]);
|
||||
|
||||
return countByFeed.map(
|
||||
(result) => (result.read(db.article.feedId)!, result.read(count)!),
|
||||
);
|
||||
}
|
||||
|
||||
Selectable<FeedArticleQueryResult> queryArticles({
|
||||
required String matchPrefix,
|
||||
required String matchSuffix,
|
||||
required String ellipsis,
|
||||
required int snippetLength,
|
||||
required String searchString,
|
||||
required Uri? feedId,
|
||||
int limit = 25,
|
||||
}) {
|
||||
final ftsQuery = db.buildFtsQuery(searchString);
|
||||
|
||||
if (ftsQuery.isNotEmpty) {
|
||||
return db.definitionsDrift.queryArticlesFullContent(
|
||||
feedId: feedId?.toString(),
|
||||
query: ftsQuery,
|
||||
snippetLength: snippetLength,
|
||||
beforeMatch: matchPrefix,
|
||||
afterMatch: matchSuffix,
|
||||
ellipsis: ellipsis,
|
||||
limit: limit,
|
||||
);
|
||||
} else {
|
||||
return db.definitionsDrift.queryArticlesBasic(
|
||||
feedId: feedId?.toString(),
|
||||
query: db.buildLikeQuery(searchString),
|
||||
limit: limit,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// dart format width=80
|
||||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:weblibre/features/web_feed/data/database/database.dart' as i1;
|
||||
|
||||
mixin $ArticleDaoMixin on i0.DatabaseAccessor<i1.FeedDatabase> {
|
||||
ArticleDaoManager get managers => ArticleDaoManager(this);
|
||||
}
|
||||
|
||||
class ArticleDaoManager {
|
||||
final $ArticleDaoMixin _db;
|
||||
ArticleDaoManager(this._db);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/daos/feed.drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/database.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
|
||||
|
||||
@DriftAccessor()
|
||||
class FeedDao extends DatabaseAccessor<FeedDatabase> with $FeedDaoMixin {
|
||||
FeedDao(super.attachedDatabase);
|
||||
|
||||
Selectable<FeedData> getFeeds() {
|
||||
return db.feed.select();
|
||||
}
|
||||
|
||||
SingleOrNullSelectable<FeedData> getFeed(Uri feedId) {
|
||||
return db.feed.select()..where((feed) => feed.url.equalsValue(feedId));
|
||||
}
|
||||
|
||||
Future<int> updateFeedFetched(Uri feedId, DateTime fetched) {
|
||||
final statement = db.feed.update()
|
||||
..where((feed) => feed.url.equalsValue(feedId));
|
||||
|
||||
return statement.write(FeedCompanion(lastFetched: Value(fetched)));
|
||||
}
|
||||
|
||||
Future<int> deleteFeed(Uri feedId) {
|
||||
return db.feed.deleteWhere((feed) => feed.url.equals(feedId.toString()));
|
||||
}
|
||||
|
||||
Future<int> upsertFeed(FeedData feedData) {
|
||||
return db.feed.insertOne(
|
||||
feedData,
|
||||
onConflict: DoUpdate((old) {
|
||||
return FeedCompanion(
|
||||
authors: Value(feedData.authors),
|
||||
title: Value(feedData.title),
|
||||
description: Value(feedData.description),
|
||||
tags: Value(feedData.tags),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// dart format width=80
|
||||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:weblibre/features/web_feed/data/database/database.dart' as i1;
|
||||
|
||||
mixin $FeedDaoMixin on i0.DatabaseAccessor<i1.FeedDatabase> {
|
||||
FeedDaoManager get managers => FeedDaoManager(this);
|
||||
}
|
||||
|
||||
class FeedDaoManager {
|
||||
final $FeedDaoMixin _db;
|
||||
FeedDaoManager(this._db);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift_dev/api/migrations_native.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:weblibre/features/search/domain/fts_tokenizer.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/daos/article.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/daos/feed.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/database.drift.dart';
|
||||
|
||||
@DriftDatabase(include: {'definitions.drift'}, daos: [ArticleDao, FeedDao])
|
||||
class FeedDatabase extends $FeedDatabase with TrigramQueryBuilderMixin {
|
||||
@override
|
||||
final int schemaVersion = 1;
|
||||
|
||||
@override
|
||||
final int ftsTokenLimit = 10;
|
||||
@override
|
||||
final int ftsMinTokenLength = 3;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
beforeOpen: (details) async {
|
||||
if (kDebugMode) {
|
||||
// This check pulls in a fair amount of code that's not needed
|
||||
// anywhere else, so we recommend only doing it in debug builds.
|
||||
await validateDatabaseSchema();
|
||||
}
|
||||
|
||||
await customStatement('PRAGMA foreign_keys = ON;');
|
||||
await definitionsDrift.optimizeFtsIndex();
|
||||
},
|
||||
);
|
||||
|
||||
FeedDatabase(super.e);
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
// dart format width=80
|
||||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart'
|
||||
as i1;
|
||||
import 'package:weblibre/features/web_feed/data/database/daos/article.dart'
|
||||
as i2;
|
||||
import 'package:weblibre/features/web_feed/data/database/database.dart' as i3;
|
||||
import 'package:weblibre/features/web_feed/data/database/daos/feed.dart' as i4;
|
||||
import 'package:drift/internal/modular.dart' as i5;
|
||||
import 'package:sqlite3/common.dart' as i6;
|
||||
|
||||
abstract class $FeedDatabase extends i0.GeneratedDatabase {
|
||||
$FeedDatabase(i0.QueryExecutor e) : super(e);
|
||||
$FeedDatabaseManager get managers => $FeedDatabaseManager(this);
|
||||
late final i1.Feed feed = i1.Feed(this);
|
||||
late final i1.Article article = i1.Article(this);
|
||||
late final i1.ArticleView articleView = i1.ArticleView(this);
|
||||
late final i1.ArticleFts articleFts = i1.ArticleFts(this);
|
||||
late final i2.ArticleDao articleDao = i2.ArticleDao(this as i3.FeedDatabase);
|
||||
late final i4.FeedDao feedDao = i4.FeedDao(this as i3.FeedDatabase);
|
||||
i1.DefinitionsDrift get definitionsDrift => i5.ReadDatabaseContainer(
|
||||
this,
|
||||
).accessor<i1.DefinitionsDrift>(i1.DefinitionsDrift.new);
|
||||
@override
|
||||
Iterable<i0.TableInfo<i0.Table, Object?>> get allTables =>
|
||||
allSchemaEntities.whereType<i0.TableInfo<i0.Table, Object?>>();
|
||||
@override
|
||||
List<i0.DatabaseSchemaEntity> get allSchemaEntities => [
|
||||
feed,
|
||||
article,
|
||||
articleView,
|
||||
i1.articleFeedId,
|
||||
articleFts,
|
||||
i1.articleAfterInsert,
|
||||
i1.articleAfterDelete,
|
||||
i1.articleAfterUpdate,
|
||||
];
|
||||
@override
|
||||
i0.StreamQueryUpdateRules get streamUpdateRules =>
|
||||
const i0.StreamQueryUpdateRules([
|
||||
i0.WritePropagation(
|
||||
on: i0.TableUpdateQuery.onTableName(
|
||||
'feed',
|
||||
limitUpdateKind: i0.UpdateKind.delete,
|
||||
),
|
||||
result: [i0.TableUpdate('article', kind: i0.UpdateKind.delete)],
|
||||
),
|
||||
i0.WritePropagation(
|
||||
on: i0.TableUpdateQuery.onTableName(
|
||||
'article',
|
||||
limitUpdateKind: i0.UpdateKind.insert,
|
||||
),
|
||||
result: [i0.TableUpdate('article_fts', kind: i0.UpdateKind.insert)],
|
||||
),
|
||||
i0.WritePropagation(
|
||||
on: i0.TableUpdateQuery.onTableName(
|
||||
'article',
|
||||
limitUpdateKind: i0.UpdateKind.delete,
|
||||
),
|
||||
result: [i0.TableUpdate('article_fts', kind: i0.UpdateKind.insert)],
|
||||
),
|
||||
i0.WritePropagation(
|
||||
on: i0.TableUpdateQuery.onTableName(
|
||||
'article',
|
||||
limitUpdateKind: i0.UpdateKind.update,
|
||||
),
|
||||
result: [i0.TableUpdate('article_fts', kind: i0.UpdateKind.insert)],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
class $FeedDatabaseManager {
|
||||
final $FeedDatabase _db;
|
||||
$FeedDatabaseManager(this._db);
|
||||
i1.$FeedTableManager get feed => i1.$FeedTableManager(_db, _db.feed);
|
||||
i1.$ArticleTableManager get article =>
|
||||
i1.$ArticleTableManager(_db, _db.article);
|
||||
i1.$ArticleFtsTableManager get articleFts =>
|
||||
i1.$ArticleFtsTableManager(_db, _db.articleFts);
|
||||
}
|
||||
|
||||
extension DefineFunctions on i6.CommonDatabase {
|
||||
void defineFunctions({
|
||||
required String Function(int, String?) lexoRankNext,
|
||||
required String Function(int, String?) lexoRankPrevious,
|
||||
required String Function(String?, String?) lexoRankReorderAfter,
|
||||
required String Function(String?, String?) lexoRankReorderBefore,
|
||||
}) {
|
||||
createFunction(
|
||||
functionName: 'lexo_rank_next',
|
||||
argumentCount: const i6.AllowedArgumentCount(2),
|
||||
function: (args) {
|
||||
final arg0 = args[0] as int;
|
||||
final arg1 = args[1] as String?;
|
||||
return lexoRankNext(arg0, arg1);
|
||||
},
|
||||
);
|
||||
createFunction(
|
||||
functionName: 'lexo_rank_previous',
|
||||
argumentCount: const i6.AllowedArgumentCount(2),
|
||||
function: (args) {
|
||||
final arg0 = args[0] as int;
|
||||
final arg1 = args[1] as String?;
|
||||
return lexoRankPrevious(arg0, arg1);
|
||||
},
|
||||
);
|
||||
createFunction(
|
||||
functionName: 'lexo_rank_reorder_after',
|
||||
argumentCount: const i6.AllowedArgumentCount(2),
|
||||
function: (args) {
|
||||
final arg0 = args[0] as String?;
|
||||
final arg1 = args[1] as String?;
|
||||
return lexoRankReorderAfter(arg0, arg1);
|
||||
},
|
||||
);
|
||||
createFunction(
|
||||
functionName: 'lexo_rank_reorder_before',
|
||||
argumentCount: const i6.AllowedArgumentCount(2),
|
||||
function: (args) {
|
||||
final arg0 = args[0] as String?;
|
||||
final arg1 = args[1] as String?;
|
||||
return lexoRankReorderBefore(arg0, arg1);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import 'package:weblibre/data/database/converters/uri.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article_query_result.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/converters/feed_authors.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/converters/feed_categories.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/converters/feed_links.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
|
||||
|
||||
CREATE TABLE feed (
|
||||
url TEXT PRIMARY KEY NOT NULL MAPPED BY `const UriConverter()`,
|
||||
title TEXT,
|
||||
description TEXT,
|
||||
icon TEXT MAPPED BY `const UriConverterNullable()`,
|
||||
site_link TEXT MAPPED BY `const UriConverterNullable()`,
|
||||
authors TEXT MAPPED BY `const FeedAuthorsConverter()`,
|
||||
tags TEXT MAPPED BY `const FeedCategoriesConverter()`,
|
||||
last_fetched DATETIME
|
||||
);
|
||||
|
||||
CREATE TABLE article (
|
||||
id TEXT PRIMARY KEY NOT NULL,
|
||||
feed_id TEXT NOT NULL MAPPED BY `const UriConverter()` REFERENCES feed ("url") ON DELETE CASCADE,
|
||||
fetched DATETIME NOT NULL,
|
||||
created DATETIME,
|
||||
updated DATETIME,
|
||||
last_read DATETIME,
|
||||
title TEXT,
|
||||
authors TEXT MAPPED BY `const FeedAuthorsConverter()`,
|
||||
tags TEXT MAPPED BY `const FeedCategoriesConverter()`,
|
||||
links TEXT MAPPED BY `const FeedLinksConverter()`,
|
||||
summaryHtml TEXT,
|
||||
summaryMarkdown TEXT,
|
||||
summaryPlain TEXT,
|
||||
contentHtml TEXT,
|
||||
contentMarkdown TEXT,
|
||||
contentPlain TEXT
|
||||
) WITH FeedArticle;
|
||||
|
||||
CREATE VIEW article_view WITH FeedArticle AS
|
||||
SELECT
|
||||
a.*,
|
||||
f.icon,
|
||||
f.site_link
|
||||
FROM
|
||||
article a
|
||||
INNER JOIN
|
||||
feed f on f.url = a.feed_id;
|
||||
|
||||
CREATE INDEX article_feed_id ON article (feed_id);
|
||||
|
||||
CREATE VIRTUAL TABLE article_fts
|
||||
USING fts5(
|
||||
title,
|
||||
summaryPlain,
|
||||
contentPlain,
|
||||
content=article,
|
||||
tokenize="trigram"
|
||||
);
|
||||
|
||||
-- Triggers to keep the FTS index up to date.
|
||||
CREATE TRIGGER article_after_insert AFTER INSERT ON article BEGIN
|
||||
INSERT INTO
|
||||
article_fts(rowid, title, summaryPlain, contentPlain)
|
||||
VALUES (new.rowid, new.title, new.summaryPlain, new.contentPlain);
|
||||
END;
|
||||
CREATE TRIGGER article_after_delete AFTER DELETE ON article BEGIN
|
||||
INSERT INTO
|
||||
article_fts(article_fts, rowid, title, summaryPlain, contentPlain)
|
||||
VALUES('delete', old.rowid, old.title, old.summaryPlain, old.contentPlain);
|
||||
END;
|
||||
CREATE TRIGGER article_after_update AFTER UPDATE ON article BEGIN
|
||||
INSERT INTO
|
||||
article_fts(article_fts, rowid, title, summaryPlain, contentPlain)
|
||||
VALUES('delete', old.rowid, old.title, old.summaryPlain, old.contentPlain);
|
||||
INSERT INTO
|
||||
article_fts(rowid, title, summaryPlain, contentPlain)
|
||||
VALUES (new.rowid, new.title, new.summaryPlain, new.contentPlain);
|
||||
END;
|
||||
|
||||
optimizeFtsIndex:
|
||||
INSERT INTO article_fts(article_fts) VALUES ('optimize');
|
||||
|
||||
queryArticlesBasic(:feed_id AS TEXT OR NULL) WITH FeedArticleQueryResult:
|
||||
WITH weights AS (
|
||||
SELECT
|
||||
-- Customize these weights (higher = more important)
|
||||
1.0 as title_weight -- Title matches are most important
|
||||
)
|
||||
SELECT
|
||||
a.*,
|
||||
f.icon,
|
||||
(
|
||||
bm25(article_fts, weights.title_weight)
|
||||
) AS weighted_rank
|
||||
FROM article_fts fts
|
||||
INNER JOIN
|
||||
article a ON a.rowid = fts.rowid
|
||||
INNER JOIN
|
||||
feed f ON f.url = a.feed_id
|
||||
CROSS JOIN weights
|
||||
WHERE
|
||||
fts.title LIKE :query AND
|
||||
(:feed_id IS NULL OR a.feed_id = :feed_id)
|
||||
ORDER BY
|
||||
weighted_rank ASC,
|
||||
a.created DESC NULLS LAST
|
||||
LIMIT :limit;
|
||||
|
||||
queryArticlesFullContent(:feed_id AS TEXT OR NULL) WITH FeedArticleQueryResult:
|
||||
WITH weights AS (
|
||||
SELECT
|
||||
-- Customize these weights (higher = more important)
|
||||
10.0 as title_weight, -- Title matches are most important
|
||||
3.0 as summary_weight, -- Summary matches are quite important
|
||||
1.0 as content_weight -- Content matches are basic
|
||||
)
|
||||
SELECT
|
||||
a.*,
|
||||
f.icon,
|
||||
highlight(article_fts, 0, :beforeMatch, :afterMatch) AS title_highlight,
|
||||
snippet(article_fts, 1, :beforeMatch, :afterMatch, :ellipsis, :snippetLength) AS summary_snippet,
|
||||
snippet(article_fts, 2, :beforeMatch, :afterMatch, :ellipsis, :snippetLength) AS content_snippet,
|
||||
(
|
||||
bm25(article_fts, weights.title_weight, weights.summary_weight,
|
||||
weights.content_weight)
|
||||
) AS weighted_rank
|
||||
FROM article_fts(:query) fts
|
||||
INNER JOIN
|
||||
article a ON a.rowid = fts.rowid
|
||||
INNER JOIN
|
||||
feed f ON f.url = a.feed_id
|
||||
CROSS JOIN weights
|
||||
WHERE
|
||||
:feed_id IS NULL OR a.feed_id = :feed_id
|
||||
ORDER BY
|
||||
weighted_rank ASC,
|
||||
a.created DESC NULLS LAST
|
||||
LIMIT :limit;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_author.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_category.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_link.dart';
|
||||
|
||||
part 'feed_article.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
@CopyWith()
|
||||
class FeedArticle with FastEquatable implements Insertable<FeedArticle> {
|
||||
final String id;
|
||||
final Uri feedId;
|
||||
final DateTime fetched;
|
||||
final DateTime? created;
|
||||
final DateTime? updated;
|
||||
final DateTime? lastRead;
|
||||
final String? title;
|
||||
final List<FeedAuthor>? authors;
|
||||
final List<FeedCategory>? tags;
|
||||
final List<FeedLink>? links;
|
||||
final String? summaryHtml;
|
||||
final String? summaryMarkdown;
|
||||
final String? summaryPlain;
|
||||
final String? contentHtml;
|
||||
final String? contentMarkdown;
|
||||
final String? contentPlain;
|
||||
|
||||
//Derived by view from feed table, should not get inserted
|
||||
final Uri? icon;
|
||||
final Uri? siteLink;
|
||||
|
||||
FeedArticle({
|
||||
required this.id,
|
||||
required this.feedId,
|
||||
required this.fetched,
|
||||
this.created,
|
||||
this.updated,
|
||||
this.lastRead,
|
||||
this.title,
|
||||
this.authors,
|
||||
this.tags,
|
||||
this.links,
|
||||
this.summaryHtml,
|
||||
this.summaryMarkdown,
|
||||
this.summaryPlain,
|
||||
this.contentHtml,
|
||||
this.contentMarkdown,
|
||||
this.contentPlain,
|
||||
this.icon,
|
||||
this.siteLink,
|
||||
});
|
||||
|
||||
factory FeedArticle.fromJson(Map<String, dynamic> json) =>
|
||||
_$FeedArticleFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FeedArticleToJson(this);
|
||||
|
||||
@override
|
||||
Map<String, Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, Expression>{};
|
||||
map['id'] = Variable<String>(id);
|
||||
{
|
||||
map['feed_id'] = Variable<String>(Article.$converterfeedId.toSql(feedId));
|
||||
}
|
||||
map['fetched'] = Variable<DateTime>(fetched);
|
||||
if (!nullToAbsent || created != null) {
|
||||
map['created'] = Variable<DateTime>(created);
|
||||
}
|
||||
if (!nullToAbsent || updated != null) {
|
||||
map['updated'] = Variable<DateTime>(updated);
|
||||
}
|
||||
if (!nullToAbsent || lastRead != null) {
|
||||
map['last_read'] = Variable<DateTime>(lastRead);
|
||||
}
|
||||
if (!nullToAbsent || title != null) {
|
||||
map['title'] = Variable<String>(title);
|
||||
}
|
||||
if (!nullToAbsent || authors != null) {
|
||||
map['authors'] = Variable<String>(
|
||||
Article.$converterauthorsn.toSql(authors),
|
||||
);
|
||||
}
|
||||
if (!nullToAbsent || tags != null) {
|
||||
map['tags'] = Variable<String>(Article.$convertertagsn.toSql(tags));
|
||||
}
|
||||
if (!nullToAbsent || links != null) {
|
||||
map['links'] = Variable<String>(Article.$converterlinksn.toSql(links));
|
||||
}
|
||||
if (!nullToAbsent || summaryHtml != null) {
|
||||
map['summaryHtml'] = Variable<String>(summaryHtml);
|
||||
}
|
||||
if (!nullToAbsent || summaryMarkdown != null) {
|
||||
map['summaryMarkdown'] = Variable<String>(summaryMarkdown);
|
||||
}
|
||||
if (!nullToAbsent || summaryPlain != null) {
|
||||
map['summaryPlain'] = Variable<String>(summaryPlain);
|
||||
}
|
||||
if (!nullToAbsent || contentHtml != null) {
|
||||
map['contentHtml'] = Variable<String>(contentHtml);
|
||||
}
|
||||
if (!nullToAbsent || contentMarkdown != null) {
|
||||
map['contentMarkdown'] = Variable<String>(contentMarkdown);
|
||||
}
|
||||
if (!nullToAbsent || contentPlain != null) {
|
||||
map['contentPlain'] = Variable<String>(contentPlain);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [
|
||||
id,
|
||||
feedId,
|
||||
fetched,
|
||||
created,
|
||||
updated,
|
||||
lastRead,
|
||||
title,
|
||||
authors,
|
||||
tags,
|
||||
links,
|
||||
summaryHtml,
|
||||
summaryMarkdown,
|
||||
summaryPlain,
|
||||
contentHtml,
|
||||
contentMarkdown,
|
||||
contentPlain,
|
||||
icon,
|
||||
siteLink,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_article.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// CopyWithGenerator
|
||||
// **************************************************************************
|
||||
|
||||
abstract class _$FeedArticleCWProxy {
|
||||
FeedArticle id(String id);
|
||||
|
||||
FeedArticle feedId(Uri feedId);
|
||||
|
||||
FeedArticle fetched(DateTime fetched);
|
||||
|
||||
FeedArticle created(DateTime? created);
|
||||
|
||||
FeedArticle updated(DateTime? updated);
|
||||
|
||||
FeedArticle lastRead(DateTime? lastRead);
|
||||
|
||||
FeedArticle title(String? title);
|
||||
|
||||
FeedArticle authors(List<FeedAuthor>? authors);
|
||||
|
||||
FeedArticle tags(List<FeedCategory>? tags);
|
||||
|
||||
FeedArticle links(List<FeedLink>? links);
|
||||
|
||||
FeedArticle summaryHtml(String? summaryHtml);
|
||||
|
||||
FeedArticle summaryMarkdown(String? summaryMarkdown);
|
||||
|
||||
FeedArticle summaryPlain(String? summaryPlain);
|
||||
|
||||
FeedArticle contentHtml(String? contentHtml);
|
||||
|
||||
FeedArticle contentMarkdown(String? contentMarkdown);
|
||||
|
||||
FeedArticle contentPlain(String? contentPlain);
|
||||
|
||||
FeedArticle icon(Uri? icon);
|
||||
|
||||
FeedArticle siteLink(Uri? siteLink);
|
||||
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `FeedArticle(...).copyWith.fieldName(value)`.
|
||||
///
|
||||
/// Example:
|
||||
/// ```dart
|
||||
/// FeedArticle(...).copyWith(id: 12, name: "My name")
|
||||
/// ```
|
||||
FeedArticle call({
|
||||
String id,
|
||||
Uri feedId,
|
||||
DateTime fetched,
|
||||
DateTime? created,
|
||||
DateTime? updated,
|
||||
DateTime? lastRead,
|
||||
String? title,
|
||||
List<FeedAuthor>? authors,
|
||||
List<FeedCategory>? tags,
|
||||
List<FeedLink>? links,
|
||||
String? summaryHtml,
|
||||
String? summaryMarkdown,
|
||||
String? summaryPlain,
|
||||
String? contentHtml,
|
||||
String? contentMarkdown,
|
||||
String? contentPlain,
|
||||
Uri? icon,
|
||||
Uri? siteLink,
|
||||
});
|
||||
}
|
||||
|
||||
/// Callable proxy for `copyWith` functionality.
|
||||
/// Use as `instanceOfFeedArticle.copyWith(...)` or call `instanceOfFeedArticle.copyWith.fieldName(value)` for a single field.
|
||||
class _$FeedArticleCWProxyImpl implements _$FeedArticleCWProxy {
|
||||
const _$FeedArticleCWProxyImpl(this._value);
|
||||
|
||||
final FeedArticle _value;
|
||||
|
||||
@override
|
||||
FeedArticle id(String id) => call(id: id);
|
||||
|
||||
@override
|
||||
FeedArticle feedId(Uri feedId) => call(feedId: feedId);
|
||||
|
||||
@override
|
||||
FeedArticle fetched(DateTime fetched) => call(fetched: fetched);
|
||||
|
||||
@override
|
||||
FeedArticle created(DateTime? created) => call(created: created);
|
||||
|
||||
@override
|
||||
FeedArticle updated(DateTime? updated) => call(updated: updated);
|
||||
|
||||
@override
|
||||
FeedArticle lastRead(DateTime? lastRead) => call(lastRead: lastRead);
|
||||
|
||||
@override
|
||||
FeedArticle title(String? title) => call(title: title);
|
||||
|
||||
@override
|
||||
FeedArticle authors(List<FeedAuthor>? authors) => call(authors: authors);
|
||||
|
||||
@override
|
||||
FeedArticle tags(List<FeedCategory>? tags) => call(tags: tags);
|
||||
|
||||
@override
|
||||
FeedArticle links(List<FeedLink>? links) => call(links: links);
|
||||
|
||||
@override
|
||||
FeedArticle summaryHtml(String? summaryHtml) =>
|
||||
call(summaryHtml: summaryHtml);
|
||||
|
||||
@override
|
||||
FeedArticle summaryMarkdown(String? summaryMarkdown) =>
|
||||
call(summaryMarkdown: summaryMarkdown);
|
||||
|
||||
@override
|
||||
FeedArticle summaryPlain(String? summaryPlain) =>
|
||||
call(summaryPlain: summaryPlain);
|
||||
|
||||
@override
|
||||
FeedArticle contentHtml(String? contentHtml) =>
|
||||
call(contentHtml: contentHtml);
|
||||
|
||||
@override
|
||||
FeedArticle contentMarkdown(String? contentMarkdown) =>
|
||||
call(contentMarkdown: contentMarkdown);
|
||||
|
||||
@override
|
||||
FeedArticle contentPlain(String? contentPlain) =>
|
||||
call(contentPlain: contentPlain);
|
||||
|
||||
@override
|
||||
FeedArticle icon(Uri? icon) => call(icon: icon);
|
||||
|
||||
@override
|
||||
FeedArticle siteLink(Uri? siteLink) => call(siteLink: siteLink);
|
||||
|
||||
@override
|
||||
/// Creates a new instance with the provided field values.
|
||||
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `FeedArticle(...).copyWith.fieldName(value)`.
|
||||
///
|
||||
/// Example:
|
||||
/// ```dart
|
||||
/// FeedArticle(...).copyWith(id: 12, name: "My name")
|
||||
/// ```
|
||||
FeedArticle call({
|
||||
Object? id = const $CopyWithPlaceholder(),
|
||||
Object? feedId = const $CopyWithPlaceholder(),
|
||||
Object? fetched = const $CopyWithPlaceholder(),
|
||||
Object? created = const $CopyWithPlaceholder(),
|
||||
Object? updated = const $CopyWithPlaceholder(),
|
||||
Object? lastRead = const $CopyWithPlaceholder(),
|
||||
Object? title = const $CopyWithPlaceholder(),
|
||||
Object? authors = const $CopyWithPlaceholder(),
|
||||
Object? tags = const $CopyWithPlaceholder(),
|
||||
Object? links = const $CopyWithPlaceholder(),
|
||||
Object? summaryHtml = const $CopyWithPlaceholder(),
|
||||
Object? summaryMarkdown = const $CopyWithPlaceholder(),
|
||||
Object? summaryPlain = const $CopyWithPlaceholder(),
|
||||
Object? contentHtml = const $CopyWithPlaceholder(),
|
||||
Object? contentMarkdown = const $CopyWithPlaceholder(),
|
||||
Object? contentPlain = const $CopyWithPlaceholder(),
|
||||
Object? icon = const $CopyWithPlaceholder(),
|
||||
Object? siteLink = const $CopyWithPlaceholder(),
|
||||
}) {
|
||||
return FeedArticle(
|
||||
id: id == const $CopyWithPlaceholder() || id == null
|
||||
? _value.id
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: id as String,
|
||||
feedId: feedId == const $CopyWithPlaceholder() || feedId == null
|
||||
? _value.feedId
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: feedId as Uri,
|
||||
fetched: fetched == const $CopyWithPlaceholder() || fetched == null
|
||||
? _value.fetched
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: fetched as DateTime,
|
||||
created: created == const $CopyWithPlaceholder()
|
||||
? _value.created
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: created as DateTime?,
|
||||
updated: updated == const $CopyWithPlaceholder()
|
||||
? _value.updated
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: updated as DateTime?,
|
||||
lastRead: lastRead == const $CopyWithPlaceholder()
|
||||
? _value.lastRead
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: lastRead as DateTime?,
|
||||
title: title == const $CopyWithPlaceholder()
|
||||
? _value.title
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: title as String?,
|
||||
authors: authors == const $CopyWithPlaceholder()
|
||||
? _value.authors
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: authors as List<FeedAuthor>?,
|
||||
tags: tags == const $CopyWithPlaceholder()
|
||||
? _value.tags
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: tags as List<FeedCategory>?,
|
||||
links: links == const $CopyWithPlaceholder()
|
||||
? _value.links
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: links as List<FeedLink>?,
|
||||
summaryHtml: summaryHtml == const $CopyWithPlaceholder()
|
||||
? _value.summaryHtml
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: summaryHtml as String?,
|
||||
summaryMarkdown: summaryMarkdown == const $CopyWithPlaceholder()
|
||||
? _value.summaryMarkdown
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: summaryMarkdown as String?,
|
||||
summaryPlain: summaryPlain == const $CopyWithPlaceholder()
|
||||
? _value.summaryPlain
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: summaryPlain as String?,
|
||||
contentHtml: contentHtml == const $CopyWithPlaceholder()
|
||||
? _value.contentHtml
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: contentHtml as String?,
|
||||
contentMarkdown: contentMarkdown == const $CopyWithPlaceholder()
|
||||
? _value.contentMarkdown
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: contentMarkdown as String?,
|
||||
contentPlain: contentPlain == const $CopyWithPlaceholder()
|
||||
? _value.contentPlain
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: contentPlain as String?,
|
||||
icon: icon == const $CopyWithPlaceholder()
|
||||
? _value.icon
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: icon as Uri?,
|
||||
siteLink: siteLink == const $CopyWithPlaceholder()
|
||||
? _value.siteLink
|
||||
// ignore: cast_nullable_to_non_nullable
|
||||
: siteLink as Uri?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension $FeedArticleCopyWith on FeedArticle {
|
||||
/// Returns a callable class used to build a new instance with modified fields.
|
||||
/// Example: `instanceOfFeedArticle.copyWith(...)` or `instanceOfFeedArticle.copyWith.fieldName(...)`.
|
||||
// ignore: library_private_types_in_public_api
|
||||
_$FeedArticleCWProxy get copyWith => _$FeedArticleCWProxyImpl(this);
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
FeedArticle _$FeedArticleFromJson(Map<String, dynamic> json) => FeedArticle(
|
||||
id: json['id'] as String,
|
||||
feedId: Uri.parse(json['feedId'] as String),
|
||||
fetched: DateTime.parse(json['fetched'] as String),
|
||||
created: json['created'] == null
|
||||
? null
|
||||
: DateTime.parse(json['created'] as String),
|
||||
updated: json['updated'] == null
|
||||
? null
|
||||
: DateTime.parse(json['updated'] as String),
|
||||
lastRead: json['lastRead'] == null
|
||||
? null
|
||||
: DateTime.parse(json['lastRead'] as String),
|
||||
title: json['title'] as String?,
|
||||
authors: (json['authors'] as List<dynamic>?)
|
||||
?.map((e) => FeedAuthor.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
tags: (json['tags'] as List<dynamic>?)
|
||||
?.map((e) => FeedCategory.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
links: (json['links'] as List<dynamic>?)
|
||||
?.map((e) => FeedLink.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
summaryHtml: json['summaryHtml'] as String?,
|
||||
summaryMarkdown: json['summaryMarkdown'] as String?,
|
||||
summaryPlain: json['summaryPlain'] as String?,
|
||||
contentHtml: json['contentHtml'] as String?,
|
||||
contentMarkdown: json['contentMarkdown'] as String?,
|
||||
contentPlain: json['contentPlain'] as String?,
|
||||
icon: json['icon'] == null ? null : Uri.parse(json['icon'] as String),
|
||||
siteLink: json['siteLink'] == null
|
||||
? null
|
||||
: Uri.parse(json['siteLink'] as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$FeedArticleToJson(FeedArticle instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'feedId': instance.feedId.toString(),
|
||||
'fetched': instance.fetched.toIso8601String(),
|
||||
'created': instance.created?.toIso8601String(),
|
||||
'updated': instance.updated?.toIso8601String(),
|
||||
'lastRead': instance.lastRead?.toIso8601String(),
|
||||
'title': instance.title,
|
||||
'authors': instance.authors?.map((e) => e.toJson()).toList(),
|
||||
'tags': instance.tags?.map((e) => e.toJson()).toList(),
|
||||
'links': instance.links?.map((e) => e.toJson()).toList(),
|
||||
'summaryHtml': instance.summaryHtml,
|
||||
'summaryMarkdown': instance.summaryMarkdown,
|
||||
'summaryPlain': instance.summaryPlain,
|
||||
'contentHtml': instance.contentHtml,
|
||||
'contentMarkdown': instance.contentMarkdown,
|
||||
'contentPlain': instance.contentPlain,
|
||||
'icon': instance.icon?.toString(),
|
||||
'siteLink': instance.siteLink?.toString(),
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
|
||||
|
||||
class FeedArticleQueryResult extends FeedArticle {
|
||||
final String? titleHighlight;
|
||||
final String? summarySnippet;
|
||||
final String? contentSnippet;
|
||||
|
||||
final double weightedRank;
|
||||
|
||||
FeedArticleQueryResult({
|
||||
required super.id,
|
||||
required super.feedId,
|
||||
required super.fetched,
|
||||
required this.weightedRank,
|
||||
required super.created,
|
||||
required super.updated,
|
||||
required super.lastRead,
|
||||
required super.title,
|
||||
required super.authors,
|
||||
required super.tags,
|
||||
required super.links,
|
||||
required super.summaryHtml,
|
||||
required super.summaryMarkdown,
|
||||
required super.summaryPlain,
|
||||
required super.contentHtml,
|
||||
required super.contentMarkdown,
|
||||
required super.contentPlain,
|
||||
required super.icon,
|
||||
this.titleHighlight,
|
||||
this.summarySnippet,
|
||||
this.contentSnippet,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [
|
||||
...super.hashParameters,
|
||||
weightedRank,
|
||||
summarySnippet,
|
||||
contentSnippet,
|
||||
titleHighlight,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'feed_author.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class FeedAuthor with FastEquatable {
|
||||
final String? name;
|
||||
final String? email;
|
||||
|
||||
FeedAuthor({this.name, this.email});
|
||||
|
||||
factory FeedAuthor.fromJson(Map<String, dynamic> json) =>
|
||||
_$FeedAuthorFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FeedAuthorToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [name, email];
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_author.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
FeedAuthor _$FeedAuthorFromJson(Map<String, dynamic> json) =>
|
||||
FeedAuthor(name: json['name'] as String?, email: json['email'] as String?);
|
||||
|
||||
Map<String, dynamic> _$FeedAuthorToJson(FeedAuthor instance) =>
|
||||
<String, dynamic>{'name': instance.name, 'email': instance.email};
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'feed_category.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class FeedCategory with FastEquatable {
|
||||
final String id;
|
||||
final String? title;
|
||||
|
||||
FeedCategory({required this.id, this.title});
|
||||
|
||||
factory FeedCategory.fromJson(Map<String, dynamic> json) =>
|
||||
_$FeedCategoryFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FeedCategoryToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [id, title];
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_category.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
FeedCategory _$FeedCategoryFromJson(Map<String, dynamic> json) =>
|
||||
FeedCategory(id: json['id'] as String, title: json['title'] as String?);
|
||||
|
||||
Map<String, dynamic> _$FeedCategoryToJson(FeedCategory instance) =>
|
||||
<String, dynamic>{'id': instance.id, 'title': instance.title};
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'feed_link.g.dart';
|
||||
|
||||
enum FeedLinkRelation {
|
||||
///an alternate representation of the entry or feed, for example a permalink to the html version of the entry, or the front page of the weblog.
|
||||
alternate,
|
||||
|
||||
///a related resource which is potentially large in size and might require special handling, for example an audio or video recording.
|
||||
enclosure,
|
||||
|
||||
///an document related to the entry or feed.
|
||||
related,
|
||||
|
||||
///the feed itself.
|
||||
self,
|
||||
|
||||
///the source of the information provided in the entry.
|
||||
via,
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class FeedLink with FastEquatable {
|
||||
final Uri uri;
|
||||
final FeedLinkRelation? relation;
|
||||
final String? title;
|
||||
|
||||
FeedLink({required this.uri, this.relation, this.title});
|
||||
|
||||
factory FeedLink.fromJson(Map<String, dynamic> json) =>
|
||||
_$FeedLinkFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FeedLinkToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get hashParameters => [uri, relation, title];
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_link.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
FeedLink _$FeedLinkFromJson(Map<String, dynamic> json) => FeedLink(
|
||||
uri: Uri.parse(json['uri'] as String),
|
||||
relation: $enumDecodeNullable(_$FeedLinkRelationEnumMap, json['relation']),
|
||||
title: json['title'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$FeedLinkToJson(FeedLink instance) => <String, dynamic>{
|
||||
'uri': instance.uri.toString(),
|
||||
'relation': _$FeedLinkRelationEnumMap[instance.relation],
|
||||
'title': instance.title,
|
||||
};
|
||||
|
||||
const _$FeedLinkRelationEnumMap = {
|
||||
FeedLinkRelation.alternate: 'alternate',
|
||||
FeedLinkRelation.enclosure: 'enclosure',
|
||||
FeedLinkRelation.related: 'related',
|
||||
FeedLinkRelation.self: 'self',
|
||||
FeedLinkRelation.via: 'via',
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/converters/feed_data.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
|
||||
|
||||
part 'feed_parse_result.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class FeedParseResult {
|
||||
@FeedDataConverter()
|
||||
final FeedData feedData;
|
||||
final List<FeedArticle> articleData;
|
||||
|
||||
FeedParseResult({required this.feedData, required this.articleData});
|
||||
|
||||
factory FeedParseResult.fromJson(Map<String, dynamic> json) =>
|
||||
_$FeedParseResultFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$FeedParseResultToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_parse_result.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
FeedParseResult _$FeedParseResultFromJson(Map<String, dynamic> json) =>
|
||||
FeedParseResult(
|
||||
feedData: const FeedDataConverter().fromJson(
|
||||
json['feedData'] as Map<String, dynamic>,
|
||||
),
|
||||
articleData: (json['articleData'] as List<dynamic>)
|
||||
.map((e) => FeedArticle.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$FeedParseResultToJson(FeedParseResult instance) =>
|
||||
<String, dynamic>{
|
||||
'feedData': const FeedDataConverter().toJson(instance.feedData),
|
||||
'articleData': instance.articleData.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:sqlite3_flutter_libs/sqlite3_flutter_libs.dart';
|
||||
import 'package:weblibre/core/database_registry.dart';
|
||||
import 'package:weblibre/core/filesystem.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/database.dart';
|
||||
|
||||
part 'providers.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
FeedDatabase feedDatabase(Ref ref) {
|
||||
final db = FeedDatabase(
|
||||
LazyDatabase(() async {
|
||||
final file = File(p.join(filesystem.profileDatabasesDir.path, 'feed.db'));
|
||||
|
||||
// Also work around limitations on old Android versions
|
||||
if (Platform.isAndroid) {
|
||||
await applyWorkaroundToOpenSqlite3OnOldAndroidVersions();
|
||||
}
|
||||
|
||||
return NativeDatabase.createInBackground(file);
|
||||
}),
|
||||
);
|
||||
|
||||
DatabaseRegistry.instance.register('feed', db);
|
||||
|
||||
ref.onDispose(() async {
|
||||
await db.close();
|
||||
});
|
||||
|
||||
return db;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'providers.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(feedDatabase)
|
||||
final feedDatabaseProvider = FeedDatabaseProvider._();
|
||||
|
||||
final class FeedDatabaseProvider
|
||||
extends $FunctionalProvider<FeedDatabase, FeedDatabase, FeedDatabase>
|
||||
with $Provider<FeedDatabase> {
|
||||
FeedDatabaseProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'feedDatabaseProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$feedDatabaseHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<FeedDatabase> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FeedDatabase create(Ref ref) {
|
||||
return feedDatabase(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(FeedDatabase value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<FeedDatabase>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$feedDatabaseHash() => r'1ecae87a3de5b2d43136fdb73411727b0b217621';
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_parse_result.dart';
|
||||
import 'package:weblibre/features/web_feed/data/providers.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/providers/article_filter.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/repositories/feed_repository.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/services/feed_reader.dart';
|
||||
|
||||
part 'providers.g.dart';
|
||||
|
||||
@Riverpod()
|
||||
class ArticleSearch extends _$ArticleSearch {
|
||||
late StreamController<List<FeedArticle>> _streamController;
|
||||
|
||||
Future<void> search(
|
||||
String input, {
|
||||
int snippetLength = 120,
|
||||
int maxResults = 25,
|
||||
String matchPrefix = '***',
|
||||
String matchSuffix = '***',
|
||||
String ellipsis = '…',
|
||||
}) async {
|
||||
if (input.isNotEmpty) {
|
||||
await ref
|
||||
.read(feedDatabaseProvider)
|
||||
.articleDao
|
||||
.queryArticles(
|
||||
matchPrefix: matchPrefix,
|
||||
matchSuffix: matchSuffix,
|
||||
ellipsis: ellipsis,
|
||||
snippetLength: snippetLength,
|
||||
searchString: input,
|
||||
feedId: feedId,
|
||||
limit: maxResults,
|
||||
)
|
||||
.get()
|
||||
.then((value) {
|
||||
if (!_streamController.isClosed) {
|
||||
_streamController.add(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<List<FeedArticle>> build(Uri? feedId) {
|
||||
_streamController = StreamController();
|
||||
|
||||
ref.onDispose(() async {
|
||||
await _streamController.close();
|
||||
});
|
||||
|
||||
return ConcatStream([Stream.value([]), _streamController.stream]);
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
Stream<List<FeedData>> feedList(Ref ref) {
|
||||
final repository = ref.watch(feedRepositoryProvider.notifier);
|
||||
return repository.watchFeeds();
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
Stream<FeedData?> feedData(Ref ref, Uri? feedId) {
|
||||
final repository = ref.watch(feedRepositoryProvider.notifier);
|
||||
|
||||
if (feedId == null) {
|
||||
return Stream.value(null);
|
||||
}
|
||||
|
||||
return repository.watchFeed(feedId);
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
Stream<List<FeedArticle>> feedArticleList(Ref ref, Uri? feedId) {
|
||||
final repository = ref.watch(feedRepositoryProvider.notifier);
|
||||
return repository.watchFeedArticles(feedId);
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
class FilteredArticleList extends _$FilteredArticleList {
|
||||
bool _hasSearch = false;
|
||||
|
||||
void search(String input) {
|
||||
if (input.isNotEmpty) {
|
||||
if (!_hasSearch) {
|
||||
_hasSearch = true;
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
|
||||
//Don't block
|
||||
unawaited(ref.read(articleSearchProvider(feedId).notifier).search(input));
|
||||
} else if (_hasSearch) {
|
||||
_hasSearch = false;
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
AsyncValue<List<FeedArticle>> build(Uri? feedId) {
|
||||
final filterTags = ref.watch(articleFilterProvider);
|
||||
|
||||
final articlesAsync = _hasSearch
|
||||
? ref.watch(articleSearchProvider(feedId))
|
||||
: ref.watch(feedArticleListProvider(feedId));
|
||||
|
||||
return articlesAsync.whenData((articles) {
|
||||
if (filterTags.isNotEmpty) {
|
||||
return articles.where((article) {
|
||||
final tags = article.tags?.map((tag) => tag.id).toSet();
|
||||
|
||||
final authors = article.authors
|
||||
?.map((author) => author.name.whenNotEmpty)
|
||||
.nonNulls
|
||||
.toSet();
|
||||
|
||||
return filterTags.every(
|
||||
(filter) =>
|
||||
(tags?.contains(filter) ?? false) ||
|
||||
(authors?.contains(filter) ?? false),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
return articles;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
Stream<FeedArticle?> feedArticle(
|
||||
Ref ref,
|
||||
String articleId, {
|
||||
required bool updateReadDate,
|
||||
}) async* {
|
||||
final repository = ref.watch(feedRepositoryProvider.notifier);
|
||||
|
||||
if (updateReadDate) {
|
||||
await repository.touchArticleRead(articleId);
|
||||
}
|
||||
|
||||
yield* repository.watchArticle(articleId);
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
Raw<Stream<Map<String, int>>> unreadArticleCount(Ref ref) {
|
||||
final repository = ref.watch(feedRepositoryProvider.notifier);
|
||||
return repository.watchUnreadFeedArticleCount();
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
Stream<int?> unreadFeedArticleCount(Ref ref, Uri feedId) {
|
||||
final stream = ref.watch(unreadArticleCountProvider);
|
||||
return stream.map((counts) => counts[feedId.toString()]);
|
||||
}
|
||||
|
||||
@Riverpod()
|
||||
Future<FeedParseResult> fetchWebFeed(Ref ref, Uri url) {
|
||||
return ref.read(feedReaderProvider.notifier).parseFeed(url);
|
||||
}
|
||||
@@ -0,0 +1,678 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'providers.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(ArticleSearch)
|
||||
final articleSearchProvider = ArticleSearchFamily._();
|
||||
|
||||
final class ArticleSearchProvider
|
||||
extends $StreamNotifierProvider<ArticleSearch, List<FeedArticle>> {
|
||||
ArticleSearchProvider._({
|
||||
required ArticleSearchFamily super.from,
|
||||
required Uri? super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'articleSearchProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$articleSearchHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'articleSearchProvider'
|
||||
''
|
||||
'($argument)';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
ArticleSearch create() => ArticleSearch();
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is ArticleSearchProvider && other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return argument.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
String _$articleSearchHash() => r'48ed3baa560c0e731626f79a8f6ff3dab1e9bc95';
|
||||
|
||||
final class ArticleSearchFamily extends $Family
|
||||
with
|
||||
$ClassFamilyOverride<
|
||||
ArticleSearch,
|
||||
AsyncValue<List<FeedArticle>>,
|
||||
List<FeedArticle>,
|
||||
Stream<List<FeedArticle>>,
|
||||
Uri?
|
||||
> {
|
||||
ArticleSearchFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'articleSearchProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: true,
|
||||
);
|
||||
|
||||
ArticleSearchProvider call(Uri? feedId) =>
|
||||
ArticleSearchProvider._(argument: feedId, from: this);
|
||||
|
||||
@override
|
||||
String toString() => r'articleSearchProvider';
|
||||
}
|
||||
|
||||
abstract class _$ArticleSearch extends $StreamNotifier<List<FeedArticle>> {
|
||||
late final _$args = ref.$arg as Uri?;
|
||||
Uri? get feedId => _$args;
|
||||
|
||||
Stream<List<FeedArticle>> build(Uri? feedId);
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref =
|
||||
this.ref as $Ref<AsyncValue<List<FeedArticle>>, List<FeedArticle>>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<List<FeedArticle>>, List<FeedArticle>>,
|
||||
AsyncValue<List<FeedArticle>>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, () => build(_$args));
|
||||
}
|
||||
}
|
||||
|
||||
@ProviderFor(feedList)
|
||||
final feedListProvider = FeedListProvider._();
|
||||
|
||||
final class FeedListProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<List<FeedData>>,
|
||||
List<FeedData>,
|
||||
Stream<List<FeedData>>
|
||||
>
|
||||
with $FutureModifier<List<FeedData>>, $StreamProvider<List<FeedData>> {
|
||||
FeedListProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'feedListProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$feedListHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$StreamProviderElement<List<FeedData>> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $StreamProviderElement(pointer);
|
||||
|
||||
@override
|
||||
Stream<List<FeedData>> create(Ref ref) {
|
||||
return feedList(ref);
|
||||
}
|
||||
}
|
||||
|
||||
String _$feedListHash() => r'0076186437354768c39fb1d7c8bcfcf7b94c7dd1';
|
||||
|
||||
@ProviderFor(feedData)
|
||||
final feedDataProvider = FeedDataFamily._();
|
||||
|
||||
final class FeedDataProvider
|
||||
extends
|
||||
$FunctionalProvider<AsyncValue<FeedData?>, FeedData?, Stream<FeedData?>>
|
||||
with $FutureModifier<FeedData?>, $StreamProvider<FeedData?> {
|
||||
FeedDataProvider._({
|
||||
required FeedDataFamily super.from,
|
||||
required Uri? super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'feedDataProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$feedDataHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'feedDataProvider'
|
||||
''
|
||||
'($argument)';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$StreamProviderElement<FeedData?> $createElement($ProviderPointer pointer) =>
|
||||
$StreamProviderElement(pointer);
|
||||
|
||||
@override
|
||||
Stream<FeedData?> create(Ref ref) {
|
||||
final argument = this.argument as Uri?;
|
||||
return feedData(ref, argument);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is FeedDataProvider && other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return argument.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
String _$feedDataHash() => r'0599a2e3d159ef3abb6c3d2c871f87da2f5e646b';
|
||||
|
||||
final class FeedDataFamily extends $Family
|
||||
with $FunctionalFamilyOverride<Stream<FeedData?>, Uri?> {
|
||||
FeedDataFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'feedDataProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: true,
|
||||
);
|
||||
|
||||
FeedDataProvider call(Uri? feedId) =>
|
||||
FeedDataProvider._(argument: feedId, from: this);
|
||||
|
||||
@override
|
||||
String toString() => r'feedDataProvider';
|
||||
}
|
||||
|
||||
@ProviderFor(feedArticleList)
|
||||
final feedArticleListProvider = FeedArticleListFamily._();
|
||||
|
||||
final class FeedArticleListProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<List<FeedArticle>>,
|
||||
List<FeedArticle>,
|
||||
Stream<List<FeedArticle>>
|
||||
>
|
||||
with
|
||||
$FutureModifier<List<FeedArticle>>,
|
||||
$StreamProvider<List<FeedArticle>> {
|
||||
FeedArticleListProvider._({
|
||||
required FeedArticleListFamily super.from,
|
||||
required Uri? super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'feedArticleListProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$feedArticleListHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'feedArticleListProvider'
|
||||
''
|
||||
'($argument)';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$StreamProviderElement<List<FeedArticle>> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $StreamProviderElement(pointer);
|
||||
|
||||
@override
|
||||
Stream<List<FeedArticle>> create(Ref ref) {
|
||||
final argument = this.argument as Uri?;
|
||||
return feedArticleList(ref, argument);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is FeedArticleListProvider && other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return argument.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
String _$feedArticleListHash() => r'45d585cc9f59ad48a0d1d6fbcf802b1c7de7f6bc';
|
||||
|
||||
final class FeedArticleListFamily extends $Family
|
||||
with $FunctionalFamilyOverride<Stream<List<FeedArticle>>, Uri?> {
|
||||
FeedArticleListFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'feedArticleListProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: true,
|
||||
);
|
||||
|
||||
FeedArticleListProvider call(Uri? feedId) =>
|
||||
FeedArticleListProvider._(argument: feedId, from: this);
|
||||
|
||||
@override
|
||||
String toString() => r'feedArticleListProvider';
|
||||
}
|
||||
|
||||
@ProviderFor(FilteredArticleList)
|
||||
final filteredArticleListProvider = FilteredArticleListFamily._();
|
||||
|
||||
final class FilteredArticleListProvider
|
||||
extends
|
||||
$NotifierProvider<FilteredArticleList, AsyncValue<List<FeedArticle>>> {
|
||||
FilteredArticleListProvider._({
|
||||
required FilteredArticleListFamily super.from,
|
||||
required Uri? super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'filteredArticleListProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$filteredArticleListHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'filteredArticleListProvider'
|
||||
''
|
||||
'($argument)';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
FilteredArticleList create() => FilteredArticleList();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(AsyncValue<List<FeedArticle>> value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<AsyncValue<List<FeedArticle>>>(
|
||||
value,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is FilteredArticleListProvider && other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return argument.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
String _$filteredArticleListHash() =>
|
||||
r'a691c3c6aa722dd85ee4980e6c48721a8025f1d8';
|
||||
|
||||
final class FilteredArticleListFamily extends $Family
|
||||
with
|
||||
$ClassFamilyOverride<
|
||||
FilteredArticleList,
|
||||
AsyncValue<List<FeedArticle>>,
|
||||
AsyncValue<List<FeedArticle>>,
|
||||
AsyncValue<List<FeedArticle>>,
|
||||
Uri?
|
||||
> {
|
||||
FilteredArticleListFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'filteredArticleListProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: true,
|
||||
);
|
||||
|
||||
FilteredArticleListProvider call(Uri? feedId) =>
|
||||
FilteredArticleListProvider._(argument: feedId, from: this);
|
||||
|
||||
@override
|
||||
String toString() => r'filteredArticleListProvider';
|
||||
}
|
||||
|
||||
abstract class _$FilteredArticleList
|
||||
extends $Notifier<AsyncValue<List<FeedArticle>>> {
|
||||
late final _$args = ref.$arg as Uri?;
|
||||
Uri? get feedId => _$args;
|
||||
|
||||
AsyncValue<List<FeedArticle>> build(Uri? feedId);
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref =
|
||||
this.ref
|
||||
as $Ref<
|
||||
AsyncValue<List<FeedArticle>>,
|
||||
AsyncValue<List<FeedArticle>>
|
||||
>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<
|
||||
AsyncValue<List<FeedArticle>>,
|
||||
AsyncValue<List<FeedArticle>>
|
||||
>,
|
||||
AsyncValue<List<FeedArticle>>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, () => build(_$args));
|
||||
}
|
||||
}
|
||||
|
||||
@ProviderFor(feedArticle)
|
||||
final feedArticleProvider = FeedArticleFamily._();
|
||||
|
||||
final class FeedArticleProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<FeedArticle?>,
|
||||
FeedArticle?,
|
||||
Stream<FeedArticle?>
|
||||
>
|
||||
with $FutureModifier<FeedArticle?>, $StreamProvider<FeedArticle?> {
|
||||
FeedArticleProvider._({
|
||||
required FeedArticleFamily super.from,
|
||||
required (String, {bool updateReadDate}) super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'feedArticleProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$feedArticleHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'feedArticleProvider'
|
||||
''
|
||||
'$argument';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$StreamProviderElement<FeedArticle?> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $StreamProviderElement(pointer);
|
||||
|
||||
@override
|
||||
Stream<FeedArticle?> create(Ref ref) {
|
||||
final argument = this.argument as (String, {bool updateReadDate});
|
||||
return feedArticle(
|
||||
ref,
|
||||
argument.$1,
|
||||
updateReadDate: argument.updateReadDate,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is FeedArticleProvider && other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return argument.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
String _$feedArticleHash() => r'18b5faf391867b95f4b3bc4f74a6083854b633a5';
|
||||
|
||||
final class FeedArticleFamily extends $Family
|
||||
with
|
||||
$FunctionalFamilyOverride<
|
||||
Stream<FeedArticle?>,
|
||||
(String, {bool updateReadDate})
|
||||
> {
|
||||
FeedArticleFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'feedArticleProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: true,
|
||||
);
|
||||
|
||||
FeedArticleProvider call(String articleId, {required bool updateReadDate}) =>
|
||||
FeedArticleProvider._(
|
||||
argument: (articleId, updateReadDate: updateReadDate),
|
||||
from: this,
|
||||
);
|
||||
|
||||
@override
|
||||
String toString() => r'feedArticleProvider';
|
||||
}
|
||||
|
||||
@ProviderFor(unreadArticleCount)
|
||||
final unreadArticleCountProvider = UnreadArticleCountProvider._();
|
||||
|
||||
final class UnreadArticleCountProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
Raw<Stream<Map<String, int>>>,
|
||||
Raw<Stream<Map<String, int>>>,
|
||||
Raw<Stream<Map<String, int>>>
|
||||
>
|
||||
with $Provider<Raw<Stream<Map<String, int>>>> {
|
||||
UnreadArticleCountProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'unreadArticleCountProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$unreadArticleCountHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<Raw<Stream<Map<String, int>>>> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
Raw<Stream<Map<String, int>>> create(Ref ref) {
|
||||
return unreadArticleCount(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(Raw<Stream<Map<String, int>>> value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<Raw<Stream<Map<String, int>>>>(
|
||||
value,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$unreadArticleCountHash() =>
|
||||
r'709518ad229636df0f1095f47e3a6d116b3aa7e6';
|
||||
|
||||
@ProviderFor(unreadFeedArticleCount)
|
||||
final unreadFeedArticleCountProvider = UnreadFeedArticleCountFamily._();
|
||||
|
||||
final class UnreadFeedArticleCountProvider
|
||||
extends $FunctionalProvider<AsyncValue<int?>, int?, Stream<int?>>
|
||||
with $FutureModifier<int?>, $StreamProvider<int?> {
|
||||
UnreadFeedArticleCountProvider._({
|
||||
required UnreadFeedArticleCountFamily super.from,
|
||||
required Uri super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'unreadFeedArticleCountProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$unreadFeedArticleCountHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'unreadFeedArticleCountProvider'
|
||||
''
|
||||
'($argument)';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$StreamProviderElement<int?> $createElement($ProviderPointer pointer) =>
|
||||
$StreamProviderElement(pointer);
|
||||
|
||||
@override
|
||||
Stream<int?> create(Ref ref) {
|
||||
final argument = this.argument as Uri;
|
||||
return unreadFeedArticleCount(ref, argument);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is UnreadFeedArticleCountProvider &&
|
||||
other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return argument.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
String _$unreadFeedArticleCountHash() =>
|
||||
r'5e0d8e58b3d1dec978dc07b22367f2cb037b1b15';
|
||||
|
||||
final class UnreadFeedArticleCountFamily extends $Family
|
||||
with $FunctionalFamilyOverride<Stream<int?>, Uri> {
|
||||
UnreadFeedArticleCountFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'unreadFeedArticleCountProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: true,
|
||||
);
|
||||
|
||||
UnreadFeedArticleCountProvider call(Uri feedId) =>
|
||||
UnreadFeedArticleCountProvider._(argument: feedId, from: this);
|
||||
|
||||
@override
|
||||
String toString() => r'unreadFeedArticleCountProvider';
|
||||
}
|
||||
|
||||
@ProviderFor(fetchWebFeed)
|
||||
final fetchWebFeedProvider = FetchWebFeedFamily._();
|
||||
|
||||
final class FetchWebFeedProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<FeedParseResult>,
|
||||
FeedParseResult,
|
||||
FutureOr<FeedParseResult>
|
||||
>
|
||||
with $FutureModifier<FeedParseResult>, $FutureProvider<FeedParseResult> {
|
||||
FetchWebFeedProvider._({
|
||||
required FetchWebFeedFamily super.from,
|
||||
required Uri super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'fetchWebFeedProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$fetchWebFeedHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'fetchWebFeedProvider'
|
||||
''
|
||||
'($argument)';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<FeedParseResult> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<FeedParseResult> create(Ref ref) {
|
||||
final argument = this.argument as Uri;
|
||||
return fetchWebFeed(ref, argument);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is FetchWebFeedProvider && other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return argument.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
String _$fetchWebFeedHash() => r'73bdf87ad7dbd039c7dc181d80acdf99d96fe1c6';
|
||||
|
||||
final class FetchWebFeedFamily extends $Family
|
||||
with $FunctionalFamilyOverride<FutureOr<FeedParseResult>, Uri> {
|
||||
FetchWebFeedFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'fetchWebFeedProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: true,
|
||||
);
|
||||
|
||||
FetchWebFeedProvider call(Uri url) =>
|
||||
FetchWebFeedProvider._(argument: url, from: this);
|
||||
|
||||
@override
|
||||
String toString() => r'fetchWebFeedProvider';
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/core/logger.dart';
|
||||
|
||||
part 'add_dialog_blocking.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class AddFeedDialogBlocking extends _$AddFeedDialogBlocking {
|
||||
DateTime? _lastIgnore;
|
||||
final _ignoredUrls = <Uri, DateTime>{};
|
||||
|
||||
void ignore(Uri url) {
|
||||
final date = DateTime.now();
|
||||
|
||||
_lastIgnore = date;
|
||||
_ignoredUrls[url] = date;
|
||||
}
|
||||
|
||||
bool canPush(Uri url) {
|
||||
if (_lastIgnore.mapNotNull(
|
||||
(last) =>
|
||||
DateTime.now().difference(last) <= const Duration(seconds: 30),
|
||||
) ??
|
||||
false) {
|
||||
logger.i('Blocking add feed default timeout for $url');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_ignoredUrls[url].mapNotNull(
|
||||
(last) =>
|
||||
DateTime.now().difference(last) <= const Duration(minutes: 5),
|
||||
) ??
|
||||
false) {
|
||||
logger.i('Blocking add feed url specific for $url');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
void build() {}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'add_dialog_blocking.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(AddFeedDialogBlocking)
|
||||
final addFeedDialogBlockingProvider = AddFeedDialogBlockingProvider._();
|
||||
|
||||
final class AddFeedDialogBlockingProvider
|
||||
extends $NotifierProvider<AddFeedDialogBlocking, void> {
|
||||
AddFeedDialogBlockingProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'addFeedDialogBlockingProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$addFeedDialogBlockingHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
AddFeedDialogBlocking create() => AddFeedDialogBlocking();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(void value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<void>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$addFeedDialogBlockingHash() =>
|
||||
r'513071d5e507dd292df6b4a3ee3ef7d2217db5bb';
|
||||
|
||||
abstract class _$AddFeedDialogBlocking extends $Notifier<void> {
|
||||
void build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<void, void>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<void, void>,
|
||||
void,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'article_filter.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class ArticleFilter extends _$ArticleFilter {
|
||||
void addTag(String tagId) {
|
||||
state = {...state, tagId};
|
||||
}
|
||||
|
||||
void removeTag(String tagId) {
|
||||
if (state.isNotEmpty) {
|
||||
state = {...state}..remove(tagId);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Set<String> build() {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'article_filter.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(ArticleFilter)
|
||||
final articleFilterProvider = ArticleFilterProvider._();
|
||||
|
||||
final class ArticleFilterProvider
|
||||
extends $NotifierProvider<ArticleFilter, Set<String>> {
|
||||
ArticleFilterProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'articleFilterProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$articleFilterHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
ArticleFilter create() => ArticleFilter();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(Set<String> value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<Set<String>>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$articleFilterHash() => r'61e4d5230e214038e753bc173158ed1d4dc57040';
|
||||
|
||||
abstract class _$ArticleFilter extends $Notifier<Set<String>> {
|
||||
Set<String> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<Set<String>, Set<String>>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<Set<String>, Set<String>>,
|
||||
Set<String>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
|
||||
import 'package:weblibre/features/web_feed/data/providers.dart';
|
||||
|
||||
part 'feed_repository.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class FeedRepository extends _$FeedRepository {
|
||||
Future<List<FeedData>> getAllFeeds() {
|
||||
return ref.read(feedDatabaseProvider).feedDao.getFeeds().get();
|
||||
}
|
||||
|
||||
Future<void> touchFeedFetched(Uri feedId) {
|
||||
return ref
|
||||
.read(feedDatabaseProvider)
|
||||
.feedDao
|
||||
.updateFeedFetched(feedId, DateTime.now());
|
||||
}
|
||||
|
||||
Future<void> upsertFeed(FeedData feedData) {
|
||||
return ref.read(feedDatabaseProvider).feedDao.upsertFeed(feedData);
|
||||
}
|
||||
|
||||
Future<void> upsertArticles(List<FeedArticle> articles) {
|
||||
return ref.read(feedDatabaseProvider).articleDao.upsertArticles(articles);
|
||||
}
|
||||
|
||||
Future<int> deleteFeed(Uri feedId) {
|
||||
return ref.read(feedDatabaseProvider).feedDao.deleteFeed(feedId);
|
||||
}
|
||||
|
||||
Future<void> touchArticleRead(String articleId) {
|
||||
return ref
|
||||
.read(feedDatabaseProvider)
|
||||
.articleDao
|
||||
.updateArticleRead(articleId, DateTime.now());
|
||||
}
|
||||
|
||||
Future<void> unsetArticleRead(String articleId) {
|
||||
return ref
|
||||
.read(feedDatabaseProvider)
|
||||
.articleDao
|
||||
.updateArticleRead(articleId, null);
|
||||
}
|
||||
|
||||
Stream<List<FeedData>> watchFeeds() {
|
||||
return ref.read(feedDatabaseProvider).feedDao.getFeeds().watch();
|
||||
}
|
||||
|
||||
Stream<FeedData?> watchFeed(Uri feedId) {
|
||||
return ref
|
||||
.read(feedDatabaseProvider)
|
||||
.feedDao
|
||||
.getFeed(feedId)
|
||||
.watchSingleOrNull();
|
||||
}
|
||||
|
||||
Stream<List<FeedArticle>> watchFeedArticles(Uri? feedId) {
|
||||
return ref
|
||||
.read(feedDatabaseProvider)
|
||||
.articleDao
|
||||
.getFeedArticles(feedId)
|
||||
.watch();
|
||||
}
|
||||
|
||||
Stream<FeedArticle?> watchArticle(String articleId) {
|
||||
return ref
|
||||
.read(feedDatabaseProvider)
|
||||
.articleDao
|
||||
.getArticleById(articleId)
|
||||
.watchSingleOrNull();
|
||||
}
|
||||
|
||||
Stream<Map<String, int>> watchUnreadFeedArticleCount() {
|
||||
return ref
|
||||
.read(feedDatabaseProvider)
|
||||
.articleDao
|
||||
.getUnreadArticleCount()
|
||||
.watch()
|
||||
.map(
|
||||
(results) =>
|
||||
Map.fromEntries(results.map((e) => MapEntry(e.$1, e.$2))),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void build() {}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_repository.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(FeedRepository)
|
||||
final feedRepositoryProvider = FeedRepositoryProvider._();
|
||||
|
||||
final class FeedRepositoryProvider
|
||||
extends $NotifierProvider<FeedRepository, void> {
|
||||
FeedRepositoryProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'feedRepositoryProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$feedRepositoryHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
FeedRepository create() => FeedRepository();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(void value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<void>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$feedRepositoryHash() => r'805cc26890b0d43576a1eab0ecb5851b6649d7b7';
|
||||
|
||||
abstract class _$FeedRepository extends $Notifier<void> {
|
||||
void build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<void, void>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<void, void>,
|
||||
void,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/core/logger.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
|
||||
import 'package:weblibre/features/web_feed/data/providers.dart';
|
||||
|
||||
part 'article_content_processor.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class ArticleContentProcessorService extends _$ArticleContentProcessorService {
|
||||
@override
|
||||
void build() {
|
||||
final db = ref.watch(feedDatabaseProvider);
|
||||
|
||||
final processSub = db.articleDao.getUnprocessedArticles().watch().listen((
|
||||
articles,
|
||||
) async {
|
||||
try {
|
||||
final content = await GeckoBrowserExtensionService.turndownHtml(
|
||||
articles.map((article) => article.contentHtml ?? '').toList(),
|
||||
);
|
||||
final summary = await GeckoBrowserExtensionService.turndownHtml(
|
||||
articles.map((article) => article.summaryHtml ?? '').toList(),
|
||||
);
|
||||
|
||||
await db.articleDao.updateArticleContent(
|
||||
articles
|
||||
.mapIndexed(
|
||||
(index, article) => article.copyWith(
|
||||
contentMarkdown: content[index].markdown ?? '',
|
||||
contentPlain: content[index].plain,
|
||||
summaryMarkdown: summary[index].markdown ?? '',
|
||||
summaryPlain: summary[index].plain,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
|
||||
logger.i('Processed ${articles.length} articles');
|
||||
} catch (e, s) {
|
||||
logger.e('Error processing articles', error: e, stackTrace: s);
|
||||
}
|
||||
});
|
||||
|
||||
ref.onDispose(() async {
|
||||
await processSub.cancel();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'article_content_processor.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(ArticleContentProcessorService)
|
||||
final articleContentProcessorServiceProvider =
|
||||
ArticleContentProcessorServiceProvider._();
|
||||
|
||||
final class ArticleContentProcessorServiceProvider
|
||||
extends $NotifierProvider<ArticleContentProcessorService, void> {
|
||||
ArticleContentProcessorServiceProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'articleContentProcessorServiceProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$articleContentProcessorServiceHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
ArticleContentProcessorService create() => ArticleContentProcessorService();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(void value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<void>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$articleContentProcessorServiceHash() =>
|
||||
r'e7cc3da71f6dcf39b0c10df4dcd061f816d5c12e';
|
||||
|
||||
abstract class _$ArticleContentProcessorService extends $Notifier<void> {
|
||||
void build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<void, void>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<void, void>,
|
||||
void,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/extensions/http_encoding.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_parse_result.dart';
|
||||
import 'package:weblibre/features/web_feed/utils/feed_parser.dart';
|
||||
|
||||
part 'feed_reader.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class FeedReader extends _$FeedReader {
|
||||
Future<FeedParseResult> parseFeed(Uri url) async {
|
||||
final rootIsolateToken = ServicesBinding.rootIsolateToken!;
|
||||
|
||||
final result = await compute((args) async {
|
||||
// Initialize BackgroundIsolateBinaryMessenger with the token
|
||||
BackgroundIsolateBinaryMessenger.ensureInitialized(
|
||||
args['token']! as RootIsolateToken,
|
||||
);
|
||||
|
||||
final client = http.Client();
|
||||
try {
|
||||
final url = Uri.parse(args['url']! as String);
|
||||
final response = await client
|
||||
.get(url)
|
||||
.timeout(const Duration(seconds: 30));
|
||||
|
||||
final parser = FeedParser.parse(
|
||||
url: url,
|
||||
xmlString: response.bodyUnicodeFallback,
|
||||
);
|
||||
final result = FeedParseResult(
|
||||
feedData: parser.readGeneralData(),
|
||||
articleData: parser.readArticles(),
|
||||
);
|
||||
|
||||
return result.toJson();
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}, {'token': rootIsolateToken, 'url': url.toString()});
|
||||
|
||||
return FeedParseResult.fromJson(result);
|
||||
}
|
||||
|
||||
@override
|
||||
void build() {}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'feed_reader.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(FeedReader)
|
||||
final feedReaderProvider = FeedReaderProvider._();
|
||||
|
||||
final class FeedReaderProvider extends $NotifierProvider<FeedReader, void> {
|
||||
FeedReaderProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'feedReaderProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$feedReaderHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
FeedReader create() => FeedReader();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(void value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<void>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$feedReaderHash() => r'5d1ca364fe7ad702628a7f2bbd3e706876bc3111';
|
||||
|
||||
abstract class _$FeedReader extends $Notifier<void> {
|
||||
void build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<void, void>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<void, void>,
|
||||
void,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:rss_dart/dart_rss.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_author.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_category.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_link.dart';
|
||||
|
||||
extension ParseAtomLink on List<AtomLink> {
|
||||
List<FeedLink> toFeedLinks() {
|
||||
return map((link) {
|
||||
final uri = link.href.mapNotNull(Uri.tryParse);
|
||||
if (uri == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final relation = link.rel.mapNotNull(
|
||||
(rel) => FeedLinkRelation.values.firstWhereOrNull((e) => e.name == rel),
|
||||
);
|
||||
|
||||
return FeedLink(
|
||||
uri: uri,
|
||||
relation: relation,
|
||||
title: link.title.whenNotEmpty,
|
||||
);
|
||||
}).nonNulls.toList();
|
||||
}
|
||||
}
|
||||
|
||||
extension SelectFeedLink on List<FeedLink> {
|
||||
FeedLink? getRelation(FeedLinkRelation? relation) {
|
||||
return firstWhereOrNull((link) => link.relation == relation);
|
||||
}
|
||||
}
|
||||
|
||||
extension ParseAtomCategory on List<AtomCategory> {
|
||||
List<FeedCategory> toFeedCategories() {
|
||||
return where((category) => category.term.isNotEmpty)
|
||||
.map(
|
||||
(category) => FeedCategory(
|
||||
id: category.term!,
|
||||
title: category.label.whenNotEmpty,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
extension ParseAtomPerson on List<AtomPerson> {
|
||||
List<FeedAuthor> toFeedAuthors() {
|
||||
return where(
|
||||
(author) =>
|
||||
author.name.whenNotEmpty != null ||
|
||||
author.email.whenNotEmpty != null,
|
||||
)
|
||||
.map(
|
||||
(author) => FeedAuthor(
|
||||
name: author.name.whenNotEmpty,
|
||||
email: author.email.whenNotEmpty,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_link.dart';
|
||||
import 'package:weblibre/features/web_feed/extensions/atom.dart';
|
||||
|
||||
extension FeedArticleX on FeedArticle {
|
||||
String get displayTitle =>
|
||||
title ??
|
||||
links
|
||||
?.getRelation(FeedLinkRelation.alternate)
|
||||
.mapNotNull(
|
||||
(link) => link.title.whenNotEmpty ?? link.uri.toString(),
|
||||
) ??
|
||||
'Unnamed Article';
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:rss_dart/dart_rss.dart';
|
||||
import 'package:rss_dart/domain/dublin_core/dublin_core.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_category.dart';
|
||||
|
||||
extension ParseDublinCategory on DublinCore {
|
||||
List<FeedCategory> toFeedCategories() {
|
||||
return subjects
|
||||
.where((subject) => subject.isNotEmpty)
|
||||
.map((subject) => FeedCategory(id: subject))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
extension ParseRssCategory on List<RssCategory> {
|
||||
List<FeedCategory> toFeedCategories() {
|
||||
return where((category) => category.value.isNotEmpty)
|
||||
.map(
|
||||
(category) => FeedCategory(
|
||||
id: '${category.domain ?? ''} ${category.value ?? ''}'.trim(),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:rss_dart/dart_rss.dart';
|
||||
|
||||
extension WebFeedJson on WebFeed {
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'title': title,
|
||||
'description': description,
|
||||
'links': links.where((link) => link != null).toList(),
|
||||
'items': items.map((item) => item.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
static WebFeed fromJson(Map<String, dynamic> json) {
|
||||
return WebFeed(
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String,
|
||||
links: (json['links'] as List).cast<String?>(),
|
||||
items: (json['items'] as List)
|
||||
.map((item) => WebFeedItemJson.fromJson(item as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension WebFeedItemJson on WebFeedItem {
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'title': title,
|
||||
'body': body,
|
||||
'links': links.where((link) => link != null).toList(),
|
||||
'updated': updated?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
static WebFeedItem fromJson(Map<String, dynamic> json) {
|
||||
return WebFeedItem(
|
||||
title: json['title'] as String,
|
||||
body: json['body'] as String,
|
||||
links: (json['links'] as List).cast<String?>(),
|
||||
updated: json['updated'] != null
|
||||
? DateTime.parse(json['updated'] as String)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:weblibre/core/routing/routes.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/providers/add_dialog_blocking.dart';
|
||||
import 'package:weblibre/utils/form_validators.dart';
|
||||
|
||||
class AddFeedDialog extends HookConsumerWidget {
|
||||
final Uri? initialUri;
|
||||
|
||||
const AddFeedDialog({super.key, required this.initialUri});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final formKey = useMemoized(() => GlobalKey<FormState>());
|
||||
|
||||
final textController = useTextEditingController(
|
||||
text: initialUri?.toString(),
|
||||
);
|
||||
|
||||
return AlertDialog(
|
||||
title: const Text('Add Feed'),
|
||||
// contentPadding: const EdgeInsets.fromLTRB(24.0, 12.0, 24.0, 16.0),
|
||||
content: Form(
|
||||
key: formKey,
|
||||
child: TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
label: Text('URL'),
|
||||
hintText: 'https://example.com/feed',
|
||||
floatingLabelBehavior: FloatingLabelBehavior.always,
|
||||
),
|
||||
controller: textController,
|
||||
keyboardType: TextInputType.url,
|
||||
minLines: 1,
|
||||
maxLines: 10,
|
||||
validator: (value) {
|
||||
return validateUrl(
|
||||
value,
|
||||
onlyHttpProtocol: true,
|
||||
eagerParsing: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
if (initialUri != null)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
ref
|
||||
.read(addFeedDialogBlockingProvider.notifier)
|
||||
.ignore(initialUri!);
|
||||
context.pop();
|
||||
},
|
||||
child: const Text('Ignore'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (formKey.currentState?.validate() == true) {
|
||||
final feedId = parseValidatedUrl(
|
||||
textController.text,
|
||||
eagerParsing: false,
|
||||
onlyHttpProtocol: true,
|
||||
);
|
||||
if (feedId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
FeedCreateRoute(feedId: feedId).pushReplacement(context);
|
||||
}
|
||||
},
|
||||
child: const Text('Add'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/core/logger.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/repositories/feed_repository.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/services/feed_reader.dart';
|
||||
|
||||
part 'fetch_articles.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class FetchArticlesController extends _$FetchArticlesController {
|
||||
Future<void> fetchAllArticles() async {
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(() async {
|
||||
final feedRepository = ref.read(feedRepositoryProvider.notifier);
|
||||
|
||||
final feeds = await feedRepository.getAllFeeds();
|
||||
|
||||
await Future.wait(
|
||||
feeds.map((feed) async {
|
||||
try {
|
||||
final feedReader = ref.read(feedReaderProvider.notifier);
|
||||
|
||||
final result = await feedReader.parseFeed(feed.url);
|
||||
|
||||
await feedRepository.upsertArticles(result.articleData);
|
||||
await feedRepository.touchFeedFetched(feed.url);
|
||||
} catch (e, s) {
|
||||
logger.e(
|
||||
'Failed fetching feed ${feed.url}',
|
||||
error: e,
|
||||
stackTrace: s,
|
||||
);
|
||||
}
|
||||
}).toList(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> fetchFeedArticles(Uri uri) async {
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(() async {
|
||||
final feedRepository = ref.read(feedRepositoryProvider.notifier);
|
||||
|
||||
final result = await ref.read(feedReaderProvider.notifier).parseFeed(uri);
|
||||
|
||||
await feedRepository.upsertArticles(result.articleData);
|
||||
await feedRepository.touchFeedFetched(uri);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
AsyncValue<void> build() {
|
||||
return const AsyncData(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'fetch_articles.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(FetchArticlesController)
|
||||
final fetchArticlesControllerProvider = FetchArticlesControllerProvider._();
|
||||
|
||||
final class FetchArticlesControllerProvider
|
||||
extends $NotifierProvider<FetchArticlesController, AsyncValue<void>> {
|
||||
FetchArticlesControllerProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'fetchArticlesControllerProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$fetchArticlesControllerHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
FetchArticlesController create() => FetchArticlesController();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(AsyncValue<void> value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<AsyncValue<void>>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$fetchArticlesControllerHash() =>
|
||||
r'5dcb9de003bc911d365c6a8ef107bf1bf446755b';
|
||||
|
||||
abstract class _$FetchArticlesController extends $Notifier<AsyncValue<void>> {
|
||||
AsyncValue<void> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<AsyncValue<void>, AsyncValue<void>>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<void>, AsyncValue<void>>,
|
||||
AsyncValue<void>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Future<bool?> showDeleteFeedDialog(BuildContext context) {
|
||||
return showDialog<bool?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(Icons.warning),
|
||||
title: const Text('Delete Feed'),
|
||||
content: const Text(
|
||||
'Are you sure you want to delete this feed and delete all related articles?',
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
child: const Text('Delete'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:weblibre/core/providers/format.dart';
|
||||
import 'package:weblibre/core/routing/routes.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/entities/tab_container_selection.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/entities/tab_mode.dart';
|
||||
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_link.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/providers.dart';
|
||||
import 'package:weblibre/features/web_feed/extensions/atom.dart';
|
||||
import 'package:weblibre/features/web_feed/extensions/feed_article.dart';
|
||||
import 'package:weblibre/features/web_feed/presentation/widgets/authors_horizontal_list.dart';
|
||||
import 'package:weblibre/features/web_feed/presentation/widgets/tags_horizontal_list.dart';
|
||||
import 'package:weblibre/presentation/widgets/failure_widget.dart';
|
||||
import 'package:weblibre/utils/markdown/image_extractor.dart';
|
||||
import 'package:weblibre/utils/ui_helper.dart';
|
||||
|
||||
enum _Pages { summary, content }
|
||||
|
||||
class FeedArticleScreen extends HookConsumerWidget {
|
||||
final String articleId;
|
||||
|
||||
const FeedArticleScreen({super.key, required this.articleId});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final articleAsync = ref.watch(
|
||||
feedArticleProvider(articleId, updateReadDate: true),
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
body: articleAsync.when(
|
||||
skipLoadingOnReload: true,
|
||||
data: (article) {
|
||||
if (article == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return HookBuilder(
|
||||
builder: (context) {
|
||||
final hasArticleCreated = article.created != null;
|
||||
final hasArticleUpdated =
|
||||
article.updated != null && article.updated != article.created;
|
||||
final hasAuthors = article.authors.isNotEmpty;
|
||||
final hasTags = article.tags.isNotEmpty;
|
||||
|
||||
final tabs = useMemoized(
|
||||
() => [
|
||||
if (article.summaryMarkdown.isNotEmpty) _Pages.summary,
|
||||
if (article.contentMarkdown.isNotEmpty) _Pages.content,
|
||||
],
|
||||
[article],
|
||||
);
|
||||
|
||||
final tabController = useTabController(
|
||||
initialLength: tabs.length,
|
||||
);
|
||||
|
||||
final articleLink = useMemoized(
|
||||
() =>
|
||||
article.links?.getRelation(FeedLinkRelation.alternate) ??
|
||||
article.links?.getRelation(null),
|
||||
[article],
|
||||
);
|
||||
|
||||
final articleImages = useMemoized(
|
||||
() => (article.contentMarkdown ?? article.summaryMarkdown)
|
||||
.mapNotNull(extractImagesFromMarkdown),
|
||||
[article],
|
||||
);
|
||||
|
||||
final bottomHeight = useMemoized(() {
|
||||
var height = 0.0;
|
||||
|
||||
if (hasArticleCreated) {
|
||||
height += 20;
|
||||
}
|
||||
if (hasArticleUpdated) {
|
||||
height += 20;
|
||||
}
|
||||
if (hasAuthors) {
|
||||
height += 56;
|
||||
}
|
||||
if (hasTags) {
|
||||
height += 56;
|
||||
}
|
||||
|
||||
return height;
|
||||
}, [article]);
|
||||
|
||||
return NestedScrollView(
|
||||
headerSliverBuilder: (context, innerBoxIsScrolled) => [
|
||||
SliverAppBar.large(
|
||||
pinned: false,
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
centerTitle: false,
|
||||
titlePadding: EdgeInsetsDirectional.only(
|
||||
start: 72,
|
||||
end: 72,
|
||||
bottom: bottomHeight + 16,
|
||||
),
|
||||
title: Text(
|
||||
article.displayTitle,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
background: articleImages?.firstOrNull.mapNotNull(
|
||||
(img) => Image.network(
|
||||
img.toString(),
|
||||
fit: BoxFit.cover,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surface.withAlpha(200),
|
||||
colorBlendMode: BlendMode.darken,
|
||||
),
|
||||
),
|
||||
),
|
||||
bottom: PreferredSize(
|
||||
preferredSize: Size(double.infinity, bottomHeight),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Divider(),
|
||||
Text(
|
||||
'Published: ${hasArticleCreated ? ref.read(formatProvider.notifier).fullDateTime(article.created!) : 'N/A'}',
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(fontStyle: FontStyle.italic),
|
||||
),
|
||||
if (hasArticleUpdated)
|
||||
Text(
|
||||
'Updated: ${ref.read(formatProvider.notifier).fullDateTime(article.updated!)}',
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(fontStyle: FontStyle.italic),
|
||||
),
|
||||
if (hasAuthors)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
const Text('Authors:'),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: AuthorsHorizontalList(
|
||||
authors: article.authors!,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (hasTags)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
const Text('Tags:'),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: TagsHorizontalList(
|
||||
tags: article.tags!,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
if (articleLink != null)
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
final tabMode = TabMode.fromTabType(
|
||||
ref
|
||||
.read(generalSettingsWithDefaultsProvider)
|
||||
.effectiveDefaultCreateTabType,
|
||||
);
|
||||
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.addTab(
|
||||
url: articleLink.uri,
|
||||
tabMode: tabMode,
|
||||
containerSelection:
|
||||
const TabContainerSelection.unassigned(),
|
||||
selectTab: true,
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
const BrowserRoute().go(context);
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.open_in_browser),
|
||||
),
|
||||
],
|
||||
),
|
||||
// SliverToBoxAdapter(
|
||||
// child: Padding(
|
||||
// padding: const EdgeInsets.all(8.0),
|
||||
// child: TabBar(
|
||||
// controller: tabController,
|
||||
// tabs: [
|
||||
// ...tabs.map(
|
||||
// (tab) => switch (tab) {
|
||||
// _Pages.summary => const Tab(text: 'Summary'),
|
||||
// _Pages.content => const Tab(text: 'Article'),
|
||||
// },
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
body: TabBarView(
|
||||
controller: tabController,
|
||||
children: [
|
||||
...tabs.map(
|
||||
(tab) => Markdown(
|
||||
selectable: true,
|
||||
onTapLink: (text, href, title) async {
|
||||
if (href.mapNotNull(Uri.tryParse)
|
||||
case final Uri url) {
|
||||
final tabMode = TabMode.fromTabType(
|
||||
ref
|
||||
.read(generalSettingsWithDefaultsProvider)
|
||||
.effectiveDefaultCreateTabType,
|
||||
);
|
||||
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.addTab(
|
||||
url: url,
|
||||
tabMode: tabMode,
|
||||
selectTab: true,
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
showTabOpenedMessage(
|
||||
context,
|
||||
tabName: title.whenNotEmpty,
|
||||
onShow: () {
|
||||
const BrowserRoute().go(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
styleSheet:
|
||||
MarkdownStyleSheet.fromTheme(
|
||||
Theme.of(context),
|
||||
).copyWith(
|
||||
blockquoteDecoration: BoxDecoration(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.secondaryContainer,
|
||||
borderRadius: BorderRadius.circular(2.0),
|
||||
),
|
||||
),
|
||||
data: switch (tab) {
|
||||
_Pages.summary => article.summaryMarkdown!,
|
||||
_Pages.content => article.contentMarkdown!,
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
error: (error, stackTrace) => Center(
|
||||
child: FailureWidget(
|
||||
title: 'Failed reading article',
|
||||
exception: error,
|
||||
),
|
||||
),
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:fading_scroll/fading_scroll.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/providers.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/providers/article_filter.dart';
|
||||
import 'package:weblibre/features/web_feed/presentation/controllers/fetch_articles.dart';
|
||||
import 'package:weblibre/features/web_feed/presentation/widgets/feed_article_card.dart';
|
||||
import 'package:weblibre/presentation/widgets/failure_widget.dart';
|
||||
import 'package:weblibre/presentation/widgets/speech_to_text_button.dart';
|
||||
|
||||
class FeedArticleListScreen extends HookConsumerWidget {
|
||||
final Uri? feedId;
|
||||
|
||||
const FeedArticleListScreen({super.key, required this.feedId});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final tags = ref.watch(articleFilterProvider);
|
||||
final articlesAsync = ref.watch(
|
||||
// ignore: provider_parameters
|
||||
filteredArticleListProvider(feedId),
|
||||
);
|
||||
|
||||
final feedTitle = ref.watch(
|
||||
feedDataProvider(
|
||||
feedId,
|
||||
).select((value) => value.value?.title.whenNotEmpty),
|
||||
);
|
||||
|
||||
final focusNode = useFocusNode();
|
||||
final searchTextController = useTextEditingController();
|
||||
|
||||
final hasText = useListenableSelector(
|
||||
searchTextController,
|
||||
() => searchTextController.text.isNotEmpty,
|
||||
);
|
||||
|
||||
useOnListenableChange(searchTextController, () {
|
||||
ref
|
||||
.read(filteredArticleListProvider(feedId).notifier)
|
||||
.search(searchTextController.text);
|
||||
});
|
||||
|
||||
final bottomHeight = useMemoized(() {
|
||||
var height = 56.0 + 4.0;
|
||||
|
||||
if (tags.isNotEmpty) {
|
||||
height += 48;
|
||||
}
|
||||
|
||||
return height;
|
||||
}, [tags.isNotEmpty]);
|
||||
|
||||
return Scaffold(
|
||||
body: NestedScrollView(
|
||||
floatHeaderSlivers: true,
|
||||
headerSliverBuilder: (context, innerBoxIsScrolled) {
|
||||
return [
|
||||
SliverAppBar(
|
||||
floating: true,
|
||||
title: Text(feedTitle ?? 'Articles'),
|
||||
bottom: PreferredSize(
|
||||
preferredSize: Size(double.infinity, bottomHeight),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(
|
||||
focusNode: focusNode,
|
||||
controller: searchTextController,
|
||||
decoration: InputDecoration(
|
||||
label: const Text('Search'),
|
||||
suffixIcon: hasText
|
||||
? IconButton(
|
||||
onPressed: () {
|
||||
searchTextController.clear();
|
||||
focusNode.requestFocus();
|
||||
},
|
||||
icon: const Icon(Icons.clear),
|
||||
)
|
||||
: SpeechToTextButton(
|
||||
onTextReceived: (data) {
|
||||
searchTextController.text = data;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
if (tags.isNotEmpty)
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
child: FadingScroll(
|
||||
fadingSize: 15,
|
||||
builder: (context, controller) {
|
||||
return ListView(
|
||||
controller: controller,
|
||||
shrinkWrap: true,
|
||||
scrollDirection: Axis.horizontal,
|
||||
children: tags
|
||||
.map(
|
||||
(tag) => Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
right: 8.0,
|
||||
),
|
||||
child: FilterChip(
|
||||
label: Text(tag),
|
||||
showCheckmark: false,
|
||||
selected: true,
|
||||
onSelected: (value) {},
|
||||
onDeleted: () {
|
||||
ref
|
||||
.read(
|
||||
articleFilterProvider
|
||||
.notifier,
|
||||
)
|
||||
.removeTag(tag);
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
];
|
||||
},
|
||||
body: articlesAsync.when(
|
||||
skipLoadingOnReload: true,
|
||||
data: (articles) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
if (feedId != null) {
|
||||
await ref
|
||||
.read(fetchArticlesControllerProvider.notifier)
|
||||
.fetchFeedArticles(feedId!);
|
||||
} else {
|
||||
await ref
|
||||
.read(fetchArticlesControllerProvider.notifier)
|
||||
.fetchAllArticles();
|
||||
}
|
||||
},
|
||||
child: MediaQuery.removePadding(
|
||||
removeTop: true,
|
||||
context: context,
|
||||
child: ListView.builder(
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: articles.length,
|
||||
itemBuilder: (context, i) {
|
||||
final article = articles[i];
|
||||
return FeedArticleCard(
|
||||
key: ValueKey(article.id),
|
||||
article: article,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
error: (error, stackTrace) => Center(
|
||||
child: FailureWidget(
|
||||
title: 'Failed to load Articles',
|
||||
exception: error,
|
||||
),
|
||||
),
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,328 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:fast_equatable/fast_equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:weblibre/extensions/uri.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_category.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/providers.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/repositories/feed_repository.dart';
|
||||
import 'package:weblibre/features/web_feed/presentation/dialogs/delete_feed_dialog.dart';
|
||||
import 'package:weblibre/features/web_feed/presentation/widgets/tag_field.dart';
|
||||
import 'package:weblibre/presentation/widgets/failure_widget.dart';
|
||||
import 'package:weblibre/presentation/widgets/url_icon.dart';
|
||||
import 'package:weblibre/utils/form_validators.dart';
|
||||
|
||||
enum _DialogMode { create, edit }
|
||||
|
||||
class FeedEditScreen extends HookConsumerWidget {
|
||||
final _DialogMode _mode;
|
||||
|
||||
final Uri feedId;
|
||||
|
||||
const FeedEditScreen._({required _DialogMode mode, required this.feedId})
|
||||
: _mode = mode;
|
||||
|
||||
factory FeedEditScreen.create({required Uri feedId}) {
|
||||
return FeedEditScreen._(mode: _DialogMode.create, feedId: feedId);
|
||||
}
|
||||
|
||||
factory FeedEditScreen.edit({required Uri feedId}) {
|
||||
return FeedEditScreen._(mode: _DialogMode.edit, feedId: feedId);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final initialFeedAsync = switch (_mode) {
|
||||
_DialogMode.create => ref.watch(
|
||||
fetchWebFeedProvider(
|
||||
feedId,
|
||||
).select((value) => value.whenData((result) => result.feedData)),
|
||||
),
|
||||
_DialogMode.edit => ref.watch(feedDataProvider(feedId)),
|
||||
};
|
||||
|
||||
return initialFeedAsync.when(
|
||||
skipLoadingOnReload: true,
|
||||
data: (initialFeed) {
|
||||
if (initialFeed == null) {
|
||||
return Scaffold(
|
||||
key: const ValueKey('data'),
|
||||
appBar: AppBar(),
|
||||
body: const Center(
|
||||
child: FailureWidget(title: 'Failed to load feed'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return _FeedEditContent(mode: _mode, initialFeed: initialFeed);
|
||||
},
|
||||
error: (error, stackTrace) => Scaffold(
|
||||
key: const ValueKey('error'),
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: FailureWidget(title: 'Failed to load feed', exception: error),
|
||||
),
|
||||
),
|
||||
loading: () => Scaffold(
|
||||
key: const ValueKey('loading'),
|
||||
appBar: AppBar(
|
||||
title: Text(switch (_mode) {
|
||||
_DialogMode.create => 'New Feed',
|
||||
_DialogMode.edit => 'Edit Feed',
|
||||
}),
|
||||
),
|
||||
body: const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 8.0),
|
||||
child: Text('Fetching feed...'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FeedEditContent extends HookConsumerWidget {
|
||||
final _DialogMode _mode;
|
||||
|
||||
final FeedData initialFeed;
|
||||
|
||||
const _FeedEditContent({required _DialogMode mode, required this.initialFeed})
|
||||
: _mode = mode;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final formKey = useMemoized(() => GlobalKey<FormState>());
|
||||
final initialTags = useMemoized(
|
||||
() => initialFeed.tags?.map((tag) => tag.id).toSet(),
|
||||
[EquatableValue(initialFeed.tags)],
|
||||
);
|
||||
final tags = useRef(initialTags ?? {});
|
||||
|
||||
final titleTextController = useTextEditingController(
|
||||
text: initialFeed.title ?? initialFeed.url.host,
|
||||
);
|
||||
final descriptionTextController = useTextEditingController(
|
||||
text: initialFeed.description,
|
||||
);
|
||||
final urlTextController = useTextEditingController(
|
||||
text: initialFeed.url.toString(),
|
||||
);
|
||||
final iconUrlTextController = useTextEditingController(
|
||||
text: initialFeed.icon?.toString(),
|
||||
);
|
||||
final siteLinkTextController = useTextEditingController(
|
||||
text: initialFeed.siteLink?.toString(),
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(switch (_mode) {
|
||||
_DialogMode.create => 'New Feed',
|
||||
_DialogMode.edit => 'Edit Feed',
|
||||
}),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
if (formKey.currentState?.validate() ?? false) {
|
||||
final feedData = FeedData(
|
||||
url: parseValidatedUrl(
|
||||
urlTextController.text,
|
||||
eagerParsing: false,
|
||||
onlyHttpProtocol: true,
|
||||
)!,
|
||||
authors: initialFeed.authors,
|
||||
description: descriptionTextController.text.whenNotEmpty,
|
||||
icon: parseValidatedUrl(
|
||||
iconUrlTextController.text,
|
||||
eagerParsing: false,
|
||||
onlyHttpProtocol: true,
|
||||
),
|
||||
siteLink: parseValidatedUrl(
|
||||
siteLinkTextController.text,
|
||||
eagerParsing: false,
|
||||
onlyHttpProtocol: true,
|
||||
),
|
||||
tags: tags.value.map((tag) => FeedCategory(id: tag)).toList(),
|
||||
title: titleTextController.text.whenNotEmpty,
|
||||
);
|
||||
|
||||
await ref
|
||||
.read(feedRepositoryProvider.notifier)
|
||||
.upsertFeed(feedData);
|
||||
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.check),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Form(
|
||||
key: formKey,
|
||||
child: ListView(
|
||||
children: [
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: UrlIcon([
|
||||
initialFeed.icon ??
|
||||
initialFeed.siteLink ??
|
||||
initialFeed.url.base,
|
||||
], iconSize: 24.0),
|
||||
),
|
||||
label: const Text('Title'),
|
||||
),
|
||||
controller: titleTextController,
|
||||
),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
label: Text('Description'),
|
||||
prefixIcon: Icon(Icons.short_text),
|
||||
),
|
||||
minLines: 1,
|
||||
maxLines: 3,
|
||||
controller: descriptionTextController,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
label: Text('Icon URL'),
|
||||
prefixIcon: Icon(Icons.image),
|
||||
),
|
||||
keyboardType: TextInputType.url,
|
||||
minLines: 1,
|
||||
maxLines: 10,
|
||||
controller: iconUrlTextController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
return validateUrl(
|
||||
value,
|
||||
onlyHttpProtocol: true,
|
||||
required: false,
|
||||
eagerParsing: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
label: Text('Site Link'),
|
||||
prefixIcon: Icon(Icons.link),
|
||||
),
|
||||
keyboardType: TextInputType.url,
|
||||
minLines: 1,
|
||||
maxLines: 10,
|
||||
controller: siteLinkTextController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
return validateUrl(
|
||||
value,
|
||||
onlyHttpProtocol: true,
|
||||
required: false,
|
||||
eagerParsing: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
TagField(
|
||||
initialTags: tags.value,
|
||||
onTagsUpdate: (newTags) {
|
||||
tags.value = newTags;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
label: Text('Feed URL'),
|
||||
prefixIcon: Icon(MdiIcons.rss),
|
||||
),
|
||||
keyboardType: TextInputType.url,
|
||||
minLines: 1,
|
||||
maxLines: 10,
|
||||
controller: urlTextController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
return validateUrl(
|
||||
value,
|
||||
onlyHttpProtocol: true,
|
||||
eagerParsing: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_mode == _DialogMode.edit)
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
style: OutlinedButton.styleFrom(
|
||||
side: BorderSide(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
foregroundColor: Theme.of(context).colorScheme.error,
|
||||
iconColor: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
label: const Text('Delete'),
|
||||
icon: const Icon(Icons.delete),
|
||||
onPressed: () async {
|
||||
final result = await showDeleteFeedDialog(context);
|
||||
|
||||
if (result == true) {
|
||||
await ref
|
||||
.read(feedRepositoryProvider.notifier)
|
||||
.deleteFeed(initialFeed.url);
|
||||
|
||||
if (context.mounted) {
|
||||
context.pop();
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:weblibre/core/routing/routes.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/providers.dart';
|
||||
import 'package:weblibre/features/web_feed/presentation/controllers/fetch_articles.dart';
|
||||
import 'package:weblibre/features/web_feed/presentation/widgets/feed_card.dart';
|
||||
import 'package:weblibre/presentation/widgets/failure_widget.dart';
|
||||
|
||||
class FeedListScreen extends HookConsumerWidget {
|
||||
const FeedListScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final feeds = ref.watch(feedListProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Feeds'),
|
||||
actions: [
|
||||
HookBuilder(
|
||||
builder: (context) {
|
||||
final future = useState<Future<void>?>(null);
|
||||
final state = useFuture(future.value);
|
||||
|
||||
if (state.connectionState == ConnectionState.waiting) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
child: SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(strokeWidth: 2.0),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return IconButton(
|
||||
onPressed: () {
|
||||
future.value = ref
|
||||
.read(fetchArticlesControllerProvider.notifier)
|
||||
.fetchAllArticles();
|
||||
},
|
||||
icon: const Icon(MdiIcons.cloudSync),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: feeds.when(
|
||||
skipLoadingOnReload: true,
|
||||
data: (feeds) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
await ref
|
||||
.read(fetchArticlesControllerProvider.notifier)
|
||||
.fetchAllArticles();
|
||||
},
|
||||
child: ListView.builder(
|
||||
itemCount: feeds.length,
|
||||
itemBuilder: (context, i) {
|
||||
return FeedCard(feed: feeds[i]);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
error: (error, stackTrace) => Center(
|
||||
child: FailureWidget(
|
||||
title: 'Failed to load Feeds',
|
||||
exception: error,
|
||||
onRetry: () {
|
||||
// ignore: unused_result
|
||||
ref.refresh(feedListProvider);
|
||||
},
|
||||
),
|
||||
),
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
label: const Text('Feed'),
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () async {
|
||||
await const FeedAddRoute(uri: null).push(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
import 'package:weblibre/core/routing/routes.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/providers.dart';
|
||||
import 'package:weblibre/presentation/widgets/failure_widget.dart';
|
||||
|
||||
/// Bottom sheet widget to select a feed from discovered feeds.
|
||||
class SelectFeedDialog extends HookConsumerWidget {
|
||||
final Set<Uri> feedUris;
|
||||
|
||||
const SelectFeedDialog({super.key, required this.feedUris});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('Add Feed', style: Theme.of(context).textTheme.titleLarge),
|
||||
const SizedBox(height: 16),
|
||||
...feedUris.map(
|
||||
(uri) => HookConsumer(
|
||||
builder: (context, ref, child) {
|
||||
final feedAsync = ref.watch(fetchWebFeedProvider(uri));
|
||||
|
||||
return feedAsync.when(
|
||||
skipLoadingOnReload: true,
|
||||
data: (data) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
data.feedData.title.whenNotEmpty ?? 'Unnamed Feed',
|
||||
),
|
||||
subtitle: Text(uri.toString()),
|
||||
trailing: const Icon(Icons.add),
|
||||
onTap: () {
|
||||
FeedCreateRoute(feedId: uri).pushReplacement(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
error: (error, stackTrace) => FailureWidget(
|
||||
title: 'Failed to fetch Feed',
|
||||
exception: error,
|
||||
onRetry: () {
|
||||
// ignore: unused_result
|
||||
ref.refresh(fetchWebFeedProvider(uri));
|
||||
},
|
||||
),
|
||||
loading: () => Skeletonizer(
|
||||
child: ListTile(
|
||||
title: Text(BoneMock.title),
|
||||
subtitle: Skeleton.keep(child: Text(uri.toString())),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:fading_scroll/fading_scroll.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_author.dart';
|
||||
|
||||
class AuthorsHorizontalList extends StatelessWidget {
|
||||
late final List<Widget> _authors;
|
||||
|
||||
AuthorsHorizontalList({
|
||||
super.key,
|
||||
required List<FeedAuthor> authors,
|
||||
Set<String> selectedTags = const {},
|
||||
void Function(String tagId, bool value)? onTagSelected,
|
||||
}) {
|
||||
_authors = authors.map((author) {
|
||||
final label = Text(
|
||||
'${author.name ?? ''} ${author.email.mapNotNull((email) => '($email)') ?? ''}'
|
||||
.trim(),
|
||||
);
|
||||
|
||||
return onTagSelected.mapNotNull(
|
||||
(onTagSelected) => FilterChip(
|
||||
label: label,
|
||||
selected: selectedTags.contains(author.name),
|
||||
onSelected: (value) {
|
||||
if (author.name.isNotEmpty) {
|
||||
onTagSelected(author.name!, value);
|
||||
}
|
||||
},
|
||||
),
|
||||
) ??
|
||||
Chip(label: label);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 48,
|
||||
child: FadingScroll(
|
||||
fadingSize: 15,
|
||||
builder: (context, controller) {
|
||||
return ListView.builder(
|
||||
itemCount: _authors.length,
|
||||
controller: controller,
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemBuilder: (context, index) => _authors[index],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
import 'package:weblibre/core/routing/routes.dart';
|
||||
import 'package:weblibre/extensions/uri.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article_query_result.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_link.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/providers/article_filter.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/repositories/feed_repository.dart';
|
||||
import 'package:weblibre/features/web_feed/extensions/atom.dart';
|
||||
import 'package:weblibre/features/web_feed/extensions/feed_article.dart';
|
||||
import 'package:weblibre/features/web_feed/presentation/widgets/authors_horizontal_list.dart';
|
||||
import 'package:weblibre/features/web_feed/presentation/widgets/tags_horizontal_list.dart';
|
||||
import 'package:weblibre/presentation/widgets/url_icon.dart';
|
||||
import 'package:weblibre/utils/text_highlight.dart';
|
||||
|
||||
class FeedArticleCard extends HookConsumerWidget {
|
||||
static const _matchPrefix = '***';
|
||||
static const _matchSuffix = '***';
|
||||
|
||||
final FeedArticle article;
|
||||
|
||||
const FeedArticleCard({super.key, required this.article});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
final tags = ref.watch(articleFilterProvider);
|
||||
|
||||
final titleHighlight = switch (article) {
|
||||
final FeedArticleQueryResult result => result.titleHighlight.whenNotEmpty,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
final searchSnippet = switch (article) {
|
||||
final FeedArticleQueryResult result =>
|
||||
result.summarySnippet.whenNotEmpty ??
|
||||
result.contentSnippet.whenNotEmpty,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
return Card(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
await FeedArticleRoute(articleId: article.id).push(context);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
UrlIcon([
|
||||
article.icon ??
|
||||
article.links
|
||||
?.getRelation(FeedLinkRelation.alternate)
|
||||
?.uri ??
|
||||
article.siteLink ??
|
||||
article.feedId.base,
|
||||
], iconSize: 34.0),
|
||||
const SizedBox(width: 12.0),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (titleHighlight.isNotEmpty)
|
||||
Text.rich(
|
||||
buildHighlightedText(
|
||||
titleHighlight!,
|
||||
Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
_matchPrefix,
|
||||
_matchSuffix,
|
||||
),
|
||||
),
|
||||
if (titleHighlight.isEmpty)
|
||||
Text(
|
||||
article.displayTitle,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
if (searchSnippet.isNotEmpty)
|
||||
Text.rich(
|
||||
buildHighlightedText(
|
||||
searchSnippet!,
|
||||
Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurfaceVariant,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
_matchPrefix,
|
||||
_matchSuffix,
|
||||
normalizeWhitespaces: true,
|
||||
),
|
||||
),
|
||||
if (searchSnippet.isEmpty &&
|
||||
article.summaryPlain != null)
|
||||
Text(
|
||||
article.summaryPlain!,
|
||||
style: theme.textTheme.bodySmall,
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (article.lastRead != null)
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
await ref
|
||||
.read(feedRepositoryProvider.notifier)
|
||||
.unsetArticleRead(article.id);
|
||||
},
|
||||
icon: const Icon(Icons.visibility),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (article.authors.isNotEmpty || article.tags.isNotEmpty) ...[
|
||||
const SizedBox(height: 8),
|
||||
if (article.authors.isNotEmpty)
|
||||
AuthorsHorizontalList(
|
||||
authors: article.authors!,
|
||||
selectedTags: tags,
|
||||
onTagSelected: (tagId, value) {
|
||||
if (value) {
|
||||
ref.read(articleFilterProvider.notifier).addTag(tagId);
|
||||
} else {
|
||||
ref
|
||||
.read(articleFilterProvider.notifier)
|
||||
.removeTag(tagId);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (article.tags.isNotEmpty)
|
||||
TagsHorizontalList(
|
||||
tags: article.tags!,
|
||||
selectedTags: tags,
|
||||
onTagSelected: (tagId, value) {
|
||||
if (value) {
|
||||
ref.read(articleFilterProvider.notifier).addTag(tagId);
|
||||
} else {
|
||||
ref
|
||||
.read(articleFilterProvider.notifier)
|
||||
.removeTag(tagId);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
const Divider(),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'Published: ${(article.created != null) ? timeago.format(article.created!) : 'N/A'}',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
if (article.updated != null &&
|
||||
article.updated != article.created)
|
||||
Text(
|
||||
'Updated: ${timeago.format(article.updated!)}',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
import 'package:weblibre/core/routing/routes.dart';
|
||||
import 'package:weblibre/extensions/uri.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/web_feed/domain/providers.dart';
|
||||
import 'package:weblibre/features/web_feed/presentation/widgets/authors_horizontal_list.dart';
|
||||
import 'package:weblibre/features/web_feed/presentation/widgets/tags_horizontal_list.dart';
|
||||
import 'package:weblibre/presentation/widgets/rounded_text.dart';
|
||||
import 'package:weblibre/presentation/widgets/url_icon.dart';
|
||||
|
||||
class FeedCard extends HookConsumerWidget {
|
||||
final FeedData feed;
|
||||
|
||||
const FeedCard({super.key, required this.feed});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Card(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
await FeedArticleListRoute(feedId: feed.url).push(context);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
UrlIcon([
|
||||
feed.icon ?? feed.siteLink ?? feed.url.base,
|
||||
], iconSize: 34.0),
|
||||
const SizedBox(width: 12.0),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
feed.title ?? feed.url.host,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
if (feed.description != null)
|
||||
Text(
|
||||
feed.description!,
|
||||
style: theme.textTheme.bodySmall,
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
await FeedEditRoute(feedId: feed.url).push(context);
|
||||
},
|
||||
icon: const Icon(Icons.edit),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (feed.authors.isNotEmpty || feed.tags.isNotEmpty) ...[
|
||||
if (feed.authors.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
|
||||
child: AuthorsHorizontalList(authors: feed.authors!),
|
||||
),
|
||||
if (feed.tags.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
|
||||
child: TagsHorizontalList(tags: feed.tags!),
|
||||
),
|
||||
],
|
||||
const Divider(),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'Last fetched: ${(feed.lastFetched != null) ? timeago.format(feed.lastFetched!) : 'N/A'}',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
Consumer(
|
||||
builder: (context, ref, child) {
|
||||
final countAsync = ref.watch(
|
||||
unreadFeedArticleCountProvider(feed.url),
|
||||
);
|
||||
|
||||
return countAsync.when(
|
||||
skipLoadingOnReload: true,
|
||||
data: (count) {
|
||||
if (count == null) {
|
||||
return const SizedBox();
|
||||
}
|
||||
|
||||
return RoundedBackground(
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
MdiIcons.newspaperVariantMultipleOutline,
|
||||
size: 18,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onPrimary,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
count.toString(),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
error: (error, stackTrace) => const Text('N/A'),
|
||||
loading: () => const SizedBox(
|
||||
height: 16,
|
||||
width: 16,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||
|
||||
final _tagSplitPatter = RegExp(r'[,\s]+');
|
||||
|
||||
class TagField extends HookWidget {
|
||||
final Set<String> initialTags;
|
||||
final void Function(Set<String> tags) onTagsUpdate;
|
||||
|
||||
const TagField({
|
||||
super.key,
|
||||
required this.initialTags,
|
||||
required this.onTagsUpdate,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final textController = useTextEditingController();
|
||||
final tags = useState(initialTags);
|
||||
|
||||
useOnListenableChange(tags, () {
|
||||
onTagsUpdate(tags.value);
|
||||
});
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Tags', style: Theme.of(context).textTheme.labelMedium),
|
||||
const SizedBox(height: 4),
|
||||
Wrap(
|
||||
spacing: 8.0,
|
||||
children: tags.value
|
||||
.map(
|
||||
(tag) => InputChip(
|
||||
label: Text(tag),
|
||||
onDeleted: () {
|
||||
tags.value = {...tags.value}..remove(tag);
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
TextField(
|
||||
controller: textController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'tag1, tag2, ...',
|
||||
prefixIcon: Icon(MdiIcons.tagMultiple),
|
||||
),
|
||||
onChanged: (String value) {
|
||||
if (value.isNotEmpty) {
|
||||
final values = value.split(_tagSplitPatter);
|
||||
|
||||
if (values.length > 1) {
|
||||
final trimmed = values
|
||||
.map((str) => str.trim())
|
||||
.where((str) => str.isNotEmpty);
|
||||
|
||||
if (trimmed.isNotEmpty) {
|
||||
textController.clear();
|
||||
|
||||
tags.value = {...tags.value, ...trimmed};
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onSubmitted: (value) {
|
||||
if (value.isNotEmpty) {
|
||||
final values = value
|
||||
.split(_tagSplitPatter)
|
||||
.map((str) => str.trim())
|
||||
.where((str) => str.isNotEmpty)
|
||||
.toList();
|
||||
|
||||
if (values.isNotEmpty) {
|
||||
textController.clear();
|
||||
|
||||
tags.value = {...tags.value, ...values};
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:fading_scroll/fading_scroll.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_category.dart';
|
||||
|
||||
class TagsHorizontalList extends StatelessWidget {
|
||||
late final List<Widget> _tags;
|
||||
|
||||
TagsHorizontalList({
|
||||
super.key,
|
||||
required List<FeedCategory> tags,
|
||||
Set<String> selectedTags = const {},
|
||||
void Function(String tagId, bool value)? onTagSelected,
|
||||
}) {
|
||||
_tags = tags.map((tag) {
|
||||
final label = Text(
|
||||
'${tag.id} ${tag.title.mapNotNull((title) => '($title)') ?? ''}'.trim(),
|
||||
);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child:
|
||||
onTagSelected.mapNotNull(
|
||||
(onTagSelected) => FilterChip(
|
||||
label: label,
|
||||
selected: selectedTags.contains(tag.id),
|
||||
onSelected: (value) {
|
||||
onTagSelected(tag.id, value);
|
||||
},
|
||||
),
|
||||
) ??
|
||||
Chip(label: label),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 48,
|
||||
child: FadingScroll(
|
||||
fadingSize: 15,
|
||||
builder: (context, controller) {
|
||||
return ListView.builder(
|
||||
itemCount: _tags.length,
|
||||
controller: controller,
|
||||
//Improve list performance by not rendering outside screen at all
|
||||
cacheExtent: 0,
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemBuilder: (context, index) => _tags[index],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:html/dom.dart';
|
||||
|
||||
class FeedFinder {
|
||||
final Uri url;
|
||||
final Document document;
|
||||
|
||||
late final String _base;
|
||||
|
||||
FeedFinder({required this.url, required this.document}) {
|
||||
final uri = url.removeFragment();
|
||||
_base = '${uri.scheme}://${uri.authority}';
|
||||
}
|
||||
|
||||
// Future<Set<String>> _verifyCandidates(Set<String> candidates) async {
|
||||
// final results = <String>{};
|
||||
|
||||
// final client = http.Client();
|
||||
// try {
|
||||
// for (final candidate in candidates) {
|
||||
// try {
|
||||
// await client.get(Uri.parse(candidate));
|
||||
// } catch (e) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// results.add(candidate);
|
||||
// }
|
||||
// } finally {
|
||||
// client.close();
|
||||
// }
|
||||
|
||||
// return results;
|
||||
// }
|
||||
|
||||
void _parseBody(Set<Uri> candidates) {
|
||||
for (final a in document.querySelectorAll('a')) {
|
||||
var href = a.attributes['href'];
|
||||
if (href != null) {
|
||||
if (href.contains('rss') ||
|
||||
href.contains('xml') ||
|
||||
href.contains('feed')) {
|
||||
// Fix relative URLs
|
||||
href = href.startsWith('/') ? _base + href : href;
|
||||
href = href.endsWith('/') ? href.substring(0, href.length - 2) : href;
|
||||
|
||||
// Fix naked URLs
|
||||
href = !href.startsWith('http') ? '$_base/$href' : href;
|
||||
|
||||
if (Uri.tryParse(href) case final Uri uri) {
|
||||
candidates.add(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _parseHead(Set<Uri> candidates) {
|
||||
for (final link in document.querySelectorAll("link[rel='alternate']")) {
|
||||
final type = link.attributes['type'];
|
||||
if (type != null) {
|
||||
if (type.contains('rss') || type.contains('xml')) {
|
||||
var href = link.attributes['href'];
|
||||
if (href != null) {
|
||||
// Fix relative URLs
|
||||
href = href.startsWith('/') ? _base + href : href;
|
||||
|
||||
if (Uri.tryParse(href) case final Uri uri) {
|
||||
candidates.add(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<Set<Uri>> parse({
|
||||
bool parseHead = true,
|
||||
bool parseBody = true,
|
||||
// bool verifyCandidates = true,
|
||||
}) async {
|
||||
final candidates = <Uri>{};
|
||||
|
||||
// Look for feed candidates in head
|
||||
if (parseHead) {
|
||||
_parseHead(candidates);
|
||||
}
|
||||
|
||||
// Look for feed candidates in body
|
||||
if (parseBody) {
|
||||
_parseBody(candidates);
|
||||
}
|
||||
|
||||
// Verify candidates
|
||||
// if (verifyCandidates) {
|
||||
// return _verifyCandidates(candidates);
|
||||
// }
|
||||
|
||||
return candidates;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:nullability/nullability.dart';
|
||||
import 'package:rss_dart/dart_rss.dart';
|
||||
import 'package:rss_dart/domain/rss1_feed.dart';
|
||||
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_author.dart';
|
||||
import 'package:weblibre/features/web_feed/data/models/feed_link.dart';
|
||||
import 'package:weblibre/features/web_feed/extensions/atom.dart';
|
||||
import 'package:weblibre/features/web_feed/extensions/rss.dart';
|
||||
|
||||
class FeedParser {
|
||||
final Uri url;
|
||||
late Object _feed;
|
||||
|
||||
FeedParser._(this.url, this._feed);
|
||||
|
||||
factory FeedParser.parse({required Uri url, required String xmlString}) {
|
||||
final rssVersion = WebFeed.detectRssVersion(xmlString);
|
||||
final feed = switch (rssVersion) {
|
||||
RssVersion.rss1 => Rss1Feed.parse(xmlString),
|
||||
RssVersion.rss2 => RssFeed.parse(xmlString),
|
||||
RssVersion.atom => AtomFeed.parse(xmlString),
|
||||
RssVersion.unknown => throw Error.safeToString(
|
||||
'Invalid XML String? We cannot detect RSS/Atom version.',
|
||||
),
|
||||
};
|
||||
|
||||
return FeedParser._(url, feed);
|
||||
}
|
||||
|
||||
FeedData readGeneralData() {
|
||||
switch (_feed) {
|
||||
case final Rss1Feed feed:
|
||||
return FeedData(
|
||||
url: url,
|
||||
title: feed.title.whenNotEmpty ?? feed.dc?.title,
|
||||
description: feed.description.whenNotEmpty ?? feed.dc?.description,
|
||||
siteLink: feed.link.mapNotNull(Uri.tryParse),
|
||||
authors: feed.dc?.creator.whenNotEmpty.mapNotNull(
|
||||
(creator) => [FeedAuthor(name: creator)],
|
||||
),
|
||||
tags: feed.dc?.toFeedCategories(),
|
||||
);
|
||||
case final RssFeed feed:
|
||||
final categories = feed.categories.toFeedCategories();
|
||||
|
||||
return FeedData(
|
||||
url: url,
|
||||
title: feed.title.whenNotEmpty ?? feed.dc?.title,
|
||||
description: feed.description.whenNotEmpty ?? feed.dc?.description,
|
||||
siteLink: feed.link.mapNotNull(Uri.tryParse),
|
||||
authors: (feed.author.whenNotEmpty ?? feed.dc?.creator.whenNotEmpty)
|
||||
.mapNotNull((creator) => [FeedAuthor(name: creator)]),
|
||||
tags: categories.isNotEmpty
|
||||
? categories
|
||||
: feed.dc?.toFeedCategories(),
|
||||
);
|
||||
case final AtomFeed feed:
|
||||
final authors = feed.authors.toFeedAuthors();
|
||||
final tags = feed.categories.toFeedCategories();
|
||||
|
||||
return FeedData(
|
||||
url: url,
|
||||
title: feed.title.whenNotEmpty,
|
||||
icon: feed.icon.mapNotNull(Uri.tryParse),
|
||||
siteLink: feed.links
|
||||
.toFeedLinks()
|
||||
.getRelation(FeedLinkRelation.alternate)
|
||||
?.uri,
|
||||
description: feed.subtitle.whenNotEmpty,
|
||||
authors: authors.isNotEmpty ? authors : null,
|
||||
tags: tags,
|
||||
);
|
||||
default:
|
||||
throw Exception(
|
||||
'Unknown feed type in readGeneralData: ${_feed.runtimeType}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
List<FeedArticle> readArticles() {
|
||||
final fetchDate = DateTime.now();
|
||||
|
||||
switch (_feed) {
|
||||
case final Rss1Feed feed:
|
||||
return feed.items.mapIndexed((i, item) {
|
||||
final title = item.title.whenNotEmpty ?? item.dc?.title.whenNotEmpty;
|
||||
|
||||
final itemId = item.dc?.identifier.whenNotEmpty ?? title;
|
||||
final uniqueId =
|
||||
'${item.link.whenNotEmpty ?? feed.link.whenNotEmpty ?? url}#$itemId';
|
||||
final date = SafeParseDateTime.safeParse(item.dc?.date);
|
||||
final link = item.link.mapNotNull(Uri.tryParse);
|
||||
|
||||
return FeedArticle(
|
||||
id: uniqueId,
|
||||
feedId: url,
|
||||
title: title,
|
||||
fetched: fetchDate,
|
||||
created: date,
|
||||
authors: item.dc?.creator.whenNotEmpty.mapNotNull(
|
||||
(creator) => [FeedAuthor(name: creator)],
|
||||
),
|
||||
summaryHtml:
|
||||
item.description.whenNotEmpty ??
|
||||
item.dc?.description.whenNotEmpty,
|
||||
links: link.mapNotNull(
|
||||
(link) => [
|
||||
FeedLink(uri: link, relation: FeedLinkRelation.alternate),
|
||||
],
|
||||
),
|
||||
tags: item.dc?.toFeedCategories(),
|
||||
contentHtml: item.content?.value.whenNotEmpty,
|
||||
);
|
||||
}).toList();
|
||||
case final RssFeed feed:
|
||||
return feed.items.mapIndexed((i, item) {
|
||||
final title = item.title.whenNotEmpty ?? item.dc?.title.whenNotEmpty;
|
||||
|
||||
final itemId =
|
||||
item.guid.whenNotEmpty ??
|
||||
item.dc?.identifier.whenNotEmpty ??
|
||||
title;
|
||||
|
||||
final uniqueId =
|
||||
'${item.link.whenNotEmpty ?? feed.link.whenNotEmpty ?? url}#$itemId';
|
||||
final date = SafeParseDateTime.safeParse(
|
||||
item.pubDate.whenNotEmpty ?? item.dc?.date,
|
||||
);
|
||||
final link = item.link.mapNotNull(Uri.tryParse);
|
||||
final author =
|
||||
item.author.whenNotEmpty ?? item.dc?.creator.whenNotEmpty;
|
||||
|
||||
final categories = item.categories.toFeedCategories();
|
||||
|
||||
return FeedArticle(
|
||||
id: uniqueId,
|
||||
feedId: url,
|
||||
title: title,
|
||||
fetched: fetchDate,
|
||||
created: date,
|
||||
authors: author.mapNotNull(
|
||||
(creator) => [FeedAuthor(name: creator)],
|
||||
),
|
||||
summaryHtml:
|
||||
item.description.whenNotEmpty ??
|
||||
item.dc?.description.whenNotEmpty,
|
||||
links: link.mapNotNull(
|
||||
(link) => [
|
||||
FeedLink(uri: link, relation: FeedLinkRelation.alternate),
|
||||
],
|
||||
),
|
||||
tags: categories.isNotEmpty
|
||||
? categories
|
||||
: item.dc?.toFeedCategories(),
|
||||
contentHtml: item.content?.value.whenNotEmpty,
|
||||
);
|
||||
}).toList();
|
||||
case final AtomFeed feed:
|
||||
final feedLink = feed.links.toFeedLinks().getRelation(
|
||||
FeedLinkRelation.self,
|
||||
);
|
||||
|
||||
return feed.items.mapIndexed((i, item) {
|
||||
final authors = item.authors.toFeedAuthors();
|
||||
|
||||
final tags = item.categories.toFeedCategories();
|
||||
|
||||
final itemLinks = item.links.toFeedLinks();
|
||||
final articleLink = itemLinks.getRelation(FeedLinkRelation.alternate);
|
||||
|
||||
final itemId = item.id.whenNotEmpty ?? item.title;
|
||||
final uniqueId =
|
||||
'${articleLink?.uri ?? feedLink?.uri ?? url}#$itemId';
|
||||
|
||||
final published = SafeParseDateTime.safeParse(item.published);
|
||||
final updated = SafeParseDateTime.safeParse(item.updated);
|
||||
|
||||
return FeedArticle(
|
||||
id: uniqueId,
|
||||
feedId: url,
|
||||
title: item.title.whenNotEmpty,
|
||||
summaryHtml: item.summary.whenNotEmpty,
|
||||
links: itemLinks,
|
||||
authors: authors.isNotEmpty ? authors : null,
|
||||
tags: tags,
|
||||
fetched: fetchDate,
|
||||
created: published,
|
||||
updated: updated,
|
||||
contentHtml: item.content.whenNotEmpty,
|
||||
);
|
||||
}).toList();
|
||||
default:
|
||||
throw Exception(
|
||||
'Unknown feed type in readArticles: ${_feed.runtimeType}',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:background_fetch/background_fetch.dart';
|
||||
import 'package:riverpod/riverpod.dart';
|
||||
import 'package:weblibre/core/error_observer.dart';
|
||||
import 'package:weblibre/core/logger.dart';
|
||||
import 'package:weblibre/features/web_feed/presentation/controllers/fetch_articles.dart';
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
Future<void> backgroundFetch(HeadlessTask task) async {
|
||||
final taskId = task.taskId;
|
||||
|
||||
final isTimeout = task.timeout;
|
||||
if (isTimeout) {
|
||||
// This task has exceeded its allowed running-time.
|
||||
// You must stop what you're doing and immediately .finish(taskId)
|
||||
logger.e("[BackgroundFetch] Headless task timed-out: $taskId");
|
||||
await BackgroundFetch.finish(taskId);
|
||||
return;
|
||||
}
|
||||
|
||||
final ref = ProviderContainer(observers: const [ErrorObserver()]);
|
||||
try {
|
||||
await ref.read(fetchArticlesControllerProvider.notifier).fetchAllArticles();
|
||||
|
||||
logger.i('Fetched articles in background');
|
||||
} catch (e, s) {
|
||||
logger.e('Failed fetching articles', error: e, stackTrace: s);
|
||||
} finally {
|
||||
ref.dispose();
|
||||
|
||||
// Give everything a bit of time to properly dispose
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
|
||||
await BackgroundFetch.finish(taskId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user