mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: fix #106
This commit is contained in:
parent
0bb871bf01
commit
b2adc5cedf
@ -24,7 +24,7 @@ android {
|
||||
minSdk = 24
|
||||
targetSdk = 33
|
||||
versionCode = (System.currentTimeMillis() / 1000).toInt()
|
||||
versionName = "1.0.6-dev" + gitCommitHash()
|
||||
versionName = "1.0.7-dev" + gitCommitHash()
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
|
@ -184,6 +184,32 @@ internal object MessageHelper {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun sendMessageNoCb(
|
||||
chatType: Int,
|
||||
peerId: String,
|
||||
message: JsonArray,
|
||||
fromId: String = peerId
|
||||
): Pair<Int, Long> {
|
||||
val uniseq = generateMsgId(chatType)
|
||||
val msg = messageArrayToMessageElements(chatType, uniseq.second, peerId, message).also {
|
||||
if (it.second.isEmpty() && !it.first) error("消息合成失败,请查看日志或者检查输入。")
|
||||
}.second.filter {
|
||||
it.elementType != -1
|
||||
} as ArrayList<MsgElement>
|
||||
val contact = generateContact(chatType, peerId, fromId)
|
||||
val nonMsg: Boolean = message.isEmpty()
|
||||
return if (!nonMsg) {
|
||||
val service = QRoute.api(IMsgService::class.java)
|
||||
return suspendCoroutine {
|
||||
service.sendMsg(contact, uniseq.second, msg) { code, why ->
|
||||
it.resume(code to uniseq.second)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
-1 to uniseq.second
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun generateContact(chatType: Int, id: String, subId: String = ""): Contact {
|
||||
val peerId = if (MsgConstant.KCHATTYPEC2C == chatType || MsgConstant.KCHATTYPETEMPC2CFROMGROUP == chatType) {
|
||||
ContactHelper.getUidByUinAsync(id.toLong())
|
||||
|
@ -2,8 +2,6 @@ package moe.fuqiuluo.shamrock.remote.action.handlers
|
||||
|
||||
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
||||
import com.tencent.qqnt.kernel.nativeinterface.MultiMsgInfo
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.json.JsonArray
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
@ -19,8 +17,6 @@ import moe.fuqiuluo.shamrock.remote.action.IActionHandler
|
||||
import moe.fuqiuluo.shamrock.remote.service.data.ForwardMessageResult
|
||||
import moe.fuqiuluo.shamrock.tools.*
|
||||
import moe.fuqiuluo.shamrock.xposed.helper.NTServiceFetcher
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
sealed interface ForwardMsgNode {
|
||||
class MessageIdNode(
|
||||
@ -87,7 +83,7 @@ internal object SendForwardMessage : IActionHandler() {
|
||||
val msgService = sessionService.msgService
|
||||
val selfUin = TicketSvc.getUin()
|
||||
|
||||
val msgs = message.map {
|
||||
val nodes = message.map {
|
||||
if (it.asJsonObject["type"].asStringOrNull != "node") return@map ForwardMsgNode.EmptyNode // 过滤非node类型消息段
|
||||
it.asJsonObject["data"].asJsonObject.let { data ->
|
||||
if (data.containsKey("content")) {
|
||||
@ -113,10 +109,7 @@ internal object SendForwardMessage : IActionHandler() {
|
||||
} else {
|
||||
val record = recordResult.getOrThrow()
|
||||
ForwardMsgNode.MessageNode(
|
||||
name = record.sendMemberName
|
||||
.ifBlank { record.sendNickName }
|
||||
.ifBlank { record.sendRemarkName }
|
||||
.ifBlank { record.peerName },
|
||||
name = record.peerName,
|
||||
content = record.toSegments().map { segment ->
|
||||
segment.toJson()
|
||||
}.json
|
||||
@ -127,31 +120,18 @@ internal object SendForwardMessage : IActionHandler() {
|
||||
}
|
||||
}.filter {
|
||||
it.content != null
|
||||
}.map { node ->
|
||||
val result = MessageHelper.sendMessageNoCb(MsgConstant.KCHATTYPEC2C, selfUin, node.content.let { msg ->
|
||||
when (msg) {
|
||||
is JsonArray -> msg
|
||||
is JsonObject -> listOf(msg).jsonArray
|
||||
else -> MessageHelper.decodeCQCode(msg.asString)
|
||||
}
|
||||
|
||||
val multiNodes = msgs.map { node ->
|
||||
suspendCoroutine {
|
||||
GlobalScope.launch {
|
||||
var msgId: Long = 0
|
||||
msgId = MessageHelper.sendMessageWithMsgId(MsgConstant.KCHATTYPEC2C,
|
||||
selfUin,
|
||||
node.content!!.let { msg ->
|
||||
if (msg is JsonArray) msg
|
||||
else if (msg is JsonObject) listOf(msg).jsonArray
|
||||
else MessageHelper.decodeCQCode(msg.asString)
|
||||
},
|
||||
{ code, why ->
|
||||
if (code != 0) {
|
||||
error("合并转发消息节点消息发送失败:$code($why)")
|
||||
}
|
||||
it.resume(node.name to msgId)
|
||||
}).first
|
||||
}.invokeOnCompletion {
|
||||
it?.let {
|
||||
LogCenter.log("合并转发消息节点消息发送失败:${it.stackTraceToString()}", Level.ERROR)
|
||||
}
|
||||
}
|
||||
})
|
||||
if (result.first != 0) {
|
||||
LogCenter.log("合并转发消息节点消息发送失败", Level.WARN)
|
||||
}
|
||||
return@map result.second
|
||||
}
|
||||
|
||||
val from = MessageHelper.generateContact(MsgConstant.KCHATTYPEC2C, selfUin)
|
||||
@ -159,7 +139,7 @@ internal object SendForwardMessage : IActionHandler() {
|
||||
|
||||
val uniseq = MessageHelper.generateMsgId(chatType)
|
||||
msgService.multiForwardMsg(ArrayList<MultiMsgInfo>().apply {
|
||||
multiNodes.forEach { add(MultiMsgInfo(it.second, it.first)) }
|
||||
nodes.forEach { add(MultiMsgInfo(it, "Anno")) }
|
||||
}.also { it.reverse() }, from, to, MsgSvc.MessageCallback(peerId, uniseq.first))
|
||||
|
||||
return ok(
|
||||
|
Loading…
x
Reference in New Issue
Block a user