mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: pm: clear unread
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -51,6 +51,7 @@ class GrpcUrl {
|
||||
static const sendMsg = '$im/SendMsg';
|
||||
static const shareList = '$im/ShareList';
|
||||
static const sessionMain = '$im2/SessionMain';
|
||||
static const clearUnread = '$im2/ClearUnread';
|
||||
}
|
||||
|
||||
class GrpcRepo {
|
||||
@@ -382,4 +383,18 @@ class GrpcRepo {
|
||||
SessionMainReply.fromBuffer,
|
||||
);
|
||||
}
|
||||
|
||||
static Future clearUnread({
|
||||
SessionPageType? pageType,
|
||||
SessionId? sessionId,
|
||||
}) async {
|
||||
return await _request(
|
||||
GrpcUrl.clearUnread,
|
||||
ClearUnreadReq(
|
||||
pageType: pageType,
|
||||
sessionId: sessionId,
|
||||
),
|
||||
ClearUnreadReply.fromBuffer,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart';
|
||||
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart'
|
||||
show SessionMainReply, Session, Offset, SessionPageType;
|
||||
import 'package:PiliPlus/grpc/grpc_repo.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/msg.dart';
|
||||
import 'package:PiliPlus/models/msg/msgfeed_unread.dart';
|
||||
@@ -117,4 +119,25 @@ class WhisperController
|
||||
loadingState.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> onClearUnread() async {
|
||||
final res = await GrpcRepo.clearUnread(
|
||||
pageType: SessionPageType.SESSION_PAGE_TYPE_HOME);
|
||||
if (res['status']) {
|
||||
if (loadingState.value is Success) {
|
||||
List<Session>? list = loadingState.value.data;
|
||||
if (list?.isNotEmpty == true) {
|
||||
for (var item in list!) {
|
||||
if (item.hasUnread()) {
|
||||
item.clearUnread();
|
||||
}
|
||||
}
|
||||
loadingState.refresh();
|
||||
}
|
||||
}
|
||||
SmartDialog.showToast('已标记为已读');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:PiliPlus/common/skeleton/whisper_item.dart';
|
||||
import 'package:PiliPlus/common/widgets/dialog/dialog.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';
|
||||
@@ -22,7 +23,27 @@ class _WhisperPageState extends State<WhisperPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('消息')),
|
||||
appBar: AppBar(
|
||||
title: const Text('消息'),
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '一键已读',
|
||||
onPressed: () {
|
||||
showConfirmDialog(
|
||||
context: context,
|
||||
title: '一键已读',
|
||||
content: '是否清除全部新消息提醒?',
|
||||
onConfirm: _whisperController.onClearUnread,
|
||||
);
|
||||
},
|
||||
icon: const Icon(
|
||||
size: 20,
|
||||
Icons.cleaning_services,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
],
|
||||
),
|
||||
body: refreshIndicator(
|
||||
onRefresh: () async {
|
||||
await _whisperController.onRefresh();
|
||||
|
||||
Reference in New Issue
Block a user