update 多次校验房间名

This commit is contained in:
gallonyin
2023-06-25 19:20:40 +08:00
parent d61931aa99
commit 8e1fdb5151
3 changed files with 50 additions and 36 deletions

View File

@@ -56,7 +56,7 @@ object WeworkOperationImpl {
successFlag = false successFlag = false
} }
if (!successFlag) { if (!successFlag) {
if (WeworkRoomUtil.intoRoom(title)) { if (WeworkRoomUtil.intoRoom(title, fastIn = false)) {
if (sendChatMessage(receivedContent, at = at, atList = atList)) { if (sendChatMessage(receivedContent, at = at, atList = atList)) {
successList.add(title) successList.add(title)
LogUtils.d("$title: 发送成功") LogUtils.d("$title: 发送成功")
@@ -107,7 +107,7 @@ object WeworkOperationImpl {
val successList = arrayListOf<String>() val successList = arrayListOf<String>()
val failList = arrayListOf<String>() val failList = arrayListOf<String>()
for (title in titleList) { for (title in titleList) {
if (WeworkRoomUtil.intoRoom(title)) { if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) {
if (WeworkTextUtil.longClickMessageItem( if (WeworkTextUtil.longClickMessageItem(
//聊天消息列表 1ListView 0RecycleView xViewGroup //聊天消息列表 1ListView 0RecycleView xViewGroup
AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView), AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView),
@@ -180,7 +180,7 @@ object WeworkOperationImpl {
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis() val startTime = System.currentTimeMillis()
for (title in titleList) { for (title in titleList) {
if (WeworkRoomUtil.intoRoom(title)) { if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) {
if (!receivedName.isNullOrEmpty()) { if (!receivedName.isNullOrEmpty()) {
if (WeworkTextUtil.longClickMessageItem( if (WeworkTextUtil.longClickMessageItem(
//聊天消息列表 1ListView 0RecycleView xViewGroup //聊天消息列表 1ListView 0RecycleView xViewGroup
@@ -328,7 +328,7 @@ object WeworkOperationImpl {
removeList: List<String>? removeList: List<String>?
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis() val startTime = System.currentTimeMillis()
if (!WeworkRoomUtil.intoRoom(groupName)) { if (!WeworkRoomUtil.intoRoom(groupName, fastIn = false)) {
uploadCommandResult(message, ExecCallbackBean.ERROR_INTO_ROOM, "进入房间失败 $groupName", startTime, listOf(), listOf(groupName)) uploadCommandResult(message, ExecCallbackBean.ERROR_INTO_ROOM, "进入房间失败 $groupName", startTime, listOf(), listOf(groupName))
return false return false
} }
@@ -372,7 +372,7 @@ object WeworkOperationImpl {
groupName: String groupName: String
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis() val startTime = System.currentTimeMillis()
if (WeworkRoomUtil.intoRoom(groupName) && WeworkRoomUtil.intoGroupManager()) { if ((WeworkRoomUtil.intoRoom(groupName) || WeworkRoomUtil.intoRoom(groupName, fastIn = false)) && WeworkRoomUtil.intoGroupManager()) {
val groupManagerTv = val groupManagerTv =
AccessibilityUtil.findOneByText(getRoot(), "群管理", exact = true, timeout = 2000) AccessibilityUtil.findOneByText(getRoot(), "群管理", exact = true, timeout = 2000)
if (groupManagerTv != null) { if (groupManagerTv != null) {
@@ -845,7 +845,7 @@ object WeworkOperationImpl {
): Boolean { ): Boolean {
val startTime = System.currentTimeMillis() val startTime = System.currentTimeMillis()
for (title in titleList) { for (title in titleList) {
if (WeworkRoomUtil.intoRoom(title)) { if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) {
if (WeworkTextUtil.longClickMyMessageItem( if (WeworkTextUtil.longClickMyMessageItem(
//聊天消息列表 1ListView 0RecycleView xViewGroup //聊天消息列表 1ListView 0RecycleView xViewGroup
AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView), AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView),
@@ -993,7 +993,7 @@ object WeworkOperationImpl {
} }
} }
} }
if (WeworkRoomUtil.intoRoom(groupName)) { if (WeworkRoomUtil.intoRoom(groupName) || WeworkRoomUtil.intoRoom(groupName, fastIn = false)) {
if (WeworkTextUtil.longClickMyMessageItem( if (WeworkTextUtil.longClickMyMessageItem(
//聊天消息列表 1ListView 0RecycleView xViewGroup //聊天消息列表 1ListView 0RecycleView xViewGroup
AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView), AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView),
@@ -1089,7 +1089,7 @@ object WeworkOperationImpl {
return relayMessage(message, titleList, receivedName, originalContent, textType, nameList, extraText) return relayMessage(message, titleList, receivedName, originalContent, textType, nameList, extraText)
} }
for (title in titleList) { for (title in titleList) {
if (WeworkRoomUtil.intoRoom(title)) { if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) {
var hasOpenMulti = false var hasOpenMulti = false
for (subMessageBean in messageList) { for (subMessageBean in messageList) {
val receivedName = subMessageBean.nameList?.firstOrNull() val receivedName = subMessageBean.nameList?.firstOrNull()

View File

@@ -1325,26 +1325,26 @@ object AccessibilityUtil {
/** /**
* 等待页面消失 * 等待页面消失
* @param clazz 页面Class * @param clazzList 页面Class
* @param timeout 检查超时时间 * @param timeout 检查超时时间
*/ */
fun waitForPageMissing( fun waitForPageMissing(
clazz: String, vararg clazzList: String,
timeout: Long = 5000 timeout: Long = 5000
): Boolean { ): Boolean {
val service = WeworkController.weworkService val service = WeworkController.weworkService
val startTime = System.currentTimeMillis() val startTime = System.currentTimeMillis()
var currentTime = startTime var currentTime = startTime
while (currentTime - startTime <= timeout) { while (currentTime - startTime <= timeout) {
if (service.currentClass == clazz || service.currentClass.split(".").last() == clazz) { if (service.currentClass in clazzList || service.currentClass.split(".").last() in clazzList) {
} else { } else {
Log.v(tag, "pageMissing: $clazz") Log.v(tag, "pageMissing: ${clazzList.joinToString()}")
return true return true
} }
sleep(SHORT_INTERVAL) sleep(SHORT_INTERVAL)
currentTime = System.currentTimeMillis() currentTime = System.currentTimeMillis()
} }
Log.e(tag, "pageMissing: not found: $clazz current: ${service.currentClass}") Log.e(tag, "pageMissing: not found: ${clazzList.joinToString()} current: ${service.currentClass}")
return false return false
} }

View File

@@ -76,32 +76,25 @@ object WeworkRoomUtil {
/** /**
* 进入房间(单聊或群聊) * 进入房间(单聊或群聊)
*/ */
fun intoRoom(title: String): Boolean { fun intoRoom(title: String, fastIn: Boolean = true): Boolean {
LogUtils.d("intoRoom(): $title") if (checkRoom(title)) {
val titleList = getRoomTitle(false)
val roomType = getRoomType()
if (roomType != WeworkMessageBean.ROOM_TYPE_UNKNOWN
&& titleList.count {
it.replace("", "").replace("\\(.*?\\)".toRegex(), "") == title.replace("", "")
.replace("\\(.*?\\)".toRegex(), "")
} > 0
) {
intoRoomPreInit()
LogUtils.d("当前正在房间")
return true return true
} }
goHome() goHome()
val list = findOneByClazz(getRoot(), Views.RecyclerView, Views.ListView, Views.ViewGroup) val list = findOneByClazz(getRoot(), Views.RecyclerView, Views.ListView, Views.ViewGroup)
if (list != null && list.childCount >= 2) { if (fastIn) {
for (i in 0 until list.childCount) { if (list != null && list.childCount >= 2) {
val item = list.getChild(i) for (i in 0 until list.childCount) {
val tvList = findAllOnceByClazz(item, Views.TextView).mapNotNull { it.text } val item = list.getChild(i)
if (tvList.isNotEmpty() && title == tvList[0].toString()) { val tvList = findAllOnceByClazz(item, Views.TextView).mapNotNull { it.text }
intoRoomPreInit() if (tvList.isNotEmpty() && title == tvList[0].toString()) {
AccessibilityUtil.performClick(item) intoRoomPreInit()
LogUtils.d("快捷进入房间: $title") AccessibilityUtil.performClick(item)
sleep(Constant.CHANGE_PAGE_INTERVAL) LogUtils.d("快捷进入房间: $title")
return true AccessibilityUtil.waitForPageMissing("WwMainActivity", "GlobalSearchActivity")
sleep(Constant.CHANGE_PAGE_INTERVAL)
return checkRoom(title)
}
} }
} }
} }
@@ -141,8 +134,9 @@ object WeworkRoomUtil {
intoRoomPreInit() intoRoomPreInit()
AccessibilityUtil.performClick(searchItem) AccessibilityUtil.performClick(searchItem)
LogUtils.d("进入房间: $title") LogUtils.d("进入房间: $title")
AccessibilityUtil.waitForPageMissing("WwMainActivity", "GlobalSearchActivity")
sleep(Constant.CHANGE_PAGE_INTERVAL) sleep(Constant.CHANGE_PAGE_INTERVAL)
return true return checkRoom(title)
} else { } else {
LogUtils.e("搜索到已退出群聊") LogUtils.e("搜索到已退出群聊")
} }
@@ -250,6 +244,26 @@ object WeworkRoomUtil {
return intoRoom(groupName) return intoRoom(groupName)
} }
/**
* 检查当前房间
*/
private fun checkRoom(title: String): Boolean {
LogUtils.d("checkRoom(): $title")
val titleList = getRoomTitle(false)
val roomType = getRoomType()
if (roomType != WeworkMessageBean.ROOM_TYPE_UNKNOWN
&& titleList.count {
it.replace("", "").replace("\\(.*?\\)".toRegex(), "") == title.replace("", "")
.replace("\\(.*?\\)".toRegex(), "")
} > 0
) {
intoRoomPreInit()
LogUtils.d("当前正在房间")
return true
}
return false
}
/** /**
* 是否是群聊 * 是否是群聊
* 群名最后有(\d)显示群人数 * 群名最后有(\d)显示群人数