Skip to content

Commit

Permalink
chore: smol fix for video comments
Browse files Browse the repository at this point in the history
while fetching next
  • Loading branch information
MSOB7YY committed Jun 25, 2024
1 parent 3bb2e12 commit 4d431db
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/youtube/controller/youtube_current_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,20 @@ class _YoutubeCurrentInfoController {
}

/// specify [sortType] to force refresh. otherwise fetches next
Future<void> updateCurrentComments(String videoId, {CommentsSortType? sortType, bool initial = false}) async {
Future<void> updateCurrentComments(String videoId, {CommentsSortType? newSortType, bool initial = false}) async {
final commentRes = _currentComments.value;
if (commentRes == null) return;
if (initial == false && commentRes.canFetchNext == false) return;

if (initial == false && commentRes.canFetchNext && commentRes.isNotEmpty && sortType == null) {
if (initial == false && commentRes.canFetchNext && newSortType == null) {
_isLoadingMoreComments.value = true;
final didFetch = await commentRes.fetchNext();
if (didFetch) _currentComments.refresh();
_isLoadingMoreComments.value = false;
} else {
// -- fetch initial.
_isLoadingInitialComments.value = true;
final initialContinuation = sortType == null ? _initialCommentsContinuation : commentRes.sorters[sortType] ?? _initialCommentsContinuation;
final initialContinuation = newSortType == null ? _initialCommentsContinuation : commentRes.sorters[newSortType] ?? _initialCommentsContinuation;
if (initialContinuation != null) {
final newRes = await YoutubeInfoController.comment.fetchComments(
videoId: videoId,
Expand Down
4 changes: 2 additions & 2 deletions lib/youtube/youtube_miniplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ class YoutubeMiniPlayerState extends State<YoutubeMiniPlayer> {
iconSize: 22.0,
onPressed: () async => await YoutubeInfoController.current.updateCurrentComments(
currentId,
sortType: YoutubeMiniplayerUiController.inst.currentCommentSort.value,
newSortType: YoutubeMiniplayerUiController.inst.currentCommentSort.value,
initial: true,
),
child: commFromCache
Expand Down Expand Up @@ -941,7 +941,7 @@ class YoutubeMiniPlayerState extends State<YoutubeMiniPlayer> {
iconSize: 22.0,
onPressed: () async => await YoutubeInfoController.current.updateCurrentComments(
currentId,
sortType: YoutubeMiniplayerUiController.inst.currentCommentSort.value,
newSortType: YoutubeMiniplayerUiController.inst.currentCommentSort.value,
initial: true,
),
child: commFromCache
Expand Down
2 changes: 1 addition & 1 deletion lib/youtube/yt_miniplayer_comments_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class _YTMiniplayerCommentsSubpageState extends State<YTMiniplayerCommentsSubpag
if (currentId != null) {
await YoutubeInfoController.current.updateCurrentComments(
currentId,
sortType: YoutubeMiniplayerUiController.inst.currentCommentSort.value,
newSortType: YoutubeMiniplayerUiController.inst.currentCommentSort.value,
initial: true,
);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 2.8.05-beta+240625124
version: 2.8.1-beta+240625124

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down

0 comments on commit 4d431db

Please sign in to comment.