mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-27 12:36:27 +08:00
update msg api (#375)
This commit is contained in:
committed by
GitHub
parent
432c5133e6
commit
d5a244ce7f
@@ -5,38 +5,33 @@ import 'package:PiliPlus/http/msg.dart';
|
||||
import '../../../models/msg/msgfeed_sys_msg.dart';
|
||||
|
||||
class SysMsgController extends GetxController {
|
||||
static const pageSize = 20;
|
||||
RxList<SystemNotifyList> msgFeedSysMsgList = <SystemNotifyList>[].obs;
|
||||
bool isLoading = false;
|
||||
int cursor = -1;
|
||||
int cursorTime = -1;
|
||||
bool isEnd = false;
|
||||
|
||||
Future queryMsgFeedSysMsg() async {
|
||||
if (isLoading) return;
|
||||
isLoading = true;
|
||||
var resUserNotify = await MsgHttp.msgFeedSysUserNotify();
|
||||
var resUnifiedNotify = await MsgHttp.msgFeedSysUnifiedNotify();
|
||||
final res = await MsgHttp.msgFeedNotify(cursor: cursor, pageSize: pageSize);
|
||||
isLoading = false;
|
||||
List<SystemNotifyList> systemNotifyList = [];
|
||||
if (resUserNotify['status']) {
|
||||
MsgFeedSysMsg data = MsgFeedSysMsg.fromJson(resUserNotify['data']);
|
||||
if (data.systemNotifyList != null) {
|
||||
systemNotifyList.addAll(data.systemNotifyList!);
|
||||
if (res['status']) {
|
||||
final data = (res['data'] as List)
|
||||
.map((i) => SystemNotifyList.fromJson(i))
|
||||
.toList();
|
||||
isEnd = data.length + 1 < pageSize; // data.length会比pageSize小1
|
||||
if (data.isNotEmpty) {
|
||||
if (cursor == -1) {
|
||||
msgFeedSysMsgList.assignAll(data);
|
||||
} else {
|
||||
msgFeedSysMsgList.addAll(data);
|
||||
}
|
||||
cursor = data.last.cursor ?? -1;
|
||||
msgSysUpdateCursor(msgFeedSysMsgList.first.cursor!);
|
||||
}
|
||||
}
|
||||
if (resUnifiedNotify['status']) {
|
||||
MsgFeedSysMsg data = MsgFeedSysMsg.fromJson(resUnifiedNotify['data']);
|
||||
if (data.systemNotifyList != null) {
|
||||
systemNotifyList.addAll(data.systemNotifyList!);
|
||||
}
|
||||
}
|
||||
if (systemNotifyList.isNotEmpty) {
|
||||
systemNotifyList.sort((a, b) => b.cursor!.compareTo(a.cursor!));
|
||||
msgFeedSysMsgList.assignAll(systemNotifyList);
|
||||
msgSysUpdateCursor(msgFeedSysMsgList.first.cursor!);
|
||||
} else {
|
||||
SmartDialog.showToast(
|
||||
"UserNotify: ${resUserNotify['msg']} UnifiedNotify: ${resUnifiedNotify['msg']}");
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +53,6 @@ class SysMsgController extends GetxController {
|
||||
|
||||
Future onRefresh() async {
|
||||
cursor = -1;
|
||||
cursorTime = -1;
|
||||
queryMsgFeedSysMsg();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user