refactor(WeworkLoopImpl): 简化等待服务端回复的逻辑

移除30秒超时机制及超时后的"网络异常"消息发送,改为仅依赖waitingForReply标志位和是否离开聊天页面作为循环条件。这使逻辑更清晰,避免不必要的错误消息发送。
This commit is contained in:
2026-03-25 18:40:01 +08:00
parent 06fa098fe0
commit bcef4eded7

View File

@@ -91,50 +91,25 @@ object WeworkLoopImpl {
}) })
} }
} }
/** /**
* 等待服务端回复指令最多30秒 * 等待服务端回复指令
* 如果超时则发送"网络异常"消息 * 收到回复时waitingForReply会被sendMessage/replyMessage设置为false
*/ */
private fun waitForServerReply() { private fun waitForServerReply() {
val waitTimeout = 30 * 1000L // 30秒超时
val startTime = System.currentTimeMillis()
LogUtils.d("等待服务端回复指令...") LogUtils.d("等待服务端回复指令...")
WeworkController.waitingForReply = true WeworkController.waitingForReply = true
while (mainLoopRunning && System.currentTimeMillis() - startTime < waitTimeout) { while (mainLoopRunning && WeworkController.waitingForReply) {
sleep(1000) sleep(1000)
// 如果waitingForReply被设置为false说明已收到服务端回复指令
// sendMessage/replyMessage会被自动调用并处理
if (!WeworkController.waitingForReply) {
LogUtils.d("收到服务端回复指令,已自动发送消息")
return
}
// 检查是否离开当前聊天页面
if (isAtHome()) { if (isAtHome()) {
LogUtils.d("用户已离开聊天页面") LogUtils.d("用户已离开聊天页面")
return WeworkController.waitingForReply = false
} return
} }
}
// 超时未收到回复,发送"网络异常"消息
WeworkController.waitingForReply = false
LogUtils.e("等待服务端回复超时,发送网络异常")
try {
val titleList = WeworkRoomUtil.getRoomTitle()
if (titleList.isNotEmpty()) {
val errorMessage = WeworkMessageBean().apply {
type = WeworkMessageBean.SEND_MESSAGE
this.titleList = titleList
receivedContent = "网络异常"
}
WeworkController.sendMessage(errorMessage)
}
} catch (e: Exception) {
LogUtils.e("发送网络异常消息失败: ${e.message}")
}
} }
/** /**
* 检查账号是否已实名 & 新号使用模拟环境 * 检查账号是否已实名 & 新号使用模拟环境