refactor: 移除会话存在性校验并添加发送消息异常保护
移除 WeworkOperationImpl 中发送消息前的会话存在性校验,简化逻辑 在 WeworkController 的 sendMessage 和 replyMessage 方法中添加 try-finally 块 确保 waitingForReply 状态在发送消息后无论成功失败都能正确重置
This commit is contained in:
@@ -65,10 +65,13 @@ object WeworkController {
|
||||
LogUtils.d("REQUEST sendMessage(): ${message.messageId} ${message.titleList} ${message.receivedContent} ${message.at} ${message.atList?.joinToString()}")
|
||||
// 进入发送消息流程,暂停主循环检测新消息,避免重复进入同一聊天页
|
||||
waitingForReply = true
|
||||
try {
|
||||
val result = WeworkOperationImpl.sendMessage(message, message.titleList, message.receivedContent, message.at, message.atList)
|
||||
// 发送完成,通知等待结束
|
||||
waitingForReply = false
|
||||
return result
|
||||
} finally {
|
||||
// 无论成功还是失败,都要恢复等待状态
|
||||
waitingForReply = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,6 +89,7 @@ object WeworkController {
|
||||
LogUtils.d("REQUEST replyMessage(): ${message.messageId} ${message.receivedName} ${message.originalContent} ${message.textType} ${message.receivedContent}")
|
||||
// 进入发送消息流程,暂停主循环检测新消息,避免重复进入同一聊天页
|
||||
waitingForReply = true
|
||||
try {
|
||||
val result = WeworkOperationImpl.replyMessage(
|
||||
message,
|
||||
message.titleList,
|
||||
@@ -94,9 +98,11 @@ object WeworkController {
|
||||
message.textType,
|
||||
message.receivedContent
|
||||
)
|
||||
// 发送完成,通知等待结束
|
||||
waitingForReply = false
|
||||
return result
|
||||
} finally {
|
||||
// 无论成功还是失败,都要恢复等待状态
|
||||
waitingForReply = false
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 在房间内转发消息
|
||||
|
||||
@@ -45,22 +45,6 @@ object WeworkOperationImpl {
|
||||
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 failList = arrayListOf<String>()
|
||||
for (title in LinkedHashSet(titleList)) {
|
||||
|
||||
Reference in New Issue
Block a user