diff --git a/app/src/main/java/org/yameida/worktool/Constant.kt b/app/src/main/java/org/yameida/worktool/Constant.kt index e1d5009..191bd68 100644 --- a/app/src/main/java/org/yameida/worktool/Constant.kt +++ b/app/src/main/java/org/yameida/worktool/Constant.kt @@ -28,7 +28,7 @@ object Constant { val wssRegex = "^wss".toRegex() val wsRegex = "^ws".toRegex() val suffixString = "(-.*)?(…)?(\\(\\d+\\))?$" - val suffixRegex = "(-.*)?(…)?(\\(\\d+\\))?$" + val suffixRegex = "(-.*)?(…)?(\\(\\d+\\))?$".toRegex() val digitalRegex = "\\(\\d+\\)\$".toRegex() var weworkCorpName: String get() = SPUtils.getInstance().getString("weworkCorpName", "") 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 fdaddca..8249103 100644 --- a/app/src/main/java/org/yameida/worktool/service/WeworkLoopImpl.kt +++ b/app/src/main/java/org/yameida/worktool/service/WeworkLoopImpl.kt @@ -159,12 +159,11 @@ object WeworkLoopImpl { * @param needInfer 是否需要推断@me并等待回复 * @param timeout 在房间内等待回复的时长 */ - fun getChatMessageList(needInfer: Boolean = !Constant.pushImage, imageCheck: Boolean = true, timeout: Long = 5000, titleList: ArrayList? = null, sendMessageBefore: Boolean = false): Boolean { + fun getChatMessageList(needInfer: Boolean = !Constant.pushImage, imageCheck: Boolean = true, timeout: Long = 5000, titleList: ArrayList? = null): Boolean { if (Constant.autoReply == 0) return true val roomType = WeworkRoomUtil.getRoomType() var titleList = titleList ?: WeworkRoomUtil.getRoomTitle() - if (!sendMessageBefore && titleList.count { it.endsWith("…") } > 0) { - LogUtils.e(java.lang.NullPointerException()) + if (titleList.count { it.endsWith("…") } > 0) { LogUtils.d("title too long... try get full name titleList: ${titleList.joinToString()}") if (roomType == WeworkMessageBean.ROOM_TYPE_INTERNAL_CONTACT || roomType == WeworkMessageBean.ROOM_TYPE_EXTERNAL_CONTACT) { titleList = WeworkRoomUtil.getFriendName() @@ -328,8 +327,6 @@ object WeworkLoopImpl { else -> return true } } - } else if (!sendMessageBefore) { - goHome() } return true } else { diff --git a/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt b/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt index bebdcfa..87dba39 100644 --- a/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt +++ b/app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt @@ -2799,8 +2799,24 @@ object WeworkOperationImpl { /** * 发送消息+@at */ - private fun sendChatMessage(text: String, at: String? = null, atList: List? = null, reply: Boolean? = false, title: String? = null): Boolean { + private fun sendChatMessage(text: String, at: String? = null, atList: List? = null, reply: Boolean? = false, title: String): Boolean { val roomType = WeworkRoomUtil.getRoomType() + var titleList = arrayListOf(title) ?: WeworkRoomUtil.getRoomTitle() + if (titleList.count { it.endsWith("…") } > 0) { + LogUtils.d("title too long... try get full name titleList: ${titleList.joinToString()}") + if (roomType == WeworkMessageBean.ROOM_TYPE_INTERNAL_CONTACT || roomType == WeworkMessageBean.ROOM_TYPE_EXTERNAL_CONTACT) { + titleList = WeworkRoomUtil.getFriendName() + } else if (Constant.fullGroupName + && (roomType == WeworkMessageBean.ROOM_TYPE_INTERNAL_GROUP || roomType == WeworkMessageBean.ROOM_TYPE_EXTERNAL_GROUP)) { + titleList = WeworkRoomUtil.getFullGroupTitle() + } + } + AccessibilityExtraUtil.loadingPage("ExternalGroupMessageListActivity", "ExternalWechatUserMessageListActivity", "MessageListActivity") + if (roomType == WeworkMessageBean.ROOM_TYPE_UNKNOWN || titleList.size == 0) { + LogUtils.e("非聊天房间 无法发送消息") + error("非聊天房间 无法发送消息") + return false + } val voiceFlag = AccessibilityUtil.findOnceByText(getRoot(), "按住 说话", "按住说话", exact = true) if (voiceFlag != null) { AccessibilityUtil.performClickWithSon(AccessibilityUtil.findFrontNode(voiceFlag)) @@ -2892,7 +2908,7 @@ object WeworkOperationImpl { LogUtils.v("atFailed: $atFailed") val content = if (atFailed) "@${atList?.joinToString()} $text" else text val append = (reply == true) || (!atList.isNullOrEmpty() && !atFailed) - WeworkLoopImpl.getChatMessageList(needInfer = false, imageCheck = false, sendMessageBefore = true) + WeworkLoopImpl.getChatMessageList(needInfer = false, imageCheck = false, titleList = titleList) if (AccessibilityUtil.findTextInput(getRoot(), content, append = append)) { AccessibilityUtil.findOneByText(getRoot(), "发送", exact = true, timeout = 2000) val sendButton = AccessibilityUtil.findAllByClazz(getRoot(), Views.Button) @@ -2902,7 +2918,8 @@ object WeworkOperationImpl { log("发送消息: \n$content") AccessibilityUtil.performClick(sendButton) sleep(Constant.POP_WINDOW_INTERVAL) - WeworkLoopImpl.getChatMessageList(needInfer = false) + WeworkLoopImpl.getChatMessageList(needInfer = false, titleList = titleList) + goHome() return true } else { LogUtils.e("未找到发送按钮") diff --git a/app/src/main/java/org/yameida/worktool/utils/WeworkRoomUtil.kt b/app/src/main/java/org/yameida/worktool/utils/WeworkRoomUtil.kt index c2cc5d9..799af78 100644 --- a/app/src/main/java/org/yameida/worktool/utils/WeworkRoomUtil.kt +++ b/app/src/main/java/org/yameida/worktool/utils/WeworkRoomUtil.kt @@ -275,7 +275,7 @@ object WeworkRoomUtil { * 检查当前房间 */ private fun checkRoom(title: String, strict: Boolean = false): Boolean { - LogUtils.d("checkRoom(): $title") + LogUtils.d("checkRoom(): $title strict: $strict") var titleList = getRoomTitle(print = false) if (titleList.isEmpty()) { return false @@ -291,10 +291,10 @@ object WeworkRoomUtil { } } val dealTitle = title.replace(Constant.suffixRegex, "") - LogUtils.v("dealTitle: $dealTitle", "titleList: ${titleList.joinToString()}") + LogUtils.d("dealTitle: $dealTitle", "titleList: ${titleList.joinToString()}") if (roomType != WeworkMessageBean.ROOM_TYPE_UNKNOWN && (titleList.count { dealTitle == it.replace(Constant.suffixRegex, "") } > 0 - || (!strict && titleList.count { dealTitle.contains(it.replace(Constant.suffixRegex, "")) } > 0)) + || ((!strict || !Constant.fullGroupName) && titleList.count { dealTitle.contains(it.replace(Constant.suffixRegex, "")) } > 0)) ) { intoRoomPreInit() LogUtils.d("当前正在房间")