You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
196 lines
5.1 KiB
196 lines
5.1 KiB
2 years ago
|
part of '../neon_news.dart';
|
||
3 years ago
|
|
||
|
abstract class NewsBlocEvents {
|
||
2 years ago
|
void addFeed(final String url, final int? folderId);
|
||
3 years ago
|
|
||
2 years ago
|
void removeFeed(final int feedId);
|
||
3 years ago
|
|
||
2 years ago
|
void renameFeed(final int feedId, final String feedTitle);
|
||
3 years ago
|
|
||
2 years ago
|
void moveFeed(final int feedId, final int? folderId);
|
||
3 years ago
|
|
||
2 years ago
|
void markFeedAsRead(final int feedId);
|
||
3 years ago
|
|
||
|
void createFolder(final String name);
|
||
|
|
||
2 years ago
|
void deleteFolder(final int folderId);
|
||
3 years ago
|
|
||
2 years ago
|
void renameFolder(final int folderId, final String name);
|
||
3 years ago
|
|
||
2 years ago
|
void markFolderAsRead(final int folderId);
|
||
3 years ago
|
}
|
||
|
|
||
|
abstract class NewsBlocStates {
|
||
2 years ago
|
BehaviorSubject<Result<List<NextcloudNewsFolder>>> get folders;
|
||
3 years ago
|
|
||
2 years ago
|
BehaviorSubject<Result<List<NextcloudNewsFeed>>> get feeds;
|
||
3 years ago
|
|
||
2 years ago
|
BehaviorSubject<int> get unreadCounter;
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
class NewsBloc extends InteractiveBloc implements NewsBlocEvents, NewsBlocStates, NewsMainArticlesBloc {
|
||
3 years ago
|
NewsBloc(
|
||
|
this.options,
|
||
|
this.requestManager,
|
||
|
this.client,
|
||
|
) {
|
||
2 years ago
|
mainArticlesBloc.articles.listen((final result) {
|
||
|
if (result.data != null) {
|
||
|
final type = mainArticlesBloc.filterType.valueOrNull;
|
||
2 years ago
|
unreadCounter.add(result.data!.where((final a) => type == FilterType.starred ? a.starred : a.unread).length);
|
||
2 years ago
|
}
|
||
|
});
|
||
|
|
||
2 years ago
|
unawaited(mainArticlesBloc.refresh());
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
@override
|
||
|
NewsBloc get _newsBloc => this;
|
||
2 years ago
|
@override
|
||
|
final NewsAppSpecificOptions options;
|
||
2 years ago
|
@override
|
||
2 years ago
|
final RequestManager requestManager;
|
||
2 years ago
|
@override
|
||
2 years ago
|
final NextcloudClient client;
|
||
|
late final mainArticlesBloc = NewsMainArticlesBloc(
|
||
|
this,
|
||
|
options,
|
||
|
requestManager,
|
||
|
client,
|
||
|
);
|
||
3 years ago
|
|
||
2 years ago
|
late int _newestItemId;
|
||
|
@override
|
||
|
int? id;
|
||
|
@override
|
||
|
ListType? listType;
|
||
3 years ago
|
|
||
2 years ago
|
@override
|
||
|
void dispose() {
|
||
|
unawaited(feeds.close());
|
||
|
unawaited(folders.close());
|
||
|
unawaited(unreadCounter.close());
|
||
|
unawaited(articles.close());
|
||
|
unawaited(filterType.close());
|
||
2 years ago
|
mainArticlesBloc.dispose();
|
||
2 years ago
|
super.dispose();
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
@override
|
||
2 years ago
|
BehaviorSubject<Result<List<NextcloudNewsFeed>>> feeds = BehaviorSubject<Result<List<NextcloudNewsFeed>>>();
|
||
2 years ago
|
|
||
|
@override
|
||
2 years ago
|
BehaviorSubject<Result<List<NextcloudNewsFolder>>> folders = BehaviorSubject<Result<List<NextcloudNewsFolder>>>();
|
||
2 years ago
|
|
||
|
@override
|
||
|
BehaviorSubject<int> unreadCounter = BehaviorSubject<int>();
|
||
|
|
||
|
@override
|
||
2 years ago
|
late BehaviorSubject<Result<List<NextcloudNewsArticle>>> articles = mainArticlesBloc.articles;
|
||
2 years ago
|
|
||
|
@override
|
||
|
late BehaviorSubject<FilterType> filterType = mainArticlesBloc.filterType;
|
||
3 years ago
|
|
||
2 years ago
|
@override
|
||
|
Future refresh() async {
|
||
2 years ago
|
await Future.wait([
|
||
2 years ago
|
requestManager.wrapNextcloud<List<NextcloudNewsFolder>, NextcloudNewsListFolders>(
|
||
2 years ago
|
client.id,
|
||
|
'news-folders',
|
||
|
folders,
|
||
|
() async => client.news.listFolders(),
|
||
|
(final response) => response.folders,
|
||
|
),
|
||
2 years ago
|
requestManager.wrapNextcloud<List<NextcloudNewsFeed>, NextcloudNewsListFeeds>(
|
||
2 years ago
|
client.id,
|
||
|
'news-feeds',
|
||
|
feeds,
|
||
|
() async => client.news.listFeeds(),
|
||
|
(final response) {
|
||
|
// This is a bit ugly, but IDGAF right now
|
||
|
if (response.newestItemId != null) {
|
||
|
_newestItemId = response.newestItemId!;
|
||
|
}
|
||
|
return response.feeds;
|
||
|
},
|
||
|
),
|
||
|
mainArticlesBloc.reload(),
|
||
|
]);
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
@override
|
||
|
void addFeed(final String url, final int? folderId) {
|
||
|
wrapAction(() async => client.news.addFeed(url: url, folderId: folderId));
|
||
|
}
|
||
3 years ago
|
|
||
2 years ago
|
@override
|
||
|
void createFolder(final String name) {
|
||
|
wrapAction(() async => client.news.createFolder(name: name));
|
||
|
}
|
||
3 years ago
|
|
||
2 years ago
|
@override
|
||
|
void deleteFolder(final int folderId) {
|
||
|
wrapAction(() async => client.news.deleteFolder(folderId: folderId));
|
||
|
}
|
||
3 years ago
|
|
||
|
@override
|
||
2 years ago
|
void markFeedAsRead(final int feedId) {
|
||
|
wrapAction(() async => client.news.markFeedAsRead(feedId: feedId, newestItemId: _newestItemId));
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void markFolderAsRead(final int folderId) {
|
||
|
wrapAction(() async => client.news.markFolderAsRead(folderId: folderId, newestItemId: _newestItemId));
|
||
3 years ago
|
}
|
||
|
|
||
|
@override
|
||
2 years ago
|
void moveFeed(final int feedId, final int? folderId) {
|
||
|
wrapAction(() async => client.news.moveFeed(feedId: feedId, folderId: folderId));
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void removeFeed(final int feedId) {
|
||
|
wrapAction(() async => client.news.deleteFeed(feedId: feedId));
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void renameFeed(final int feedId, final String feedTitle) {
|
||
|
wrapAction(() async => client.news.renameFeed(feedId: feedId, feedTitle: feedTitle));
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void renameFolder(final int folderId, final String name) {
|
||
|
wrapAction(() async => client.news.renameFolder(folderId: folderId, name: name));
|
||
|
}
|
||
|
|
||
|
@override
|
||
2 years ago
|
void markArticleAsRead(final NextcloudNewsArticle article) {
|
||
2 years ago
|
mainArticlesBloc.markArticleAsRead(article);
|
||
|
}
|
||
3 years ago
|
|
||
|
@override
|
||
2 years ago
|
void markArticleAsUnread(final NextcloudNewsArticle article) {
|
||
2 years ago
|
mainArticlesBloc.markArticleAsUnread(article);
|
||
|
}
|
||
3 years ago
|
|
||
|
@override
|
||
2 years ago
|
void setFilterType(final FilterType type) {
|
||
|
mainArticlesBloc.setFilterType(type);
|
||
|
}
|
||
2 years ago
|
|
||
|
@override
|
||
2 years ago
|
void starArticle(final NextcloudNewsArticle article) {
|
||
2 years ago
|
mainArticlesBloc.starArticle(article);
|
||
|
}
|
||
|
|
||
|
@override
|
||
2 years ago
|
void unstarArticle(final NextcloudNewsArticle article) {
|
||
2 years ago
|
mainArticlesBloc.unstarArticle(article);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Future reload() async {
|
||
|
await mainArticlesBloc.reload();
|
||
|
}
|
||
3 years ago
|
}
|