Shamrock: fix #171 #165

This commit is contained in:
WhiteChi 2023-12-23 05:06:37 +08:00
parent 77504d68fd
commit 8fadd0016a
2 changed files with 15 additions and 13 deletions

View File

@ -176,9 +176,6 @@ internal object MsgSvc: BaseSvc() {
fromId: String = peedId,
retryCnt: Int = 3
): Result<Pair<Long, Int>> {
//LogCenter.log(message.toString(), Level.ERROR)
//callback.msgHash = result.second 什么垃圾代码万一cb比你快你不就寄了
// 主动临时消息
when (chatType) {
MsgConstant.KCHATTYPETEMPC2CFROMGROUP -> {
@ -188,13 +185,7 @@ internal object MsgSvc: BaseSvc() {
}
}
}
val result = MessageHelper.sendMessageWithoutMsgId(
chatType,
peedId,
message,
fromId,
MessageCallback(peedId, 0)
)
val result = MessageHelper.sendMessageWithoutMsgId(chatType, peedId, message, fromId, MessageCallback(peedId, 0))
return if (result.isFailure
&& result.exceptionOrNull()?.javaClass == SendMsgException::class.java
&& retryCnt > 0) {

View File

@ -9,6 +9,7 @@ import com.tencent.qqnt.msg.api.IMsgService
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withTimeoutOrNull
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
@ -38,7 +39,11 @@ internal object MessageHelper {
): Pair<Long, Int> {
val uniseq = generateMsgId(chatType)
val msg = messageArrayToMessageElements(chatType, uniseq.second, peerId, decodeCQCode(message)).also {
if (it.second.isEmpty() && !it.first) error("消息合成失败,请查看日志或者检查输入。")
if (it.second.isEmpty() && !it.first) {
error("消息合成失败,请查看日志或者检查输入。")
} else if (it.second.isEmpty()) {
return System.currentTimeMillis() to 0
}
}.second.filter {
it.elementType != -1
} as ArrayList<MsgElement>
@ -59,6 +64,12 @@ internal object MessageHelper {
}.second.filter {
it.elementType != -1
} as ArrayList<MsgElement>
// ActionMsg No Care
if (msg.isEmpty()) {
return Result.success(System.currentTimeMillis() to 0)
}
val totalSize = msg.filter {
it.elementType == MsgConstant.KELEMTYPEPIC ||
it.elementType == MsgConstant.KELEMTYPEPTT ||
@ -67,11 +78,11 @@ internal object MessageHelper {
(it.picElement?.fileSize ?: 0) + (it.pttElement?.fileSize
?: 0) + (it.videoElement?.fileSize ?: 0)
}.reduceOrNull { a, b -> a + b } ?: 0
val estimateTime = (totalSize / (300 * 1024)) * 1000 + 2000
val estimateTime = (totalSize / (300 * 1024)) * 1000 + 5000
lateinit var sendResultPair: Pair<Long, Int>
val sendRet = withTimeoutOrNull<Pair<Int, String>>(estimateTime) {
suspendCoroutine {
suspendCancellableCoroutine {
GlobalScope.launch {
sendResultPair = sendMessageWithoutMsgId(
chatType,