refa: whisper page

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-05-06 21:38:46 +08:00
parent 661e7bfa78
commit b19c718a2a
30 changed files with 8764 additions and 193 deletions

View File

@@ -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,