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

View File

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

View File

@@ -28,6 +28,10 @@ abstract class ReplyController extends CommonController {
bool isLogin = GStorage.userInfo.get('userInfoCache') != null;
CursorReply? cursor;
Mode mode = Mode.MAIN_LIST_HOT;
bool hasUpTop = false;
@override
void onInit() {
super.onInit();
@@ -44,6 +48,7 @@ abstract class ReplyController extends CommonController {
@override
Future onRefresh() {
cursor = null;
nextOffset = '';
noMore.value = '';
return super.onRefresh();
@@ -57,41 +62,29 @@ abstract class ReplyController extends CommonController {
@override
bool customHandleResponse(Success response) {
List<ReplyItemModel> replies = response.response.replies;
if (!isLogin) {
nextOffset = response.response.cursor.paginationReply.nextOffset ?? "";
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);
}
}
if (replies.isNotEmpty) {
cursor = replies.cursor;
if (replies.replies.isNotEmpty) {
noMore.value = '加载中...';
/// 第一页回复数小于20
if (currentPage == 1 && replies.length < 18) {
if (replies.cursor.isEnd) {
noMore.value = '没有更多了';
}
} else {
// 未登录状态replies可能返回null
noMore.value = nextOffset == "" && currentPage == 1 ? '还没有评论' : '没有更多了';
noMore.value = currentPage == 1 ? '还没有评论' : '没有更多了';
}
if (currentPage == 1) {
// 添加置顶回复
if (response.response.upper.top != null) {
final bool flag = response.response.topReplies.any(
(ReplyItemModel reply) =>
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>[]);
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;
@@ -104,9 +97,11 @@ abstract class ReplyController extends CommonController {
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:
}

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

View File

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

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/pages/common/reply_controller.dart';
import 'package:get/get.dart';
import 'package:PiliPalaX/http/html.dart';
import 'package:PiliPalaX/http/reply.dart';
import 'package:fixnum/fixnum.dart' as $fixnum;
class HtmlRenderController extends ReplyController {
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
Future<LoadingState> customGetData() => ReplyHttp.replyList(
isLogin: isLogin,
oid: oid.value,
nextOffset: nextOffset,
Future<LoadingState> customGetData() => ReplyHttp.replyListGrpc(
type: type,
sort: sortType.index,
page: currentPage,
oid: oid.value,
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/http_error.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:flutter/material.dart';
import 'package:flutter/rendering.dart';
@@ -108,20 +109,21 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
}
}
void replyReply(replyItem) {
int oid = replyItem.oid;
int rpid = replyItem.rpid!;
void replyReply(replyItem, id) {
int oid = replyItem.oid.toInt();
int rpid = replyItem.id.toInt();
Get.to(
() => Scaffold(
appBar: AppBar(
titleSpacing: 0,
centerTitle: false,
title: Text(
'评论详情${replyItem.rcount > 0 ? '${replyItem.rcount}' : ''}',
'评论详情',
style: Theme.of(context).textTheme.titleMedium,
),
),
body: VideoReplyReplyPanel(
id: id,
oid: oid,
rpid: rpid,
source: 'dynamic',
@@ -330,9 +332,9 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
Widget replyList(LoadingState loadingState) {
return loadingState is Success
? SliverList.builder(
itemCount: loadingState.response.length + 1,
itemCount: loadingState.response.replies.length + 1,
itemBuilder: (context, index) {
if (index == loadingState.response.length) {
if (index == loadingState.response.replies.length) {
return Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom),
@@ -350,8 +352,8 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
),
);
} else {
return ReplyItem(
replyItem: loadingState.response[index],
return ReplyItemGrpc(
replyItem: loadingState.response.replies[index],
showReplyRow: true,
replyLevel: '1',
replyReply: replyReply,
@@ -359,11 +361,13 @@ class _HtmlRenderPageState extends State<HtmlRenderPage>
onReply: () {
_htmlRenderCtr.onReply(
context,
replyItem: loadingState.response[index],
replyItem: loadingState.response.replies[index],
index: index,
);
},
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/http/loading_state.dart';
import 'package:PiliPalaX/models/common/reply_sort_type.dart';
import 'package:PiliPalaX/pages/common/reply_controller.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;
class VideoReplyController extends ReplyController {
@@ -20,76 +17,6 @@ class VideoReplyController extends ReplyController {
// 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
Future<LoadingState> customGetData() => ReplyHttp.replyListGrpc(
oid: aid!,

View File

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

View File

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

View File

@@ -4,7 +4,6 @@ import 'dart:math';
import 'package:PiliPalaX/common/constants.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/models/bangumi/info.dart';
import 'package:PiliPalaX/models/common/reply_type.dart';