diff --git a/app/src/main/java/org/yameida/worktool/service/WeworkLoopImpl.kt b/app/src/main/java/org/yameida/worktool/service/WeworkLoopImpl.kt index f4bb9d1..ddb106b 100644 --- a/app/src/main/java/org/yameida/worktool/service/WeworkLoopImpl.kt +++ b/app/src/main/java/org/yameida/worktool/service/WeworkLoopImpl.kt @@ -91,50 +91,25 @@ object WeworkLoopImpl { }) } } - /** - * 等待服务端回复指令,最多30秒 - * 如果超时则发送"网络异常"消息 - */ + /** + * 等待服务端回复指令 + * 收到回复时waitingForReply会被sendMessage/replyMessage设置为false + */ private fun waitForServerReply() { - val waitTimeout = 30 * 1000L // 30秒超时 - val startTime = System.currentTimeMillis() LogUtils.d("等待服务端回复指令...") WeworkController.waitingForReply = true - while (mainLoopRunning && System.currentTimeMillis() - startTime < waitTimeout) { - sleep(1000) - - // 如果waitingForReply被设置为false,说明已收到服务端回复指令 - // sendMessage/replyMessage会被自动调用并处理 - if (!WeworkController.waitingForReply) { - LogUtils.d("收到服务端回复指令,已自动发送消息") - return - } - - // 检查是否离开当前聊天页面 + while (mainLoopRunning && WeworkController.waitingForReply) { + sleep(1000) + if (isAtHome()) { - LogUtils.d("用户已离开聊天页面") - return - } - } + LogUtils.d("用户已离开聊天页面") + 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}") - } } /** * 检查账号是否已实名 & 新号使用模拟环境