File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed
Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -205,6 +205,7 @@ class LemmyApi {
205205
206206 /// Fetches a list of posts from the Lemmy API
207207 Future <Map <String , dynamic >> getPosts ({
208+ int ? page,
208209 String ? cursor,
209210 int ? limit,
210211 FeedListType ? feedListType,
@@ -214,17 +215,19 @@ class LemmyApi {
214215 bool ? showHidden,
215216 bool ? showSaved,
216217 }) async {
217- final queryParams = {
218+ Map < String , dynamic > queryParams = {
218219 'type_' : feedListType? .value,
219220 'sort' : postSortType? .value,
220221 'page_cursor' : cursor,
222+ 'page' : page,
221223 'limit' : limit,
222224 'community_name' : communityName,
223225 'community_id' : communityId,
224- 'saved_only' : showSaved,
225- 'show_hidden' : showHidden,
226226 };
227227
228+ if (showSaved == true ) queryParams['saved_only' ] = showSaved;
229+ if (showHidden == true ) queryParams['show_hidden' ] = showHidden;
230+
228231 final json = await _request (HttpMethod .get , '/api/v3/post/list' , queryParams);
229232 return {
230233 'posts' : json['posts' ].map <ThunderPost >((pv) => ThunderPost .fromLemmyPostView (pv)).toList (),
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import 'package:bloc/bloc.dart';
44import 'package:bloc_concurrency/bloc_concurrency.dart' ;
55import 'package:equatable/equatable.dart' ;
66import 'package:stream_transform/stream_transform.dart' ;
7+ import 'package:thunder/src/core/network/lemmy_api.dart' ;
78
89import 'package:thunder/src/features/account/account.dart' ;
910import 'package:thunder/src/features/comment/comment.dart' ;
@@ -655,7 +656,7 @@ class FeedBloc extends Bloc<FeedEvent, FeedState> {
655656 ));
656657 } catch (e) {
657658 debugPrint ('Error fetching feed: $e ' );
658- return emit (state.copyWith (status: FeedStatus .failure, message: e.toString ()));
659+ return emit (state.copyWith (status: FeedStatus .failure, message: e is LemmyApiException ? e.message : e .toString ()));
659660 }
660661 }
661662
Original file line number Diff line number Diff line change @@ -166,8 +166,13 @@ class PostRepositoryImpl implements PostRepository {
166166 }) async {
167167 switch (account.platform) {
168168 case ThreadiversePlatform .lemmy:
169- return await lemmy.getPosts (
170- cursor: cursor,
169+ // Use page-based pagination for Lemmy for 0.19.x instances as there are some performance issues with cursor-based pagination.
170+ // See https://github.com/LemmyNet/lemmy/issues/6171, https://lemmy.world/post/40266465/21176898
171+ // TODO: Once 1.x.x is released, we can switch back to cursor-based pagination.
172+ final page = cursor != null ? int .tryParse (cursor) ?? 1 : 1 ;
173+
174+ final response = await lemmy.getPosts (
175+ page: page,
171176 limit: limit,
172177 postSortType: postSortType,
173178 feedListType: feedListType,
@@ -176,6 +181,13 @@ class PostRepositoryImpl implements PostRepository {
176181 showHidden: showHidden,
177182 showSaved: showSaved,
178183 );
184+
185+ // Return next page as string cursor for Lemmy
186+ final nextPage = response['posts' ].isNotEmpty ? (page + 1 ).toString () : null ;
187+ return {
188+ 'posts' : response['posts' ],
189+ 'next_page' : nextPage,
190+ };
179191 case ThreadiversePlatform .piefed:
180192 // PieFed uses integer page-based pagination. The cursor in this case is the page number.
181193 final page = cursor != null ? int .tryParse (cursor) ?? 1 : 1 ;
You can’t perform that action at this time.
0 commit comments