✨ Basic fediverse posts displaying
This commit is contained in:
@ -19,6 +19,7 @@ const kAppExpandPostLink = 'app_expand_post_link';
|
||||
const kAppExpandChatLink = 'app_expand_chat_link';
|
||||
const kAppRealmCompactView = 'app_realm_compact_view';
|
||||
const kAppCustomFonts = 'app_custom_fonts';
|
||||
const kAppMixedFeed = 'app_mixed_feed';
|
||||
|
||||
const Map<String, FilterQuality> kImageQualityLevel = {
|
||||
'settingsImageQualityLowest': FilterQuality.none,
|
||||
@ -81,8 +82,18 @@ class ConfigProvider extends ChangeNotifier {
|
||||
return prefs.getBool(kAppRealmCompactView) ?? false;
|
||||
}
|
||||
|
||||
bool get mixedFeed {
|
||||
return prefs.getBool(kAppMixedFeed) ?? true;
|
||||
}
|
||||
|
||||
set mixedFeed(bool value) {
|
||||
prefs.setBool(kAppMixedFeed, value);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set realmCompactView(bool value) {
|
||||
prefs.setBool(kAppRealmCompactView, value);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set serverUrl(String url) {
|
||||
|
@ -145,6 +145,36 @@ class SnPostContentProvider {
|
||||
return out;
|
||||
}
|
||||
|
||||
Future<List<SnFeedEntry>> getFeed({int take = 20, DateTime? cursor}) async {
|
||||
final resp =
|
||||
await _sn.client.get('/cgi/co/recommendations/feed', queryParameters: {
|
||||
'take': take,
|
||||
if (cursor != null) 'cursor': cursor.toUtc().millisecondsSinceEpoch,
|
||||
});
|
||||
final List<SnFeedEntry> out =
|
||||
List.from(resp.data.map((ele) => SnFeedEntry.fromJson(ele)));
|
||||
|
||||
List<SnPost> posts = List.empty(growable: true);
|
||||
for (var idx = 0; idx < out.length; idx++) {
|
||||
final ele = out[idx];
|
||||
if (ele.type == 'interactive.post') {
|
||||
posts.add(SnPost.fromJson(ele.data));
|
||||
}
|
||||
}
|
||||
posts = await _preloadRelatedDataInBatch(posts);
|
||||
|
||||
var postsIdx = 0;
|
||||
for (var idx = 0; idx < out.length; idx++) {
|
||||
final ele = out[idx];
|
||||
if (ele.type == 'interactive.post') {
|
||||
out[idx] = ele.copyWith(data: posts[postsIdx].toJson());
|
||||
postsIdx++;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
Future<(List<SnPost>, int)> listPosts({
|
||||
int take = 10,
|
||||
int offset = 0,
|
||||
|
Reference in New Issue
Block a user