mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refa: whisper page
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,21 +1,20 @@
|
||||
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/msg.dart';
|
||||
import 'package:PiliPlus/models/msg/account.dart';
|
||||
import 'package:PiliPlus/models/msg/msgfeed_unread.dart';
|
||||
import 'package:PiliPlus/models/msg/session.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:protobuf/protobuf.dart' show PbMap;
|
||||
|
||||
class WhisperController
|
||||
extends CommonListController<List<SessionList>?, SessionList> {
|
||||
extends CommonListController<SessionMainReply, Session> {
|
||||
late final List msgFeedTopItems;
|
||||
late final RxList<int> unreadCounts;
|
||||
|
||||
int? endTs;
|
||||
PbMap<int, Offset>? offset;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -65,37 +64,20 @@ class WhisperController
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<List<SessionList>?>> customGetData() =>
|
||||
MsgHttp.sessionList(endTs: endTs);
|
||||
|
||||
@override
|
||||
bool customHandleResponse(
|
||||
bool isRefresh, Success<List<SessionList>?> response) {
|
||||
endTs = response.response?.lastOrNull?.sessionTs;
|
||||
List<SessionList>? dataList = response.response;
|
||||
if (dataList.isNullOrEmpty) {
|
||||
isEnd = true;
|
||||
if (isRefresh) {
|
||||
loadingState.value = LoadingState<List<SessionList>?>.success(dataList);
|
||||
}
|
||||
isLoading = false;
|
||||
return true;
|
||||
}
|
||||
queryAccountList(dataList!).then((_) {
|
||||
if (isRefresh) {
|
||||
loadingState.value = LoadingState<List<SessionList>?>.success(dataList);
|
||||
} else if (loadingState.value is Success) {
|
||||
loadingState.value.data!.addAll(dataList);
|
||||
loadingState.refresh();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
List<Session>? getDataList(SessionMainReply response) {
|
||||
offset = response.paginationParams.offsets;
|
||||
isEnd = !response.paginationParams.hasMore;
|
||||
return response.sessions;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<SessionMainReply>> customGetData() =>
|
||||
MsgHttp.sessionMain(offset: offset);
|
||||
|
||||
@override
|
||||
Future<void> onRefresh() {
|
||||
offset = null;
|
||||
queryMsgFeedUnread();
|
||||
endTs = null;
|
||||
return super.onRefresh();
|
||||
}
|
||||
|
||||
@@ -116,11 +98,10 @@ class WhisperController
|
||||
opType: isTop ? 1 : 0,
|
||||
);
|
||||
if (res['status']) {
|
||||
List<SessionList> list = (loadingState.value as Success).response;
|
||||
list[index].topTs = isTop ? 0 : 1;
|
||||
List<Session> list = (loadingState.value as Success).response;
|
||||
list[index].isPinned = isTop ? false : true;
|
||||
if (!isTop) {
|
||||
SessionList item = list.removeAt(index);
|
||||
list.insert(0, item);
|
||||
list.insert(0, list.removeAt(index));
|
||||
}
|
||||
loadingState.refresh();
|
||||
SmartDialog.showToast('${isTop ? '移除' : ''}置顶成功');
|
||||
@@ -130,26 +111,10 @@ class WhisperController
|
||||
}
|
||||
|
||||
void onTap(int index) {
|
||||
List<SessionList> list = (loadingState.value as Success).response;
|
||||
list[index].unreadCount = 0;
|
||||
loadingState.refresh();
|
||||
}
|
||||
|
||||
Future queryAccountList(List<SessionList> sessionList) async {
|
||||
List<int?> midsList = sessionList.map((e) => e.talkerId).toList();
|
||||
var res = await MsgHttp.accountList(midsList.join(','));
|
||||
if (res['status']) {
|
||||
List<AccountListModel> accountList = res['data'];
|
||||
Map<int, AccountListModel> accountMap = {};
|
||||
for (AccountListModel item in accountList) {
|
||||
accountMap[item.mid!] = item;
|
||||
}
|
||||
for (SessionList item in sessionList) {
|
||||
AccountListModel? accountInfo = accountMap[item.talkerId];
|
||||
if (accountInfo != null) {
|
||||
item.accountInfo = accountInfo;
|
||||
}
|
||||
}
|
||||
Session item = loadingState.value.data![index];
|
||||
if (item.hasUnread()) {
|
||||
item.clearUnread();
|
||||
loadingState.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user