diff --git a/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt b/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt index 05dccc1..5b1fb4a 100644 --- a/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt +++ b/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt @@ -44,6 +44,23 @@ object WeworkOperationImpl { goHome() return false } + + // 验证titleList是否在当前会话列表中存在 + val currentRoomList = WeworkRoomUtil.getRoomTitle(print = false) + if (currentRoomList.isEmpty()) { + LogUtils.d("无法获取当前会话列表") + uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "无法获取当前会话列表,请确保在微信首页", startTime, listOf(), titleList) + return false + } + val notFoundList = titleList.filter { title -> + currentRoomList.none { it == title || it.replace(Constant.digitalRegex, "") == title || title.replace(Constant.digitalRegex, "") == it } + } + if (notFoundList.isNotEmpty()) { + LogUtils.d("以下会话不存在: ${notFoundList.joinToString()}") + uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "会话不存在: ${notFoundList.joinToString()}", startTime, listOf(), titleList) + return false + } + val successList = arrayListOf() val failList = arrayListOf() for (title in LinkedHashSet(titleList)) { @@ -107,6 +124,23 @@ object WeworkOperationImpl { goHome() return false } + + // 验证titleList是否在当前会话列表中存在 + val currentRoomList = WeworkRoomUtil.getRoomTitle(print = false) + if (currentRoomList.isEmpty()) { + LogUtils.d("无法获取当前会话列表") + uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "无法获取当前会话列表,请确保在微信首页", startTime, listOf(), titleList) + return false + } + val notFoundList = titleList.filter { title -> + currentRoomList.none { it == title || it.replace(Constant.digitalRegex, "") == title || title.replace(Constant.digitalRegex, "") == it } + } + if (notFoundList.isNotEmpty()) { + LogUtils.d("以下会话不存在: ${notFoundList.joinToString()}") + uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "会话不存在: ${notFoundList.joinToString()}", startTime, listOf(), titleList) + return false + } + val successList = arrayListOf() val failList = arrayListOf() for (title in LinkedHashSet(titleList)) { @@ -182,6 +216,23 @@ object WeworkOperationImpl { extraText: String? = null ): Boolean { val startTime = System.currentTimeMillis() + + // 验证titleList是否在当前会话列表中存在 + val currentRoomList = WeworkRoomUtil.getRoomTitle(print = false) + if (currentRoomList.isEmpty()) { + LogUtils.d("无法获取当前会话列表") + uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "无法获取当前会话列表,请确保在微信首页", startTime, listOf(), titleList) + return false + } + val notFoundList = titleList.filter { title -> + currentRoomList.none { it == title || it.replace(Constant.digitalRegex, "") == title || title.replace(Constant.digitalRegex, "") == it } + } + if (notFoundList.isNotEmpty()) { + LogUtils.d("以下会话不存在: ${notFoundList.joinToString()}") + uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "会话不存在: ${notFoundList.joinToString()}", startTime, listOf(), titleList) + return false + } + for (title in LinkedHashSet(titleList)) { if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) { if (!receivedName.isNullOrEmpty()) {