fix(wechat): 添加会话存在性验证以避免无效操作
在发送消息、图片和文件前,先验证目标会话是否存在于当前会话列表中 通过数字正则匹配处理会话标题中的数字差异,提高匹配准确性 当会话不存在或无法获取列表时,提前返回错误信息,避免不必要的后续操作
This commit is contained in:
@@ -44,6 +44,23 @@ object WeworkOperationImpl {
|
|||||||
goHome()
|
goHome()
|
||||||
return false
|
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<String>()
|
val successList = arrayListOf<String>()
|
||||||
val failList = arrayListOf<String>()
|
val failList = arrayListOf<String>()
|
||||||
for (title in LinkedHashSet(titleList)) {
|
for (title in LinkedHashSet(titleList)) {
|
||||||
@@ -107,6 +124,23 @@ object WeworkOperationImpl {
|
|||||||
goHome()
|
goHome()
|
||||||
return false
|
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<String>()
|
val successList = arrayListOf<String>()
|
||||||
val failList = arrayListOf<String>()
|
val failList = arrayListOf<String>()
|
||||||
for (title in LinkedHashSet(titleList)) {
|
for (title in LinkedHashSet(titleList)) {
|
||||||
@@ -182,6 +216,23 @@ object WeworkOperationImpl {
|
|||||||
extraText: String? = null
|
extraText: String? = null
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val startTime = System.currentTimeMillis()
|
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)) {
|
for (title in LinkedHashSet(titleList)) {
|
||||||
if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) {
|
if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) {
|
||||||
if (!receivedName.isNullOrEmpty()) {
|
if (!receivedName.isNullOrEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user