feat: pm: remove/setTop

This commit is contained in:
bggRGjQaUbCoE
2024-09-29 17:04:39 +08:00
parent f1e64752ae
commit 3a59b8bb60
5 changed files with 182 additions and 41 deletions

View File

@@ -613,4 +613,8 @@ class Api {
static const String videoTags = '/x/tag/archive/tags';
static const String reportMember = '/ajax/report/add';
static const String removeMsg = '/session_svr/v1/session_svr/remove_session';
static const String setTop = '/session_svr/v1/session_svr/set_top';
}

View File

@@ -1,4 +1,5 @@
import 'dart:math';
import 'package:PiliPalaX/http/constants.dart';
import 'package:dio/dio.dart';
import '../models/msg/account.dart';
@@ -142,6 +143,56 @@ class MsgHttp {
}
}
static Future removeMsg(
dynamic talkerId,
) async {
String csrf = await Request.getCsrf();
Map<String, dynamic> data = await WbiSign().makSign({
'talker_id': talkerId,
'session_type': 1,
'build': 0,
'mobi_app': 'web',
'csrf_token': csrf,
'csrf': csrf
});
var res = await Request()
.post(HttpString.tUrl + Api.removeMsg, data: FormData.fromMap(data));
if (res.data['code'] == 0) {
return {'status': true};
} else {
return {
'status': false,
'msg': res.data['message'],
};
}
}
static Future setTop(
dynamic talkerId,
int opType,
) async {
String csrf = await Request.getCsrf();
Map<String, dynamic> data = await WbiSign().makSign({
'talker_id': talkerId,
'session_type': 1,
'op_type': opType,
'build': 0,
'mobi_app': 'web',
'csrf_token': csrf,
'csrf': csrf
});
var res = await Request()
.post(HttpString.tUrl + Api.setTop, data: FormData.fromMap(data));
if (res.data['code'] == 0) {
return {'status': true};
} else {
return {
'status': false,
'msg': res.data['message'],
};
}
}
// 会话列表
static Future sessionList({int? endTs}) async {
Map<String, dynamic> params = {

View File

@@ -264,41 +264,40 @@ class ReplyItem extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Semantics(
label: text,
child: Text.rich(
style: TextStyle(
height: 1.75,
fontSize: Theme.of(context)
.textTheme
.bodyMedium!
.fontSize),
TextSpan(
children: [
if (replyItem!.isTop!) ...[
const WidgetSpan(
alignment: PlaceholderAlignment.top,
child: PBadge(
text: 'TOP',
size: 'small',
stack: 'normal',
type: 'line',
fs: 9,
semanticsLabel: '置顶',
),
label: text,
child: Text.rich(
style: TextStyle(
height: 1.75,
fontSize:
Theme.of(context).textTheme.bodyMedium!.fontSize),
TextSpan(
children: [
if (replyItem!.isTop!) ...[
const WidgetSpan(
alignment: PlaceholderAlignment.top,
child: PBadge(
text: 'TOP',
size: 'small',
stack: 'normal',
type: 'line',
fs: 9,
semanticsLabel: '置顶',
),
const TextSpan(text: ' '),
],
buildContent(
context,
replyItem!,
replyReply,
null,
textPainter,
didExceedMaxLines,
),
const TextSpan(text: ' '),
],
),
)),
buildContent(
context,
replyItem!,
replyReply,
null,
textPainter,
didExceedMaxLines,
),
],
),
),
),
if (didExceedMaxLines)
Text(
'查看更多',

View File

@@ -15,29 +15,29 @@ class WhisperController extends GetxController {
Rx<MsgFeedUnread> msgFeedUnread = MsgFeedUnread().obs;
RxList msgFeedTop = [
{
"name":"回复我的",
"icon":Icons.message_outlined,
"name": "回复我的",
"icon": Icons.message_outlined,
"route": "/replyMe",
"enabled": true,
"value": 0
},
{
"name":"@我",
"icon":Icons.alternate_email_outlined,
"name": "@我",
"icon": Icons.alternate_email_outlined,
"route": "/atMe",
"enabled": true,
"value": 0
},
{
"name":"收到的赞",
"icon":Icons.favorite_border_outlined,
"name": "收到的赞",
"icon": Icons.favorite_border_outlined,
"route": "/likeMe",
"enabled": true,
"value": 0
},
{
"name":"系统通知",
"icon":Icons.notifications_none_outlined,
"name": "系统通知",
"icon": Icons.notifications_none_outlined,
"route": "/sysMsg",
"enabled": true,
"value": 0
@@ -52,7 +52,8 @@ class WhisperController extends GetxController {
msgFeedTop[1]["value"] = msgFeedUnread.value.at;
msgFeedTop[2]["value"] = msgFeedUnread.value.like;
msgFeedTop[3]["value"] = msgFeedUnread.value.sys_msg;
if (GStorage.setting.get(SettingBoxKey.disableLikeMsg, defaultValue: false)) {
if (GStorage.setting
.get(SettingBoxKey.disableLikeMsg, defaultValue: false)) {
msgFeedTop[2]["value"] = -1;
msgFeedTop[2]["enabled"] = false;
}
@@ -63,6 +64,41 @@ class WhisperController extends GetxController {
}
}
Future onRemove(int index) async {
var res = await MsgHttp.removeMsg(sessionList[index].talkerId);
if (res['status']) {
sessionList.removeAt(index);
SmartDialog.showToast('删除成功');
} else {
SmartDialog.showToast(res['msg']);
}
}
Future onSetTop(int index) async {
bool isTop = sessionList[index].topTs != 0;
var res = await MsgHttp.setTop(
sessionList[index].talkerId,
isTop ? 1 : 0,
);
if (res['status']) {
List<SessionList> list = sessionList.map((item) {
if (item.talkerId == sessionList[index].talkerId) {
return item..topTs = isTop ? 0 : 1;
} else {
return item;
}
}).toList();
if (!isTop) {
SessionList item = list.removeAt(index);
list.insert(0, item);
}
sessionList.value = list;
SmartDialog.showToast('${isTop ? '移除' : ''}置顶成功');
} else {
SmartDialog.showToast(res['msg']);
}
}
Future querySessionList(String? type) async {
if (isLoading) return;
var res = await MsgHttp.sessionList(

View File

@@ -172,6 +172,57 @@ class _WhisperPageState extends State<WhisperPage> {
content.toString();
}
return ListTile(
tileColor: sessionList[i].topTs == 0
? null
: Theme.of(context)
.colorScheme
.primaryContainer,
onLongPress: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
clipBehavior: Clip.hardEdge,
contentPadding:
const EdgeInsets.symmetric(
vertical: 12),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
dense: true,
onTap: () {
Get.back();
_whisperController
.onSetTop(i);
},
title: Text(
sessionList[i].topTs == 0
? '置顶'
: '移除置顶',
style: const TextStyle(
fontSize: 14),
),
),
ListTile(
dense: true,
onTap: () {
Get.back();
_whisperController
.onRemove(i);
},
title: const Text(
'删除',
style:
TextStyle(fontSize: 14),
),
),
],
),
);
},
);
},
onTap: () {
setState(() {
sessionList[i].unreadCount = 0;