From bcef4eded73ed27f19a3ccd7bcfdb450863c8224 Mon Sep 17 00:00:00 2001 From: tanjianbin <632190820@qq.com> Date: Wed, 25 Mar 2026 18:40:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor(WeworkLoopImpl):=20=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E6=9C=8D=E5=8A=A1=E7=AB=AF=E5=9B=9E=E5=A4=8D?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除30秒超时机制及超时后的"网络异常"消息发送,改为仅依赖waitingForReply标志位和是否离开聊天页面作为循环条件。这使逻辑更清晰,避免不必要的错误消息发送。 --- .../worktool/service/WeworkLoopImpl.kt | 49 +++++-------------- 1 file changed, 12 insertions(+), 37 deletions(-) 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}") - } } /** * 检查账号是否已实名 & 新号使用模拟环境