更改分享和解绑消息弹窗
This commit is contained in:
225
lib/main.dart
225
lib/main.dart
@@ -213,17 +213,18 @@ Timer? _messageTimer;
|
||||
// }
|
||||
Future<void> startMessagePolling(int ent_type) async {
|
||||
Get.put(MhMessageController());
|
||||
MhMessageController messageController = Get.find();
|
||||
Get.put(MessageController());
|
||||
MessageController messageController = Get.find();
|
||||
final Set<String> _poppedMessageIds = {}; // 本地已弹窗的消息 ID(无论是否已读成功)
|
||||
final Set<String> _readMessageIds = {};
|
||||
final controller = Get.find<MhMessageController>();
|
||||
_messageTimer?.cancel();
|
||||
if (ent_type == APPPackageType.MHT.code) {
|
||||
if (Get.isRegistered<MhMessageController>()) {
|
||||
Get.find<MhMessageController>().getMessageStatus();
|
||||
await controller.getMessageStatus();
|
||||
if (controller.model.system_message_read == 1) {
|
||||
await controller.getMessageList("app_system");
|
||||
await controller.getMessageList("app_system",
|
||||
page: 1, limit: 100, append: false);
|
||||
final unhandledShareMessages =
|
||||
controller.systemMessageList.where((item) {
|
||||
final data = item['data'];
|
||||
@@ -313,7 +314,113 @@ Future<void> startMessagePolling(int ent_type) async {
|
||||
}
|
||||
} else {
|
||||
if (Get.isRegistered<MessageController>()) {
|
||||
Get.find<MessageController>().getMessageStatus();
|
||||
await messageController.getMessageStatus();
|
||||
if (messageController.model.system_message_read == 1) {
|
||||
await messageController.getMessageList(
|
||||
key: "app_system", page: 1, limit: 100, append: false);
|
||||
final unhandledShareMessages =
|
||||
messageController.messageList.where((item) {
|
||||
final data = item['data'];
|
||||
final id = item['_id']?.toString();
|
||||
return data is Map &&
|
||||
(data['type'] == 'share' || data['type'] == 'unShare') &&
|
||||
id != null &&
|
||||
!_poppedMessageIds.contains(id) &&
|
||||
(item['read_time'] == null);
|
||||
}).toList();
|
||||
|
||||
if (unhandledShareMessages.isNotEmpty) {
|
||||
for (final message in unhandledShareMessages) {
|
||||
final messageId = message['_id']?.toString();
|
||||
|
||||
if (messageId == null || _poppedMessageIds.contains(messageId))
|
||||
continue;
|
||||
|
||||
// 新增:如果当前页面是消息页,则跳过弹窗
|
||||
if (Get.currentRoute == '/messagePage') {
|
||||
continue;
|
||||
}
|
||||
|
||||
final data = message['data'] as Map<String, dynamic>;
|
||||
final valList = data['val'] as List<dynamic>;
|
||||
final messageType = data['type'];
|
||||
|
||||
// Extract device ID
|
||||
final deviceIdEntry = valList.firstWhere(
|
||||
(item) => item['k'] == '设备ID',
|
||||
orElse: () => null,
|
||||
);
|
||||
final mac = deviceIdEntry?['v'] as String?;
|
||||
_poppedMessageIds.add(messageId);
|
||||
|
||||
try {
|
||||
await controller.updateMessageReadStatus(
|
||||
Get.context!, message['type'],
|
||||
mid: messageId);
|
||||
} catch (e) {
|
||||
print("标记消息 $messageId 为已读失败: $e");
|
||||
}
|
||||
|
||||
String dialogTitle;
|
||||
String msg;
|
||||
if (messageType == 'share') {
|
||||
dialogTitle = '设备分享提醒'.tr; // "Device Sharing Notification"
|
||||
final result = await showMessageConfirmDialog(
|
||||
title: dialogTitle,
|
||||
colorsList: [
|
||||
themeController.currentColor.sc1,
|
||||
themeController.currentColor.sc2,
|
||||
],
|
||||
backgroundColor: themeController.currentColor.sc17,
|
||||
textColor: themeController.currentColor.sc3);
|
||||
|
||||
if (result == 'confirm') {
|
||||
messageController.model.type = 2;
|
||||
Get.toNamed('/messagePage');
|
||||
}
|
||||
} else {
|
||||
dialogTitle = '设备解绑提醒'.tr;
|
||||
showUnShareMessageDialog(
|
||||
title: dialogTitle,
|
||||
mac: mac!,
|
||||
colorsList: [
|
||||
themeController.currentColor.sc1,
|
||||
themeController.currentColor.sc2,
|
||||
],
|
||||
backgroundColor: themeController.currentColor.sc17,
|
||||
textColor: themeController.currentColor.sc3,
|
||||
);
|
||||
}
|
||||
}
|
||||
try {
|
||||
MHTHomeController homeController = Get.find();
|
||||
//更新设备列表
|
||||
homeController.getPersonList();
|
||||
//请求绑定设备列表
|
||||
// homeController.getSleepReport();
|
||||
homeController.getDeviceNum();
|
||||
homeController.getDeviceList(group: 'room').then((apiResponse) {
|
||||
if (apiResponse.code != HttpStatusCodes.ok) {
|
||||
try {
|
||||
WebviewTestController webviewTestController = Get.find();
|
||||
webviewTestController.web.jsbridge?.dart.alterDevice();
|
||||
} catch (e) {
|
||||
ef.log("[h5]通知列表更新报错:$e");
|
||||
}
|
||||
}
|
||||
});
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (homeController.homeSleepDays.value.isNotEmpty) {
|
||||
homeController.selectedDayIndex.value =
|
||||
homeController.homeSleepDays.value.length - 1;
|
||||
}
|
||||
});
|
||||
await homeController.getPersonList();
|
||||
} catch (e) {
|
||||
ef.log("更新失败:$e");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,7 +431,8 @@ Future<void> startMessagePolling(int ent_type) async {
|
||||
await controller.getMessageStatus();
|
||||
|
||||
if (controller.model.system_message_read == 1) {
|
||||
await controller.getMessageList("app_system");
|
||||
await controller.getMessageList("app_system",
|
||||
page: 1, limit: 100, append: false);
|
||||
final unhandledShareMessages =
|
||||
controller.systemMessageList.where((item) {
|
||||
final data = item['data'];
|
||||
@@ -389,6 +497,113 @@ Future<void> startMessagePolling(int ent_type) async {
|
||||
} else {
|
||||
if (Get.isRegistered<MessageController>()) {
|
||||
Get.find<MessageController>().getMessageStatus();
|
||||
if (messageController.model.system_message_read == 1) {
|
||||
await messageController.getMessageList(
|
||||
key: "app_system", page: 1, limit: 100, append: false);
|
||||
final unhandledShareMessages =
|
||||
messageController.messageList.where((item) {
|
||||
final data = item['data'];
|
||||
final id = item['_id']?.toString();
|
||||
return data is Map &&
|
||||
(data['type'] == 'share' || data['type'] == 'unShare') &&
|
||||
id != null &&
|
||||
!_poppedMessageIds.contains(id) &&
|
||||
(item['read_time'] == null);
|
||||
}).toList();
|
||||
|
||||
if (unhandledShareMessages.isNotEmpty) {
|
||||
for (final message in unhandledShareMessages) {
|
||||
final messageId = message['_id']?.toString();
|
||||
|
||||
if (messageId == null || _poppedMessageIds.contains(messageId))
|
||||
continue;
|
||||
|
||||
// 新增:如果当前页面是消息页,则跳过弹窗
|
||||
if (Get.currentRoute == '/messagePage') {
|
||||
continue;
|
||||
}
|
||||
|
||||
final data = message['data'] as Map<String, dynamic>;
|
||||
final valList = data['val'] as List<dynamic>;
|
||||
final messageType = data['type'];
|
||||
|
||||
// Extract device ID
|
||||
final deviceIdEntry = valList.firstWhere(
|
||||
(item) => item['k'] == '设备ID',
|
||||
orElse: () => null,
|
||||
);
|
||||
final mac = deviceIdEntry?['v'] as String?;
|
||||
_poppedMessageIds.add(messageId);
|
||||
|
||||
try {
|
||||
await controller.updateMessageReadStatus(
|
||||
Get.context!, message['type'],
|
||||
mid: messageId);
|
||||
} catch (e) {
|
||||
print("标记消息 $messageId 为已读失败: $e");
|
||||
}
|
||||
|
||||
String dialogTitle;
|
||||
String msg;
|
||||
if (messageType == 'share') {
|
||||
dialogTitle = '设备分享提醒'.tr; // "Device Sharing Notification"
|
||||
final result = await showMessageConfirmDialog(
|
||||
title: dialogTitle,
|
||||
colorsList: [
|
||||
themeController.currentColor.sc1,
|
||||
themeController.currentColor.sc2,
|
||||
],
|
||||
backgroundColor: themeController.currentColor.sc17,
|
||||
textColor: themeController.currentColor.sc3);
|
||||
|
||||
if (result == 'confirm') {
|
||||
Get.toNamed(
|
||||
'/messagePage',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
dialogTitle = '设备解绑提醒'.tr;
|
||||
showUnShareMessageDialog(
|
||||
title: dialogTitle,
|
||||
mac: mac!,
|
||||
colorsList: [
|
||||
themeController.currentColor.sc1,
|
||||
themeController.currentColor.sc2,
|
||||
],
|
||||
backgroundColor: themeController.currentColor.sc17,
|
||||
textColor: themeController.currentColor.sc3,
|
||||
);
|
||||
}
|
||||
}
|
||||
try {
|
||||
MHTHomeController homeController = Get.find();
|
||||
//更新设备列表
|
||||
homeController.getPersonList();
|
||||
//请求绑定设备列表
|
||||
// homeController.getSleepReport();
|
||||
homeController.getDeviceNum();
|
||||
homeController.getDeviceList(group: 'room').then((apiResponse) {
|
||||
if (apiResponse.code != HttpStatusCodes.ok) {
|
||||
try {
|
||||
WebviewTestController webviewTestController = Get.find();
|
||||
webviewTestController.web.jsbridge?.dart.alterDevice();
|
||||
} catch (e) {
|
||||
ef.log("[h5]通知列表更新报错:$e");
|
||||
}
|
||||
}
|
||||
});
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (homeController.homeSleepDays.value.isNotEmpty) {
|
||||
homeController.selectedDayIndex.value =
|
||||
homeController.homeSleepDays.value.length - 1;
|
||||
}
|
||||
});
|
||||
await homeController.getPersonList();
|
||||
} catch (e) {
|
||||
ef.log("更新失败:$e");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user