mod: reply ctr

This commit is contained in:
bggRGjQaUbCoE
2024-10-12 10:59:41 +08:00
parent 6e7e815710
commit 98512a7275
11 changed files with 95 additions and 136 deletions

View File

@@ -132,6 +132,7 @@ class GrpcRepo {
} }
static Future detailList({ static Future detailList({
int type = 1,
required int oid, required int oid,
required int root, required int root,
required CursorReq cursor, required CursorReq cursor,
@@ -140,7 +141,7 @@ class GrpcRepo {
return await _request(() async { return await _request(() async {
final request = DetailListReq() final request = DetailListReq()
..oid = Int64(oid) ..oid = Int64(oid)
..type = Int64(1) ..type = Int64(type)
..root = Int64(root) ..root = Int64(root)
..cursor = cursor ..cursor = cursor
..scene = scene; ..scene = scene;
@@ -151,13 +152,14 @@ class GrpcRepo {
} }
static Future mainList({ static Future mainList({
int type = 1,
required int oid, required int oid,
required CursorReq cursor, required CursorReq cursor,
}) async { }) async {
return await _request(() async { return await _request(() async {
final request = MainListReq() final request = MainListReq()
..oid = Int64(oid) ..oid = Int64(oid)
..type = Int64(1) ..type = Int64(type)
..rpid = Int64(0) ..rpid = Int64(0)
..cursor = cursor; ..cursor = cursor;
final response = await GrpcClient.instance.replyClient final response = await GrpcClient.instance.replyClient

View File

@@ -57,10 +57,11 @@ class ReplyHttp {
} }
static Future<LoadingState> replyListGrpc({ static Future<LoadingState> replyListGrpc({
int type = 1,
required int oid, required int oid,
required CursorReq cursor, required CursorReq cursor,
}) async { }) async {
dynamic res = await GrpcRepo.mainList(oid: oid, cursor: cursor); dynamic res = await GrpcRepo.mainList(type: type, oid: oid, cursor: cursor);
if (res['status']) { if (res['status']) {
return LoadingState.success(res['data']); return LoadingState.success(res['data']);
} else { } else {
@@ -99,11 +100,13 @@ class ReplyHttp {
} }
static Future<LoadingState> replyReplyListGrpc({ static Future<LoadingState> replyReplyListGrpc({
int type = 1,
required int oid, required int oid,
required int root, required int root,
required CursorReq cursor, required CursorReq cursor,
}) async { }) async {
dynamic res = await GrpcRepo.detailList( dynamic res = await GrpcRepo.detailList(
type: type,
oid: oid, oid: oid,
root: root, root: root,
cursor: cursor, cursor: cursor,

View File

@@ -28,6 +28,10 @@ abstract class ReplyController extends CommonController {
bool isLogin = GStorage.userInfo.get('userInfoCache') != null; bool isLogin = GStorage.userInfo.get('userInfoCache') != null;
CursorReply? cursor;
Mode mode = Mode.MAIN_LIST_HOT;
bool hasUpTop = false;
@override @override
void onInit() { void onInit() {
super.onInit(); super.onInit();
@@ -44,6 +48,7 @@ abstract class ReplyController extends CommonController {
@override @override
Future onRefresh() { Future onRefresh() {
cursor = null;
nextOffset = ''; nextOffset = '';
noMore.value = ''; noMore.value = '';
return super.onRefresh(); return super.onRefresh();
@@ -57,41 +62,29 @@ abstract class ReplyController extends CommonController {
@override @override
bool customHandleResponse(Success response) { bool customHandleResponse(Success response) {
List<ReplyItemModel> replies = response.response.replies; MainListReply replies = response.response;
if (!isLogin) { if (cursor == null) {
nextOffset = response.response.cursor.paginationReply.nextOffset ?? ""; count.value = replies.subjectControl.count.toInt();
hasUpTop = replies.hasUpTop();
if (replies.hasUpTop()) {
replies.replies.insert(0, replies.upTop);
}
} }
if (replies.isNotEmpty) { cursor = replies.cursor;
if (replies.replies.isNotEmpty) {
noMore.value = '加载中...'; noMore.value = '加载中...';
if (replies.cursor.isEnd) {
/// 第一页回复数小于20
if (currentPage == 1 && replies.length < 18) {
noMore.value = '没有更多了'; noMore.value = '没有更多了';
} }
} else { } else {
// 未登录状态replies可能返回null // 未登录状态replies可能返回null
noMore.value = nextOffset == "" && currentPage == 1 ? '还没有评论' : '没有更多了'; noMore.value = currentPage == 1 ? '还没有评论' : '没有更多了';
} }
if (currentPage == 1) { if (currentPage != 1) {
// 添加置顶回复 List<ReplyInfo> list = loadingState.value is Success
if (response.response.upper.top != null) { ? (loadingState.value as Success).response.replies
final bool flag = response.response.topReplies.any( : <ReplyInfo>[];
(ReplyItemModel reply) => replies.replies.insertAll(0, list);
reply.rpid == response.response.upper.top.rpid) as bool;
if (!flag) {
replies.insert(0, response.response.upper.top);
}
}
replies.insertAll(0, response.response.topReplies);
count.value = !isLogin
? response.response.cursor.allCount
: response.response.page.count ?? 0;
} else {
replies.insertAll(
0,
loadingState.value is Success
? (loadingState.value as Success).response
: <ReplyItemModel>[]);
} }
loadingState.value = LoadingState.success(replies); loadingState.value = LoadingState.success(replies);
return true; return true;
@@ -104,9 +97,11 @@ abstract class ReplyController extends CommonController {
switch (sortType) { switch (sortType) {
case ReplySortType.time: case ReplySortType.time:
sortType = ReplySortType.like; sortType = ReplySortType.like;
mode = Mode.MAIN_LIST_HOT;
break; break;
case ReplySortType.like: case ReplySortType.like:
sortType = ReplySortType.time; sortType = ReplySortType.time;
mode = Mode.MAIN_LIST_TIME;
break; break;
default: default:
} }

View File

@@ -1,8 +1,10 @@
import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart';
import 'package:PiliPalaX/http/loading_state.dart'; import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/pages/common/reply_controller.dart'; import 'package:PiliPalaX/pages/common/reply_controller.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:PiliPalaX/http/html.dart'; import 'package:PiliPalaX/http/html.dart';
import 'package:PiliPalaX/http/reply.dart'; import 'package:PiliPalaX/http/reply.dart';
import 'package:fixnum/fixnum.dart' as $fixnum;
class DynamicDetailController extends ReplyController { class DynamicDetailController extends ReplyController {
DynamicDetailController(this.oid, this.type); DynamicDetailController(this.oid, this.type);
@@ -32,13 +34,23 @@ class DynamicDetailController extends ReplyController {
queryData(); queryData();
} }
// @override
// Future<LoadingState> customGetData() => ReplyHttp.replyList(
// isLogin: isLogin,
// oid: oid!,
// nextOffset: nextOffset,
// type: type!,
// sort: sortType.index,
// page: currentPage,
// );
@override @override
Future<LoadingState> customGetData() => ReplyHttp.replyList( Future<LoadingState> customGetData() => ReplyHttp.replyListGrpc(
isLogin: isLogin, type: type ?? 1,
oid: oid!, oid: oid!,
nextOffset: nextOffset, cursor: CursorReq(
type: type!, next: cursor?.next ?? $fixnum.Int64(0),
sort: sortType.index, mode: mode,
page: currentPage, ),
); );
} }

View File

@@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:math'; import 'dart:math';
import 'package:PiliPalaX/http/loading_state.dart'; import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/pages/video/detail/reply/widgets/reply_item_grpc.dart';
import 'package:easy_debounce/easy_throttle.dart'; import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
@@ -105,20 +106,21 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
} }
// 查看二级评论 // 查看二级评论
void replyReply(replyItem) { void replyReply(replyItem, id) {
int oid = replyItem.oid; int oid = replyItem.oid.toInt();
int rpid = replyItem.rpid!; int rpid = replyItem.id.toInt()!;
Get.to( Get.to(
() => Scaffold( () => Scaffold(
appBar: AppBar( appBar: AppBar(
titleSpacing: 0, titleSpacing: 0,
centerTitle: false, centerTitle: false,
title: Text( title: Text(
'评论详情${replyItem.rcount > 0 ? '${replyItem.rcount}' : ''}', '评论详情',
style: Theme.of(context).textTheme.titleMedium, style: Theme.of(context).textTheme.titleMedium,
), ),
), ),
body: VideoReplyReplyPanel( body: VideoReplyReplyPanel(
id: id,
oid: oid, oid: oid,
rpid: rpid, rpid: rpid,
source: 'dynamic', source: 'dynamic',
@@ -369,7 +371,7 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
? SliverList( ? SliverList(
delegate: SliverChildBuilderDelegate( delegate: SliverChildBuilderDelegate(
(context, index) { (context, index) {
if (index == loadingState.response.length) { if (index == loadingState.response.replies.length) {
return Container( return Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom), bottom: MediaQuery.of(context).padding.bottom),
@@ -387,8 +389,8 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
), ),
); );
} else { } else {
return ReplyItem( return ReplyItemGrpc(
replyItem: loadingState.response[index], replyItem: loadingState.response.replies[index],
showReplyRow: true, showReplyRow: true,
replyLevel: '1', replyLevel: '1',
replyReply: replyReply, replyReply: replyReply,
@@ -396,15 +398,17 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
onReply: () { onReply: () {
_dynamicDetailController.onReply( _dynamicDetailController.onReply(
context, context,
replyItem: loadingState.response[index], replyItem: loadingState.response.replies[index],
index: index, index: index,
); );
}, },
onDelete: _dynamicDetailController.onMDelete, onDelete: _dynamicDetailController.onMDelete,
isTop: _dynamicDetailController.hasUpTop && index == 0,
upMid: loadingState.response.subjectControl.upMid,
); );
} }
}, },
childCount: loadingState.response.length + 1, childCount: loadingState.response.replies.length + 1,
), ),
) )
: loadingState is Error : loadingState is Error

View File

@@ -1,8 +1,10 @@
import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart';
import 'package:PiliPalaX/http/loading_state.dart'; import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/pages/common/reply_controller.dart'; import 'package:PiliPalaX/pages/common/reply_controller.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:PiliPalaX/http/html.dart'; import 'package:PiliPalaX/http/html.dart';
import 'package:PiliPalaX/http/reply.dart'; import 'package:PiliPalaX/http/reply.dart';
import 'package:fixnum/fixnum.dart' as $fixnum;
class HtmlRenderController extends ReplyController { class HtmlRenderController extends ReplyController {
late String id; late String id;
@@ -42,13 +44,23 @@ class HtmlRenderController extends ReplyController {
} }
} }
// @override
// Future<LoadingState> customGetData() => ReplyHttp.replyList(
// isLogin: isLogin,
// oid: oid.value,
// nextOffset: nextOffset,
// type: type,
// sort: sortType.index,
// page: currentPage,
// );
@override @override
Future<LoadingState> customGetData() => ReplyHttp.replyList( Future<LoadingState> customGetData() => ReplyHttp.replyListGrpc(
isLogin: isLogin,
oid: oid.value,
nextOffset: nextOffset,
type: type, type: type,
sort: sortType.index, oid: oid.value,
page: currentPage, cursor: CursorReq(
next: cursor?.next ?? $fixnum.Int64(0),
mode: mode,
),
); );
} }

View File

@@ -3,6 +3,7 @@ import 'dart:math';
import 'package:PiliPalaX/common/widgets/article_content.dart'; import 'package:PiliPalaX/common/widgets/article_content.dart';
import 'package:PiliPalaX/common/widgets/http_error.dart'; import 'package:PiliPalaX/common/widgets/http_error.dart';
import 'package:PiliPalaX/http/loading_state.dart'; import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/pages/video/detail/reply/widgets/reply_item_grpc.dart';
import 'package:easy_debounce/easy_throttle.dart'; import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
@@ -108,20 +109,21 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
} }
} }
void replyReply(replyItem) { void replyReply(replyItem, id) {
int oid = replyItem.oid; int oid = replyItem.oid.toInt();
int rpid = replyItem.rpid!; int rpid = replyItem.id.toInt();
Get.to( Get.to(
() => Scaffold( () => Scaffold(
appBar: AppBar( appBar: AppBar(
titleSpacing: 0, titleSpacing: 0,
centerTitle: false, centerTitle: false,
title: Text( title: Text(
'评论详情${replyItem.rcount > 0 ? '${replyItem.rcount}' : ''}', '评论详情',
style: Theme.of(context).textTheme.titleMedium, style: Theme.of(context).textTheme.titleMedium,
), ),
), ),
body: VideoReplyReplyPanel( body: VideoReplyReplyPanel(
id: id,
oid: oid, oid: oid,
rpid: rpid, rpid: rpid,
source: 'dynamic', source: 'dynamic',
@@ -330,9 +332,9 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
Widget replyList(LoadingState loadingState) { Widget replyList(LoadingState loadingState) {
return loadingState is Success return loadingState is Success
? SliverList.builder( ? SliverList.builder(
itemCount: loadingState.response.length + 1, itemCount: loadingState.response.replies.length + 1,
itemBuilder: (context, index) { itemBuilder: (context, index) {
if (index == loadingState.response.length) { if (index == loadingState.response.replies.length) {
return Container( return Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom), bottom: MediaQuery.of(context).padding.bottom),
@@ -350,8 +352,8 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
), ),
); );
} else { } else {
return ReplyItem( return ReplyItemGrpc(
replyItem: loadingState.response[index], replyItem: loadingState.response.replies[index],
showReplyRow: true, showReplyRow: true,
replyLevel: '1', replyLevel: '1',
replyReply: replyReply, replyReply: replyReply,
@@ -359,11 +361,13 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
onReply: () { onReply: () {
_htmlRenderCtr.onReply( _htmlRenderCtr.onReply(
context, context,
replyItem: loadingState.response[index], replyItem: loadingState.response.replies[index],
index: index, index: index,
); );
}, },
onDelete: _htmlRenderCtr.onMDelete, onDelete: _htmlRenderCtr.onMDelete,
isTop: _htmlRenderCtr.hasUpTop && index == 0,
upMid: loadingState.response.subjectControl.upMid,
); );
} }
}, },

View File

@@ -1,10 +1,7 @@
import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart'; import 'package:PiliPalaX/grpc/app/main/community/reply/v1/reply.pb.dart';
import 'package:PiliPalaX/http/loading_state.dart'; import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/models/common/reply_sort_type.dart';
import 'package:PiliPalaX/pages/common/reply_controller.dart'; import 'package:PiliPalaX/pages/common/reply_controller.dart';
import 'package:PiliPalaX/http/reply.dart'; import 'package:PiliPalaX/http/reply.dart';
import 'package:PiliPalaX/utils/feed_back.dart';
import 'package:easy_debounce/easy_throttle.dart';
import 'package:fixnum/fixnum.dart' as $fixnum; import 'package:fixnum/fixnum.dart' as $fixnum;
class VideoReplyController extends ReplyController { class VideoReplyController extends ReplyController {
@@ -20,76 +17,6 @@ class VideoReplyController extends ReplyController {
// rpid 请求楼中楼回复 // rpid 请求楼中楼回复
String? rpid; String? rpid;
CursorReply? cursor;
Mode mode = Mode.MAIN_LIST_HOT;
bool hasUpTop = false;
@override
Future onRefresh() {
cursor = null;
return super.onRefresh();
}
@override
queryBySort() {
EasyThrottle.throttle('queryBySort', const Duration(seconds: 1), () {
feedBack();
switch (sortType) {
case ReplySortType.time:
sortType = ReplySortType.like;
mode = Mode.MAIN_LIST_HOT;
break;
case ReplySortType.like:
sortType = ReplySortType.time;
mode = Mode.MAIN_LIST_TIME;
break;
default:
}
sortTypeTitle.value = sortType.titles;
sortTypeLabel.value = sortType.labels;
nextOffset = "";
noMore.value = '';
loadingState.value = LoadingState.loading();
onRefresh();
});
}
@override
bool customHandleResponse(Success response) {
MainListReply replies = response.response;
if (cursor == null) {
count.value = replies.subjectControl.count.toInt();
hasUpTop = replies.hasUpTop();
if (replies.hasUpTop()) {
replies.replies.insert(0, replies.upTop);
}
}
cursor = replies.cursor;
// replies.replies.clear();
// showDialog(
// context: Get.context!,
// builder: (_) => AlertDialog(
// content: SelectableText(jsonEncode(replies.toProto3Json())),
// ));
if (replies.replies.isNotEmpty) {
noMore.value = '加载中...';
if (replies.cursor.isEnd) {
noMore.value = '没有更多了';
}
} else {
// 未登录状态replies可能返回null
noMore.value = currentPage == 1 ? '还没有评论' : '没有更多了';
}
if (currentPage != 1) {
List<ReplyInfo> list = loadingState.value is Success
? (loadingState.value as Success).response.replies
: <ReplyInfo>[];
replies.replies.insertAll(0, list);
}
loadingState.value = LoadingState.success(replies);
return true;
}
@override @override
Future<LoadingState> customGetData() => ReplyHttp.replyListGrpc( Future<LoadingState> customGetData() => ReplyHttp.replyListGrpc(
oid: aid!, oid: aid!,

View File

@@ -224,7 +224,6 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
return ReplyItemGrpc( return ReplyItemGrpc(
replyItem: loadingState.response.replies[index], replyItem: loadingState.response.replies[index],
showReplyRow: true, showReplyRow: true,
isTop: _videoReplyController.hasUpTop && index == 0,
replyLevel: replyLevel, replyLevel: replyLevel,
replyReply: widget.replyReply, replyReply: widget.replyReply,
replyType: ReplyType.video, replyType: ReplyType.video,
@@ -236,6 +235,7 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
); );
}, },
onDelete: _videoReplyController.onMDelete, onDelete: _videoReplyController.onMDelete,
isTop: _videoReplyController.hasUpTop && index == 0,
upMid: loadingState.response.subjectControl.upMid, upMid: loadingState.response.subjectControl.upMid,
); );
} }

View File

@@ -131,6 +131,7 @@ class VideoReplyReplyController extends CommonController {
@override @override
Future<LoadingState> customGetData() => ReplyHttp.replyReplyListGrpc( Future<LoadingState> customGetData() => ReplyHttp.replyReplyListGrpc(
type: replyType.index,
oid: aid!, oid: aid!,
root: int.parse(rpid!), root: int.parse(rpid!),
cursor: CursorReq( cursor: CursorReq(

View File

@@ -4,7 +4,6 @@ import 'dart:math';
import 'package:PiliPalaX/common/constants.dart'; import 'package:PiliPalaX/common/constants.dart';
import 'package:PiliPalaX/common/widgets/list_sheet.dart'; import 'package:PiliPalaX/common/widgets/list_sheet.dart';
import 'package:PiliPalaX/grpc/grpc_repo.dart';
import 'package:PiliPalaX/http/loading_state.dart'; import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/models/bangumi/info.dart'; import 'package:PiliPalaX/models/bangumi/info.dart';
import 'package:PiliPalaX/models/common/reply_type.dart'; import 'package:PiliPalaX/models/common/reply_type.dart';