mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: msg ctr
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
70
lib/pages/common/common_whisper_controller.dart
Normal file
70
lib/pages/common/common_whisper_controller.dart
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart';
|
||||||
|
import 'package:PiliPlus/grpc/im.dart';
|
||||||
|
import 'package:PiliPlus/http/loading_state.dart';
|
||||||
|
import 'package:PiliPlus/http/msg.dart';
|
||||||
|
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
|
|
||||||
|
abstract class CommonWhisperController<R>
|
||||||
|
extends CommonListController<R, Session> {
|
||||||
|
SessionPageType get sessionPageType;
|
||||||
|
|
||||||
|
Future<void> onRemove(int index, int? talkerId) async {
|
||||||
|
var res = await MsgHttp.removeMsg(talkerId);
|
||||||
|
if (res['status']) {
|
||||||
|
loadingState
|
||||||
|
..value.data!.removeAt(index)
|
||||||
|
..refresh();
|
||||||
|
SmartDialog.showToast('删除成功');
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast(res['msg']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> onSetTop(int index, bool isTop, SessionId sessionId) async {
|
||||||
|
var res = isTop
|
||||||
|
? await ImGrpc.unpinSession(sessionId: sessionId)
|
||||||
|
: await ImGrpc.pinSession(sessionId: sessionId);
|
||||||
|
|
||||||
|
if (res['status']) {
|
||||||
|
List<Session> list = loadingState.value.data!;
|
||||||
|
list[index].isPinned = isTop ? false : true;
|
||||||
|
if (!isTop) {
|
||||||
|
list.insert(0, list.removeAt(index));
|
||||||
|
}
|
||||||
|
loadingState.refresh();
|
||||||
|
SmartDialog.showToast('${isTop ? '移除' : ''}置顶成功');
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast(res['msg']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> onClearUnread() async {
|
||||||
|
final res = await ImGrpc.clearUnread(pageType: sessionPageType);
|
||||||
|
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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> onDeleteList() async {
|
||||||
|
var res = await ImGrpc.deleteSessionList(pageType: sessionPageType);
|
||||||
|
if (res['status']) {
|
||||||
|
loadingState.value = LoadingState.success(null);
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast(res['msg']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +1,20 @@
|
|||||||
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart'
|
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart'
|
||||||
show
|
show Offset, Session, SessionMainReply, SessionPageType, ThreeDotItem;
|
||||||
Offset,
|
|
||||||
Session,
|
|
||||||
SessionId,
|
|
||||||
SessionMainReply,
|
|
||||||
SessionPageType,
|
|
||||||
ThreeDotItem;
|
|
||||||
import 'package:PiliPlus/grpc/im.dart';
|
import 'package:PiliPlus/grpc/im.dart';
|
||||||
import 'package:PiliPlus/http/loading_state.dart';
|
import 'package:PiliPlus/http/loading_state.dart';
|
||||||
import 'package:PiliPlus/http/msg.dart';
|
import 'package:PiliPlus/http/msg.dart';
|
||||||
import 'package:PiliPlus/models/msg/msgfeed_unread.dart';
|
import 'package:PiliPlus/models/msg/msgfeed_unread.dart';
|
||||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
import 'package:PiliPlus/pages/common/common_whisper_controller.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:protobuf/protobuf.dart' show PbMap;
|
import 'package:protobuf/protobuf.dart' show PbMap;
|
||||||
|
|
||||||
class WhisperController
|
class WhisperController extends CommonWhisperController<SessionMainReply> {
|
||||||
extends CommonListController<SessionMainReply, Session> {
|
@override
|
||||||
|
SessionPageType sessionPageType = SessionPageType.SESSION_PAGE_TYPE_HOME;
|
||||||
|
|
||||||
late final List msgFeedTopItems;
|
late final List msgFeedTopItems;
|
||||||
late final RxList<int> unreadCounts;
|
late final RxList<int> unreadCounts;
|
||||||
|
|
||||||
@@ -101,72 +97,4 @@ class WhisperController
|
|||||||
queryMsgFeedUnread();
|
queryMsgFeedUnread();
|
||||||
return super.onRefresh();
|
return super.onRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> onRemove(int index, int? talkerId) async {
|
|
||||||
var res = await MsgHttp.removeMsg(talkerId);
|
|
||||||
if (res['status']) {
|
|
||||||
loadingState.value.data!.removeAt(index);
|
|
||||||
loadingState.refresh();
|
|
||||||
SmartDialog.showToast('删除成功');
|
|
||||||
} else {
|
|
||||||
SmartDialog.showToast(res['msg']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> onSetTop(int index, bool isTop, SessionId sessionId) async {
|
|
||||||
var res = isTop
|
|
||||||
? await ImGrpc.unpinSession(sessionId: sessionId)
|
|
||||||
: await ImGrpc.pinSession(sessionId: sessionId);
|
|
||||||
|
|
||||||
if (res['status']) {
|
|
||||||
List<Session> list = loadingState.value.data!;
|
|
||||||
list[index].isPinned = isTop ? false : true;
|
|
||||||
if (!isTop) {
|
|
||||||
list.insert(0, list.removeAt(index));
|
|
||||||
}
|
|
||||||
loadingState.refresh();
|
|
||||||
SmartDialog.showToast('${isTop ? '移除' : ''}置顶成功');
|
|
||||||
} else {
|
|
||||||
SmartDialog.showToast(res['msg']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void onTap(int index) {
|
|
||||||
Session item = loadingState.value.data![index];
|
|
||||||
if (item.hasUnread()) {
|
|
||||||
item.clearUnread();
|
|
||||||
loadingState.refresh();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> onClearUnread() async {
|
|
||||||
final res = await ImGrpc.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']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> onDeleteList() async {
|
|
||||||
var res = await ImGrpc.deleteSessionList(
|
|
||||||
pageType: SessionPageType.SESSION_PAGE_TYPE_HOME);
|
|
||||||
if (res['status']) {
|
|
||||||
loadingState.value = LoadingState.success(null);
|
|
||||||
} else {
|
|
||||||
SmartDialog.showToast(res['msg']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,6 @@ class _WhisperPageState extends State<WhisperPage> {
|
|||||||
onSetTop: (isTop, id) =>
|
onSetTop: (isTop, id) =>
|
||||||
_controller.onSetTop(index, isTop, id),
|
_controller.onSetTop(index, isTop, id),
|
||||||
onRemove: (talkerId) => _controller.onRemove(index, talkerId),
|
onRemove: (talkerId) => _controller.onRemove(index, talkerId),
|
||||||
onTap: () => _controller.onTap(index),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
separatorBuilder: (context, index) => Divider(
|
separatorBuilder: (context, index) => Divider(
|
||||||
|
|||||||
@@ -18,13 +18,11 @@ class WhisperSessionItem extends StatelessWidget {
|
|||||||
required this.item,
|
required this.item,
|
||||||
required this.onSetTop,
|
required this.onSetTop,
|
||||||
required this.onRemove,
|
required this.onRemove,
|
||||||
required this.onTap,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final Session item;
|
final Session item;
|
||||||
final Function(bool isTop, SessionId id) onSetTop;
|
final Function(bool isTop, SessionId id) onSetTop;
|
||||||
final ValueChanged<int?> onRemove;
|
final ValueChanged<int?> onRemove;
|
||||||
final VoidCallback onTap;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -77,7 +75,12 @@ class WhisperSessionItem extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
onTap: () {
|
onTap: () {
|
||||||
onTap();
|
if (item.hasUnread()) {
|
||||||
|
item.clearUnread();
|
||||||
|
if (context.mounted) {
|
||||||
|
(context as Element).markNeedsBuild();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (item.id.privateId.hasTalkerUid()) {
|
if (item.id.privateId.hasTalkerUid()) {
|
||||||
Get.toNamed(
|
Get.toNamed(
|
||||||
'/whisperDetail',
|
'/whisperDetail',
|
||||||
|
|||||||
@@ -1,26 +1,19 @@
|
|||||||
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart'
|
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart'
|
||||||
show
|
show Offset, Session, SessionPageType, SessionSecondaryReply, ThreeDotItem;
|
||||||
Offset,
|
|
||||||
Session,
|
|
||||||
SessionId,
|
|
||||||
SessionPageType,
|
|
||||||
SessionSecondaryReply,
|
|
||||||
ThreeDotItem;
|
|
||||||
import 'package:PiliPlus/grpc/im.dart';
|
import 'package:PiliPlus/grpc/im.dart';
|
||||||
import 'package:PiliPlus/http/loading_state.dart';
|
import 'package:PiliPlus/http/loading_state.dart';
|
||||||
import 'package:PiliPlus/http/msg.dart';
|
import 'package:PiliPlus/pages/common/common_whisper_controller.dart';
|
||||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:protobuf/protobuf.dart' show PbMap;
|
import 'package:protobuf/protobuf.dart' show PbMap;
|
||||||
|
|
||||||
class WhisperSecController
|
class WhisperSecController
|
||||||
extends CommonListController<SessionSecondaryReply, Session> {
|
extends CommonWhisperController<SessionSecondaryReply> {
|
||||||
WhisperSecController({
|
WhisperSecController({
|
||||||
required this.sessionPageType,
|
required this.sessionPageType,
|
||||||
});
|
});
|
||||||
|
|
||||||
PbMap<int, Offset>? offset;
|
PbMap<int, Offset>? offset;
|
||||||
|
@override
|
||||||
final SessionPageType sessionPageType;
|
final SessionPageType sessionPageType;
|
||||||
Rx<List<ThreeDotItem>?> threeDotItems = Rx<List<ThreeDotItem>?>(null);
|
Rx<List<ThreeDotItem>?> threeDotItems = Rx<List<ThreeDotItem>?>(null);
|
||||||
|
|
||||||
@@ -60,71 +53,4 @@ class WhisperSecController
|
|||||||
offset: offset,
|
offset: offset,
|
||||||
pageType: sessionPageType,
|
pageType: sessionPageType,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<void> onRemove(int index, int? talkerId) async {
|
|
||||||
var res = await MsgHttp.removeMsg(talkerId);
|
|
||||||
if (res['status']) {
|
|
||||||
loadingState
|
|
||||||
..value.data!.removeAt(index)
|
|
||||||
..refresh();
|
|
||||||
SmartDialog.showToast('删除成功');
|
|
||||||
} else {
|
|
||||||
SmartDialog.showToast(res['msg']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> onSetTop(int index, bool isTop, SessionId sessionId) async {
|
|
||||||
var res = isTop
|
|
||||||
? await ImGrpc.unpinSession(sessionId: sessionId)
|
|
||||||
: await ImGrpc.pinSession(sessionId: sessionId);
|
|
||||||
|
|
||||||
if (res['status']) {
|
|
||||||
List<Session> list = loadingState.value.data!;
|
|
||||||
list[index].isPinned = isTop ? false : true;
|
|
||||||
if (!isTop) {
|
|
||||||
list.insert(0, list.removeAt(index));
|
|
||||||
}
|
|
||||||
loadingState.refresh();
|
|
||||||
SmartDialog.showToast('${isTop ? '移除' : ''}置顶成功');
|
|
||||||
} else {
|
|
||||||
SmartDialog.showToast(res['msg']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void onTap(int index) {
|
|
||||||
Session item = loadingState.value.data![index];
|
|
||||||
if (item.hasUnread()) {
|
|
||||||
item.clearUnread();
|
|
||||||
loadingState.refresh();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> onClearUnread() async {
|
|
||||||
final res = await ImGrpc.clearUnread(pageType: sessionPageType);
|
|
||||||
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']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> onDeleteList() async {
|
|
||||||
var res = await ImGrpc.deleteSessionList(pageType: sessionPageType);
|
|
||||||
if (res['status']) {
|
|
||||||
loadingState.value = LoadingState.success(null);
|
|
||||||
} else {
|
|
||||||
SmartDialog.showToast(res['msg']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,6 @@ class _WhisperSecPageState extends State<WhisperSecPage> {
|
|||||||
onSetTop: (isTop, talkerId) =>
|
onSetTop: (isTop, talkerId) =>
|
||||||
_controller.onSetTop(index, isTop, talkerId),
|
_controller.onSetTop(index, isTop, talkerId),
|
||||||
onRemove: (talkerId) => _controller.onRemove(index, talkerId),
|
onRemove: (talkerId) => _controller.onRemove(index, talkerId),
|
||||||
onTap: () => _controller.onTap(index),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
separatorBuilder: (context, index) => Divider(
|
separatorBuilder: (context, index) => Divider(
|
||||||
|
|||||||
Reference in New Issue
Block a user