feat: 会话移除

This commit is contained in:
guozhigq
2024-06-15 17:03:52 +08:00
parent e051e77856
commit f62eae55d2
7 changed files with 105 additions and 23 deletions

View File

@ -71,4 +71,10 @@ class WhisperController extends GetxController {
sessionList.insert(0, currentItem);
sessionList.refresh();
}
// 移除会话
void removeSessionMsg(int talkerId) {
sessionList.removeWhere((p0) => p0.talkerId == talkerId);
sessionList.refresh();
}
}

View File

@ -204,6 +204,8 @@ class SessionItem extends StatelessWidget {
Widget build(BuildContext context) {
final String heroTag = Utils.makeHeroTag(sessionItem.accountInfo.mid);
final content = sessionItem.lastMsg.content;
final msgStatus = sessionItem.lastMsg.msgStatus;
return ListTile(
onTap: () {
sessionItem.unreadCount = 0;
@ -235,13 +237,15 @@ class SessionItem extends StatelessWidget {
),
title: Text(sessionItem.accountInfo.name),
subtitle: Text(
content != null && content != ''
? (content['text'] ??
content['content'] ??
content['title'] ??
content['reply_content'] ??
'不支持的消息类型')
: '不支持的消息类型',
msgStatus == 1
? '你撤回了一条消息'
: content != null && content != ''
? (content['text'] ??
content['content'] ??
content['title'] ??
content['reply_content'] ??
'不支持的消息类型')
: '不支持的消息类型',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)

View File

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
@ -105,4 +106,41 @@ class WhisperDetailController extends GetxController {
SmartDialog.showToast(result['msg']);
}
}
void removeSession(context) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
clipBehavior: Clip.hardEdge,
title: const Text('提示'),
content: const Text('确认清空会话内容并移除会话?'),
actions: [
TextButton(
onPressed: Get.back,
child: Text(
'取消',
style: TextStyle(color: Theme.of(context).colorScheme.outline),
),
),
TextButton(
onPressed: () async {
var res = await MsgHttp.removeSession(talkerId: talkerId);
if (res['status']) {
SmartDialog.showToast('操作成功');
try {
late final WhisperController whisperController =
Get.find<WhisperController>();
whisperController.removeSessionMsg(talkerId!);
Get.back();
} catch (_) {}
}
},
child: const Text('确认'),
),
],
);
},
);
}
}

View File

@ -145,7 +145,7 @@ class _WhisperDetailPageState extends State<WhisperDetailPage>
src: _whisperDetailController.face,
),
),
const SizedBox(width: 6),
const SizedBox(width: 10),
Text(
_whisperDetailController.name,
style: Theme.of(context).textTheme.titleMedium,
@ -158,12 +158,14 @@ class _WhisperDetailPageState extends State<WhisperDetailPage>
),
),
actions: [
IconButton(
onPressed: () {},
icon: const Icon(
Icons.more_vert_outlined,
size: 20,
),
PopupMenuButton(
icon: const Icon(Icons.more_vert_outlined, size: 20),
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
PopupMenuItem(
onTap: () => _whisperDetailController.removeSession(context),
child: const Text('关闭会话'),
)
],
),
const SizedBox(width: 14)
],

View File

@ -389,8 +389,19 @@ class ChatItem extends StatelessWidget {
? messageContent(context)
: isRevoke
? const SizedBox()
: Padding(
padding: const EdgeInsets.only(top: 12),
: Container(
padding: const EdgeInsets.only(top: 6, bottom: 6),
decoration: BoxDecoration(
border: Border(
left: item.msgStatus == 1 && !isOwner
? BorderSide(
width: 4, color: Theme.of(context).dividerColor)
: BorderSide.none,
right: item.msgStatus == 1 && isOwner
? BorderSide(
width: 4, color: Theme.of(context).primaryColor)
: BorderSide.none,
)),
child: Row(
mainAxisAlignment: !isOwner
? MainAxisAlignment.start