Переглянути джерело

增加转发两次机会,修复群发因搜索不到人失败

yangyang 9 місяців тому
батько
коміт
6abd62dae7

+ 2 - 2
app/build.gradle

@@ -9,8 +9,8 @@ android {
         applicationId "com.rk.worktool"
         minSdkVersion 24
         targetSdkVersion 30
-        versionCode 20250401
-        versionName "2.9.3"
+        versionCode 20250414
+        versionName "2.9.4"
     }
 
     buildTypes {

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -29,6 +29,7 @@
     <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
     <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
         tools:ignore="QueryAllPackagesPermission" />
+    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
 
     <application
         android:name="org.yameida.worktool.MyApplication"

+ 4 - 3
app/src/main/java/org/yameida/worktool/Constant.kt

@@ -53,7 +53,8 @@ object Constant {
     var CHANGE_PAGE_INTERVAL = BASE_CHANGE_PAGE_INTERVAL
     var POP_WINDOW_INTERVAL = BASE_POP_WINDOW_INTERVAL
 
-//            private const val DEFAULT_HOST = "wss://assistant.flowbb.top/"
+//    private const val DEFAULT_HOST = "wss://assistant.flowbb.top/"
+//    private const val DEFAULT_HOST = "ws://192.168.2.36:9059/"
     private const val DEFAULT_HOST = "wss://www.mooger8.com/"
     var version = Int.MAX_VALUE
     var myName = ""
@@ -177,9 +178,9 @@ object Constant {
 
     fun getPushLocalFileUrl() = "${getBaseUrl()}/fileUpload/upload?robotId=$robotId"
 
-    fun upgrade() = "${getBaseUrl()}/api/qwPone/upgrade"
+    fun upgrade() = "${getBaseUrl()}api/qwPone/upgrade"
 
-    fun saveRebot() = "${getBaseUrl()}/api/qwPone/saveRebot"
+    fun saveRebot() = "${getBaseUrl()}api/qwPone/saveRebot"
 
     private fun getBaseUrl() = host.replace(wssRegex, "https").replace(wsRegex, "http")
 

+ 0 - 2
app/src/main/java/org/yameida/worktool/activity/ListenActivity.kt

@@ -403,12 +403,10 @@ class ListenActivity : AppCompatActivity() , HttpCallback {
 
     override fun onSuccess(result: Boolean) {
         if (result){
-//            ToastUtils.showShort("保存成功")
             Constant.robotId = et_channel.text.toString().trim()
             HttpUtil.upgrade(this)
         }else{
             et_channel.setText("")
-//            ToastUtils.showShort("账号已存在,请确认")
         }
     }
 

+ 2 - 0
app/src/main/java/org/yameida/worktool/config/GlobalException.java

@@ -3,6 +3,7 @@ package org.yameida.worktool.config;
 import android.util.Log;
 
 import com.blankj.utilcode.util.AppUtils;
+import com.blankj.utilcode.util.LogUtils;
 
 public class GlobalException implements Thread.UncaughtExceptionHandler {
     private final static GlobalException myCrashHandler = new GlobalException();
@@ -16,6 +17,7 @@ public class GlobalException implements Thread.UncaughtExceptionHandler {
 
     @Override
     public void uncaughtException(Thread arg0, Throwable arg1) {
+        LogUtils.e("崩溃了~~");
         Log.e("GlobalException", "-------------Caught Exception-------------");
         arg1.printStackTrace();
         try {

+ 7 - 5
app/src/main/java/org/yameida/worktool/service/WeworkOperationImpl.kt

@@ -4202,7 +4202,8 @@ object WeworkOperationImpl {
         }
         //聊天消息列表 1ListView 0RecycleView xViewGroup
         val list = AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView)
-        if (list != null) {
+        //暂时注释掉这个判断,很奇怪为什么有时候为空
+//        if (list != null) {
             val frontNode = AccessibilityUtil.findFrontNode(list, 2)
             val textViewList = AccessibilityUtil.findAllOnceByClazz(frontNode, Views.TextView)
             if (textViewList.size >= 2) {
@@ -4308,10 +4309,10 @@ object WeworkOperationImpl {
                 error("未发现搜索和多选按钮")
                 return selectResult
             }
-        }
-        LogUtils.e("未知错误")
-        error("未知错误")
-        return selectResult
+//        }
+//        LogUtils.e("未知错误")
+//        error("未知错误")
+//        return selectResult
     }
 
     /**
@@ -4508,6 +4509,7 @@ object WeworkOperationImpl {
                     for (select in LinkedHashSet(selectList)) {
                         val needTrim = select.contains(Constant.regTrimTitle)
                         val trimTitle = select.replace(Constant.regTrimTitle, "")
+                        sleep(Constant.POP_WINDOW_INTERVAL)
                         AccessibilityUtil.performClick(multiButton)
                         AccessibilityUtil.findTextInput(getRoot(), trimTitle)
                         sleep(Constant.POP_WINDOW_INTERVAL)

+ 2 - 2
app/src/main/java/org/yameida/worktool/utils/HttpUtil.kt

@@ -218,7 +218,7 @@ object HttpUtil {
                         GsonUtils.fromJson(
                             response.body(),
                             UpgradeResult::class.java
-                        )
+                        ) ?: return
                     if (commonResult.code == 100) {
                         if (commonResult.result) {
                             XUpdate.newBuild(context)
@@ -249,7 +249,7 @@ object HttpUtil {
                         GsonUtils.fromJson(
                             response.body(),
                             SaveRebotResult::class.java
-                        )
+                        ) ?: return
                     ToastUtils.showLong(commonResult.msg)
                     commonResult.result.num?.let { SPUtils.getInstance().put("num", it) }
                     if (commonResult.code == 100) {

+ 9 - 10
app/src/main/java/org/yameida/worktool/utils/WebSocketManager.java

@@ -34,7 +34,7 @@ public class WebSocketManager {
     private static final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
     public static Map<String, WebSocketManager> webSocketManager = new ConcurrentHashMap<>();
     private static final int reconnectInt = 5000;  //毫秒
-    private static final long heartBeatRate = 5;  //秒
+    private static final long heartBeatRate = 10;  //秒
     private Map<String, Long> messageIdMap = new ConcurrentHashMap<>();
     private ScheduledFuture task;
     private WebSocket socket;
@@ -180,16 +180,15 @@ public class WebSocketManager {
                 reConnect();
                 //重连后刷新连接时间
                 lastConnectedTime = System.currentTimeMillis();
+            } else if (!connecting && lastMessage != 0L && (System.currentTimeMillis() - lastMessage) > HEARTBEAT_INTERVAL) {
+                //断开链接后关闭新消息接收
+                WeworkController.INSTANCE.setEnableLoopRunning(false);
+                //断开链接后进入重连
+                reConnect();
+                //重连后刷新连接时间
+                lastConnectedTime = System.currentTimeMillis();
+                lastMessage = 0L;
             }
-//            else if (!connecting && lastMessage != 0L && (System.currentTimeMillis() - lastMessage) > HEARTBEAT_INTERVAL) {
-//                //断开链接后关闭新消息接收
-//                WeworkController.INSTANCE.setEnableLoopRunning(false);
-//                //断开链接后进入重连
-//                reConnect();
-//                //重连后刷新连接时间
-//                lastConnectedTime = System.currentTimeMillis();
-//                lastMessage = 0L;
-//            }
             else if (System.currentTimeMillis() % 1000 == 0) {
                 socket.send("{\"td\":" + System.currentTimeMillis() + "}");
             }

+ 77 - 5
app/src/main/java/org/yameida/worktool/utils/WeworkTextUtil.kt

@@ -6,6 +6,7 @@ import org.yameida.worktool.Constant
 import org.yameida.worktool.model.WeworkMessageBean
 import org.yameida.worktool.service.WeworkController
 import org.yameida.worktool.service.getRoot
+import org.yameida.worktool.service.log
 import org.yameida.worktool.service.sleep
 import org.yameida.worktool.utils.AccessibilityUtil.findAllByClazz
 import org.yameida.worktool.utils.AccessibilityUtil.findAllOnceByClazz
@@ -429,11 +430,27 @@ object WeworkTextUtil {
                     val textNode = AccessibilityUtil.findOnceByText(backNode, replyContent)
                     if (textNode != null && replyContent.isNotEmpty()) {
                         LogUtils.d("nameList: $nameList\nreplyContent: $replyContent")
-                        return longClickMessageItem(
+                        var longClickMessageItem = longClickMessageItem(
                             item,
                             WeworkMessageBean.ROOM_TYPE_INTERNAL_CONTACT,
                             *key
                         )
+                        if (!longClickMessageItem && num == 2) {
+                            log(
+                                "长按转发失败11111 type nameList: $nameList\n" +
+                                        "replyContent: $replyContent",
+                                WeworkMessageBean.ROBOT_ERROR_LOG
+                            )
+                            return longClickMessageItem(
+                                node,
+                                replyTextType,
+                                replyNick,
+                                replyContent,
+                                *key,
+                                num = 1
+                            )
+                        }
+                        return longClickMessageItem
                     }
                 }
             }
@@ -455,11 +472,27 @@ object WeworkTextUtil {
                         }
                         if (replyTextType == WeworkMessageBean.TEXT_TYPE_LINK && replyTextType == textTypeFromItem) {
                             LogUtils.d("nameList: $nameList\nreplyContent: $replyContent")
-                            return longClickMessageItem(
+                            var longClickMessageItem = longClickMessageItem(
                                 item,
                                 WeworkMessageBean.ROOM_TYPE_INTERNAL_GROUP,
                                 *key
                             )
+                            if (!longClickMessageItem && num == 2) {
+                                log(
+                                    "长按转发失败11113 nameList: $nameList\n" +
+                                            "replyContent: $replyContent",
+                                    WeworkMessageBean.ROBOT_ERROR_LOG
+                                )
+                                return longClickMessageItem(
+                                    node,
+                                    replyTextType,
+                                    replyNick,
+                                    replyContent,
+                                    *key,
+                                    num = 1
+                                )
+                            }
+                            return true
                         }
                         if ((replyTextType == WeworkMessageBean.TEXT_TYPE_FILE || replyTextType == WeworkMessageBean.TEXT_TYPE_VIDEO)
                             && replyContent.contains("###")
@@ -475,21 +508,60 @@ object WeworkTextUtil {
                                 ) != null
                             ) {
                                 LogUtils.d("nameList: $nameList\nreplyContent: $replyContent")
-                                return longClickMessageItem(
+                                var longClickMessageItem = longClickMessageItem(
                                     item,
                                     WeworkMessageBean.ROOM_TYPE_INTERNAL_GROUP,
                                     *key
                                 )
+                                if (!longClickMessageItem && num == 2) {
+                                    log(
+                                        "长按转发失败11112 nameList: $nameList\n" +
+                                                "replyContent: $replyContent",
+                                        WeworkMessageBean.ROBOT_ERROR_LOG
+                                    )
+                                    return longClickMessageItem(
+                                        node,
+                                        replyTextType,
+                                        replyNick,
+                                        replyContent,
+                                        *key,
+                                        num = 1
+                                    )
+                                }
+                                return true
                             }
                         }
+                        sleep(Constant.CHANGE_PAGE_INTERVAL)
                         val textNode = AccessibilityUtil.findOnceByText(backNode, replyContent)
                         if (textNode != null && replyContent.isNotEmpty()) {
                             LogUtils.d("nameList: $nameList\nreplyContent: $replyContent")
-                            return longClickMessageItem(
+                            var longClickMessageItem = longClickMessageItem(
                                 item,
                                 WeworkMessageBean.ROOM_TYPE_INTERNAL_GROUP,
                                 *key
                             )
+                            if (!longClickMessageItem && num == 2) {
+                                log(
+                                    "长按转发失败11111nameList: $nameList\n" +
+                                            "replyContent: $replyContent",
+                                    WeworkMessageBean.ROBOT_ERROR_LOG
+                                )
+                                return longClickMessageItem(
+                                    node,
+                                    replyTextType,
+                                    replyNick,
+                                    replyContent,
+                                    *key,
+                                    num = 1
+                                )
+                            }
+                            return true
+                        }else{
+                            log(
+                                "找不到消息: $nameList\n" +
+                                        "replyContent: $replyContent",
+                                WeworkMessageBean.ROBOT_ERROR_LOG
+                            )
                         }
                     }
                 }
@@ -573,7 +645,7 @@ object WeworkTextUtil {
             return AccessibilityUtil.clickByNode(WeworkController.weworkService, backNode)
         }
         AccessibilityUtil.performLongClickWithSon(backNode)
-        sleep(Constant.CHANGE_PAGE_INTERVAL)
+        sleep(Constant.BASE_GENERAL_INTERVAL)
         val optionRvList = findAllByClazz(getRoot(), Views.RecyclerView, Views.ViewGroup)
         for (optionRv in optionRvList) {
             val keyTv = AccessibilityUtil.findOnceByText(optionRv, *key, exact = true)