update 发送消息优化

This commit is contained in:
gallonyin
2023-10-12 23:11:23 +08:00
parent 2d078fe6ab
commit 1f411b79ac
3 changed files with 16 additions and 4 deletions

View File

@@ -159,11 +159,12 @@ object WeworkLoopImpl {
* @param needInfer 是否需要推断@me并等待回复 * @param needInfer 是否需要推断@me并等待回复
* @param timeout 在房间内等待回复的时长 * @param timeout 在房间内等待回复的时长
*/ */
fun getChatMessageList(needInfer: Boolean = !Constant.pushImage, imageCheck: Boolean = true, timeout: Long = 5000, titleList: ArrayList<String>? = null): Boolean { fun getChatMessageList(needInfer: Boolean = !Constant.pushImage, imageCheck: Boolean = true, timeout: Long = 5000, titleList: ArrayList<String>? = null, sendMessageBefore: Boolean = false): Boolean {
if (Constant.autoReply == 0) return true if (Constant.autoReply == 0) return true
val roomType = WeworkRoomUtil.getRoomType() val roomType = WeworkRoomUtil.getRoomType()
var titleList = titleList ?: WeworkRoomUtil.getRoomTitle() var titleList = titleList ?: WeworkRoomUtil.getRoomTitle()
if (titleList.count { it.endsWith("") } > 0) { if (!sendMessageBefore && titleList.count { it.endsWith("") } > 0) {
LogUtils.e(java.lang.NullPointerException())
LogUtils.d("title too long... try get full name titleList: ${titleList.joinToString()}") 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) { if (roomType == WeworkMessageBean.ROOM_TYPE_INTERNAL_CONTACT || roomType == WeworkMessageBean.ROOM_TYPE_EXTERNAL_CONTACT) {
titleList = WeworkRoomUtil.getFriendName() titleList = WeworkRoomUtil.getFriendName()
@@ -327,6 +328,8 @@ object WeworkLoopImpl {
else -> return true else -> return true
} }
} }
} else if (!sendMessageBefore) {
goHome()
} }
return true return true
} else { } else {

View File

@@ -2892,7 +2892,7 @@ object WeworkOperationImpl {
LogUtils.v("atFailed: $atFailed") LogUtils.v("atFailed: $atFailed")
val content = if (atFailed) "@${atList?.joinToString()} $text" else text val content = if (atFailed) "@${atList?.joinToString()} $text" else text
val append = (reply == true) || (!atList.isNullOrEmpty() && !atFailed) val append = (reply == true) || (!atList.isNullOrEmpty() && !atFailed)
WeworkLoopImpl.getChatMessageList(needInfer = false, imageCheck = false) WeworkLoopImpl.getChatMessageList(needInfer = false, imageCheck = false, sendMessageBefore = true)
if (AccessibilityUtil.findTextInput(getRoot(), content, append = append)) { if (AccessibilityUtil.findTextInput(getRoot(), content, append = append)) {
AccessibilityUtil.findOneByText(getRoot(), "发送", exact = true, timeout = 2000) AccessibilityUtil.findOneByText(getRoot(), "发送", exact = true, timeout = 2000)
val sendButton = AccessibilityUtil.findAllByClazz(getRoot(), Views.Button) val sendButton = AccessibilityUtil.findAllByClazz(getRoot(), Views.Button)

View File

@@ -276,11 +276,20 @@ object WeworkRoomUtil {
*/ */
private fun checkRoom(title: String, strict: Boolean = false): Boolean { private fun checkRoom(title: String, strict: Boolean = false): Boolean {
LogUtils.d("checkRoom(): $title") LogUtils.d("checkRoom(): $title")
val titleList = getRoomTitle(print = false) var titleList = getRoomTitle(print = false)
if (titleList.isEmpty()) { if (titleList.isEmpty()) {
return false return false
} }
val roomType = getRoomType() val roomType = getRoomType()
if (strict && 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 = getFriendName()
} else if (Constant.fullGroupName
&& (roomType == WeworkMessageBean.ROOM_TYPE_INTERNAL_GROUP || roomType == WeworkMessageBean.ROOM_TYPE_EXTERNAL_GROUP)) {
titleList = getFullGroupTitle()
}
}
val dealTitle = title.replace(Constant.suffixRegex, "") val dealTitle = title.replace(Constant.suffixRegex, "")
LogUtils.v("dealTitle: $dealTitle", "titleList: ${titleList.joinToString()}") LogUtils.v("dealTitle: $dealTitle", "titleList: ${titleList.joinToString()}")
if (roomType != WeworkMessageBean.ROOM_TYPE_UNKNOWN if (roomType != WeworkMessageBean.ROOM_TYPE_UNKNOWN