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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:PiliPlus/common/skeleton/whisper_item.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/msg/session.dart';
|
||||
import 'package:PiliPlus/pages/whisper/controller.dart';
|
||||
import 'package:PiliPlus/pages/whisper/widgets/item.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -38,7 +38,7 @@ class _WhisperPageState extends State<WhisperPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState<List<SessionList>?> loadingState) {
|
||||
Widget _buildBody(LoadingState<List<Session>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverList.builder(
|
||||
itemCount: 12,
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/badge.dart';
|
||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/models/msg/session.dart';
|
||||
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart'
|
||||
show Session, UnreadStyle;
|
||||
import 'package:PiliPlus/models/common/badge_type.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -13,32 +19,19 @@ class WhisperSessionItem extends StatelessWidget {
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final SessionList item;
|
||||
final Session item;
|
||||
final Function(bool isTop, int? talkerId) onSetTop;
|
||||
final ValueChanged<int?> onRemove;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
dynamic content = item.lastMsg?.content;
|
||||
Map? vipInfo = item.sessionInfo.hasVipInfo()
|
||||
? jsonDecode(item.sessionInfo.vipInfo)
|
||||
: null;
|
||||
final ThemeData theme = Theme.of(context);
|
||||
if (content == null || content == "") {
|
||||
content = '不支持的消息类型';
|
||||
} else {
|
||||
dynamic msg = content['text'] ??
|
||||
content['content'] ??
|
||||
content['title'] ??
|
||||
content['reply_content'];
|
||||
if (msg == null) {
|
||||
if (content['imageType'] != null) {
|
||||
msg = '[图片消息]';
|
||||
}
|
||||
}
|
||||
content = msg ?? content.toString();
|
||||
}
|
||||
|
||||
return ListTile(
|
||||
tileColor: item.topTs == 0 ? null : theme.colorScheme.onInverseSurface,
|
||||
tileColor: item.isPinned ? theme.colorScheme.onInverseSurface : null,
|
||||
onLongPress: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -53,10 +46,13 @@ class WhisperSessionItem extends StatelessWidget {
|
||||
dense: true,
|
||||
onTap: () {
|
||||
Get.back();
|
||||
onSetTop(item.topTs != 0, item.talkerId);
|
||||
onSetTop(
|
||||
item.isPinned,
|
||||
item.id.privateId.talkerUid.toInt(),
|
||||
);
|
||||
},
|
||||
title: Text(
|
||||
item.topTs == 0 ? '置顶' : '移除置顶',
|
||||
item.isPinned ? '移除置顶' : '置顶',
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
@@ -64,7 +60,7 @@ class WhisperSessionItem extends StatelessWidget {
|
||||
dense: true,
|
||||
onTap: () {
|
||||
Get.back();
|
||||
onRemove(item.talkerId);
|
||||
onRemove(item.id.privateId.talkerUid.toInt());
|
||||
},
|
||||
title: const Text(
|
||||
'删除',
|
||||
@@ -82,11 +78,12 @@ class WhisperSessionItem extends StatelessWidget {
|
||||
Get.toNamed(
|
||||
'/whisperDetail',
|
||||
parameters: {
|
||||
'talkerId': '${item.talkerId}',
|
||||
'name': item.accountInfo?.name ?? '',
|
||||
'face': item.accountInfo?.face ?? '',
|
||||
if (item.accountInfo?.mid != null)
|
||||
'mid': '${item.accountInfo?.mid}',
|
||||
'talkerId': item.id.privateId.talkerUid.toString(),
|
||||
'name': item.sessionInfo.sessionName,
|
||||
'face': item.sessionInfo.avatar.fallbackLayers.layers.first.resource
|
||||
.resImage.imageSrc.remote.url,
|
||||
if (item.sessionInfo.avatar.hasMid())
|
||||
'mid': item.sessionInfo.avatar.mid.toString(),
|
||||
},
|
||||
);
|
||||
},
|
||||
@@ -96,19 +93,23 @@ class WhisperSessionItem extends StatelessWidget {
|
||||
width: 45,
|
||||
height: 45,
|
||||
type: 'avatar',
|
||||
src: item.accountInfo?.face ?? "",
|
||||
src: item.sessionInfo.avatar.fallbackLayers.layers.first
|
||||
.resource.resImage.imageSrc.remote.url,
|
||||
);
|
||||
return GestureDetector(
|
||||
onTap: item.accountInfo?.mid != null
|
||||
onTap: item.sessionInfo.avatar.hasMid()
|
||||
? () {
|
||||
Get.toNamed(
|
||||
'/member?mid=${item.accountInfo!.mid}',
|
||||
'/member?mid=${item.sessionInfo.avatar.mid}',
|
||||
);
|
||||
}
|
||||
: null,
|
||||
child: item.unreadCount != null && item.unreadCount! > 0
|
||||
child: item.hasUnread() &&
|
||||
item.unread.style != UnreadStyle.UNREAD_STYLE_NONE
|
||||
? Badge(
|
||||
label: Text(" ${item.unreadCount} "),
|
||||
label: item.unread.style == UnreadStyle.UNREAD_STYLE_NUMBER
|
||||
? Text(" ${item.unread.number} ")
|
||||
: null,
|
||||
alignment: Alignment.topRight,
|
||||
child: buildAvatar(),
|
||||
)
|
||||
@@ -116,17 +117,45 @@ class WhisperSessionItem extends StatelessWidget {
|
||||
);
|
||||
},
|
||||
),
|
||||
title: Text(item.accountInfo?.name ?? ""),
|
||||
title: Row(
|
||||
children: [
|
||||
Text(
|
||||
item.sessionInfo.sessionName,
|
||||
style: TextStyle(
|
||||
color: vipInfo?['status'] != null &&
|
||||
vipInfo!['status'] > 0 &&
|
||||
vipInfo['type'] == 2
|
||||
? context.vipColor
|
||||
: null,
|
||||
),
|
||||
),
|
||||
if (item.sessionInfo.userLabel.style.borderedLabel.hasText()) ...[
|
||||
const SizedBox(width: 5),
|
||||
PBadge(
|
||||
isStack: false,
|
||||
type: PBadgeType.line_secondary,
|
||||
fontSize: 10,
|
||||
isBold: false,
|
||||
text: item.sessionInfo.userLabel.style.borderedLabel.text,
|
||||
),
|
||||
],
|
||||
if (item.sessionInfo.isLive) ...[
|
||||
const SizedBox(width: 5),
|
||||
Image.asset('assets/images/live/live.gif', height: 15),
|
||||
],
|
||||
],
|
||||
),
|
||||
subtitle: Text(
|
||||
'$content',
|
||||
item.msgSummary.rawMsg,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.labelMedium!
|
||||
.copyWith(color: theme.colorScheme.outline),
|
||||
),
|
||||
trailing: item.lastMsg?.timestamp != null
|
||||
trailing: item.hasTimestamp()
|
||||
? Text(
|
||||
Utils.dateFormat(item.lastMsg!.timestamp, formatType: "day"),
|
||||
Utils.dateFormat((item.timestamp ~/ 1000000).toInt(),
|
||||
formatType: "day"),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: theme.colorScheme.outline,
|
||||
|
||||
Reference in New Issue
Block a user