|
|
|
@ -132,21 +132,6 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
|
|
|
|
|
final NewsArticlesBloc bloc, |
|
|
|
|
final NewsArticle article, |
|
|
|
|
final NewsFeed feed, |
|
|
|
|
) { |
|
|
|
|
final clientID = RxBlocProvider.of<AccountsBloc>(context).activeAccount.value!.client.id; |
|
|
|
|
|
|
|
|
|
return ResultStreamBuilder<String>( |
|
|
|
|
stream: Provider.of<RequestManager>(context).wrapString( |
|
|
|
|
clientID, |
|
|
|
|
'news-articles-body-${article.id}', |
|
|
|
|
() async => _fixArticleBody(article.body!), |
|
|
|
|
preferCache: true, |
|
|
|
|
), |
|
|
|
|
builder: ( |
|
|
|
|
final context, |
|
|
|
|
final bodyData, |
|
|
|
|
final bodyError, |
|
|
|
|
final bodyLoading, |
|
|
|
|
) => |
|
|
|
|
ListTile( |
|
|
|
|
title: Row( |
|
|
|
@ -225,10 +210,17 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
|
|
|
|
|
bloc.markArticleAsUnread(article); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
onTap: bodyData != null |
|
|
|
|
? () async { |
|
|
|
|
onTap: () async { |
|
|
|
|
final viewType = bloc.newsBloc.options.articleViewTypeOption.value; |
|
|
|
|
if (viewType == ArticleViewType.direct) { |
|
|
|
|
String? bodyData; |
|
|
|
|
try { |
|
|
|
|
bodyData = _fixArticleBody(article.body!); |
|
|
|
|
} catch (e, s) { |
|
|
|
|
debugPrint(e.toString()); |
|
|
|
|
debugPrint(s.toString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (viewType == ArticleViewType.direct && bodyData != null) { |
|
|
|
|
await Navigator.of(context).push( |
|
|
|
|
MaterialPageRoute( |
|
|
|
|
builder: (final context) => NewsArticlePage( |
|
|
|
@ -259,22 +251,12 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
|
|
|
|
|
mode: LaunchMode.externalApplication, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
: null, |
|
|
|
|
), |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String _fixArticleBody(final String b) => _fixTree(html_parser.parse(b).documentElement!).outerHtml; |
|
|
|
|
String _fixArticleBody(final String b) => _fixArticleBodyElement(html_parser.parse(b).documentElement!).outerHtml; |
|
|
|
|
|
|
|
|
|
html_dom.Element _fixTree(final html_dom.Element element) { |
|
|
|
|
_fixElement(element); |
|
|
|
|
element.children.forEach(_fixTree); |
|
|
|
|
|
|
|
|
|
return element; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
html_dom.Element _fixElement(final html_dom.Element element) { |
|
|
|
|
html_dom.Element _fixArticleBodyElement(final html_dom.Element element) { |
|
|
|
|
for (final attributeName in ['src', 'href']) { |
|
|
|
|
final attributeValue = element.attributes[attributeName]; |
|
|
|
|
if (attributeValue != null && attributeValue.startsWith('//')) { |
|
|
|
@ -282,6 +264,8 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
element.children.forEach(_fixArticleBodyElement); |
|
|
|
|
|
|
|
|
|
return element; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|