feat: 会话移除
This commit is contained in:
@ -535,4 +535,8 @@ class Api {
|
||||
|
||||
/// 搜索结果计数
|
||||
static const String searchCount = '/x/web-interface/wbi/search/all/v2';
|
||||
|
||||
/// 关闭会话
|
||||
static const String removeSession =
|
||||
'${HttpString.tUrl}/session_svr/v1/session_svr/remove_session';
|
||||
}
|
||||
|
@ -124,13 +124,7 @@ class MsgHttp {
|
||||
'data': res.data['data'],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
'status': false,
|
||||
'date': [],
|
||||
'msg': "message: ${res.data['message']},"
|
||||
" msg: ${res.data['msg']},"
|
||||
" code: ${res.data['code']}",
|
||||
};
|
||||
return {'status': false, 'date': [], 'msg': res.data['message']};
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,4 +202,27 @@ class MsgHttp {
|
||||
}
|
||||
return s.join();
|
||||
}
|
||||
|
||||
static Future removeSession({
|
||||
int? talkerId,
|
||||
}) async {
|
||||
String csrf = await Request.getCsrf();
|
||||
Map params = await WbiSign().makSign({
|
||||
'talker_id': talkerId,
|
||||
'session_type': 1,
|
||||
'build': 0,
|
||||
'mobi_app': 'web',
|
||||
'csrf_token': csrf,
|
||||
'csrf': csrf
|
||||
});
|
||||
var res = await Request().get(Api.removeSession, data: params);
|
||||
if (res.data['code'] == 0) {
|
||||
return {
|
||||
'status': true,
|
||||
'data': res.data['data'],
|
||||
};
|
||||
} else {
|
||||
return {'status': false, 'date': [], 'msg': res.data['message']};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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,7 +237,9 @@ class SessionItem extends StatelessWidget {
|
||||
),
|
||||
title: Text(sessionItem.accountInfo.name),
|
||||
subtitle: Text(
|
||||
content != null && content != ''
|
||||
msgStatus == 1
|
||||
? '你撤回了一条消息'
|
||||
: content != null && content != ''
|
||||
? (content['text'] ??
|
||||
content['content'] ??
|
||||
content['title'] ??
|
||||
|
@ -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('确认'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
],
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user