update 推送图片

This commit is contained in:
gallonyin
2023-02-27 23:53:50 +08:00
parent 0f792ee75a
commit 83373395a2
2 changed files with 40 additions and 15 deletions

View File

@@ -132,7 +132,7 @@ object WeworkLoopImpl {
for (i in 0 until list.childCount) { for (i in 0 until list.childCount) {
val item = list.getChild(i) val item = list.getChild(i)
if (item != null && item.childCount > 0) { if (item != null && item.childCount > 0) {
messageList.add(parseChatMessageItem(item, titleList, roomType)) messageList.add(parseChatMessageItem(item, titleList, roomType, false))
} }
} }
} }
@@ -144,7 +144,7 @@ object WeworkLoopImpl {
for (i in 0 until list2.childCount) { for (i in 0 until list2.childCount) {
val item = list2.getChild(i) val item = list2.getChild(i)
if (item != null && item.childCount > 0) { if (item != null && item.childCount > 0) {
messageList2.add(parseChatMessageItem(item, titleList, roomType)) messageList2.add(parseChatMessageItem(item, titleList, roomType, true))
} }
} }
} }
@@ -163,7 +163,13 @@ object WeworkLoopImpl {
null null
) )
) )
SPUtils.getInstance("lastSyncMessage").put(title, messageList.last().itemMessageList.lastOrNull()?.text) val lastMessage = messageList.last()
val lastSyncMessage = if (lastMessage.textType == 2) {
"[图片]"
} else {
lastMessage.itemMessageList.lastOrNull()?.text
}
SPUtils.getInstance("lastSyncMessage").put(title, lastSyncMessage)
//推测是否回复并在房间等待指令 //推测是否回复并在房间等待指令
if (needInfer) { if (needInfer) {
val lastMessage = messageList.lastOrNull() val lastMessage = messageList.lastOrNull()
@@ -467,7 +473,7 @@ object WeworkLoopImpl {
continue continue
} }
if (SPUtils.getInstance("noSyncMessage").getString(title) != lastSyncMessage) { if (SPUtils.getInstance("noSyncMessage").getString(title) != lastSyncMessage) {
LogUtils.e("发现不一致消息: $tvList") LogUtils.e("发现不一致消息: $tvList $lastSyncMessage")
error("发现不一致消息: $tvList $lastSyncMessage") error("发现不一致消息: $tvList $lastSyncMessage")
SPUtils.getInstance("noSyncMessage").put(title, lastSyncMessage) SPUtils.getInstance("noSyncMessage").put(title, lastSyncMessage)
if (AccessibilityUtil.performClick(item)) { if (AccessibilityUtil.performClick(item)) {
@@ -493,7 +499,8 @@ object WeworkLoopImpl {
private fun parseChatMessageItem( private fun parseChatMessageItem(
node: AccessibilityNodeInfo, node: AccessibilityNodeInfo,
titleList: ArrayList<String>, titleList: ArrayList<String>,
roomType: Int roomType: Int,
doubleCheck: Boolean
): WeworkMessageBean.SubMessageBean { ): WeworkMessageBean.SubMessageBean {
val message: WeworkMessageBean.SubMessageBean val message: WeworkMessageBean.SubMessageBean
val nameList = arrayListOf<String>() val nameList = arrayListOf<String>()
@@ -537,7 +544,7 @@ object WeworkLoopImpl {
} }
message = WeworkMessageBean.SubMessageBean(0, textType, itemMessageList, nameList) message = WeworkMessageBean.SubMessageBean(0, textType, itemMessageList, nameList)
//图片类型特殊处理 //图片类型特殊处理
if (Constant.pushImage && textType == 2) { if (doubleCheck && Constant.pushImage && textType == 2) {
val lastPicCreateTime = MultiFileObserver.lastPicCreateTime val lastPicCreateTime = MultiFileObserver.lastPicCreateTime
val lastPicPath = MultiFileObserver.lastPicPath val lastPicPath = MultiFileObserver.lastPicPath
LogUtils.d("发现图片类型应该点击") LogUtils.d("发现图片类型应该点击")

View File

@@ -1,17 +1,16 @@
package org.yameida.worktool.utils package org.yameida.worktool.utils
import com.blankj.utilcode.util.AppUtils import com.blankj.utilcode.util.*
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import com.lzy.okgo.OkGo import com.lzy.okgo.OkGo
import com.lzy.okgo.callback.StringCallback import com.lzy.okgo.callback.StringCallback
import com.lzy.okgo.model.Response import com.lzy.okgo.model.Response
import model.UpdateConfig import model.UpdateConfig
import org.json.JSONObject
import org.yameida.worktool.Constant import org.yameida.worktool.Constant
import org.yameida.worktool.R import org.yameida.worktool.R
import org.yameida.worktool.model.network.CheckUpdateResult import org.yameida.worktool.model.network.CheckUpdateResult
import org.yameida.worktool.model.network.GetMyConfigResult import org.yameida.worktool.model.network.GetMyConfigResult
import org.yameida.worktool.service.log
import update.UpdateAppUtils import update.UpdateAppUtils
import java.io.File import java.io.File
@@ -112,19 +111,38 @@ object HttpUtil {
/** /**
* 推送图片 * 推送图片
*/ */
fun pushImage(url: String, groupName: String, receivedName: String?, imagePath: String) { fun pushImage(url: String, titleList: List<String>, receivedName: String?, imagePath: String, roomType: Int) {
val json = JSONObject()
if (receivedName != null) {
json.put("receivedName", receivedName)
json.put("groupName", titleList.lastOrNull())
if (titleList.size > 1) {
json.put("groupRemark", titleList.first())
} else {
json.put("groupRemark", null)
}
} else {
json.put("receivedName", titleList.lastOrNull() { !it.contains("") } ?: "")
json.put("groupName", null)
json.put("groupRemark", null)
}
json.put("image", EncodeUtils.base64Encode2String(File(imagePath).readBytes()))
json.put("robotId", Constant.robotId)
json.put("roomType", roomType)
json.put("atMe", false)
json.put("textType", 2)
OkGo.post<String>(url) OkGo.post<String>(url)
.params("groupName", groupName) .upJson(json)
.params("receivedName", receivedName ?: "")
.params("image", File(imagePath))
.execute(object : StringCallback() { .execute(object : StringCallback() {
override fun onSuccess(response: Response<String>) { override fun onSuccess(response: Response<String>) {
LogUtils.d("推送图片成功: $groupName $receivedName $imagePath") LogUtils.d("推送图片成功: ${titleList.joinToString()} $receivedName $imagePath")
log("推送图片成功: ${titleList.joinToString()} $receivedName $imagePath")
} }
override fun onError(response: Response<String>) { override fun onError(response: Response<String>) {
ToastUtils.showLong("推送图片失败") ToastUtils.showLong("推送图片失败")
LogUtils.e("推送图片失败") LogUtils.e("推送图片失败")
error("推送图片失败: $${titleList.joinToString()} $receivedName $imagePath")
} }
}) })
} }