mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: 自発メッセージメッセージIDエラーの修正
Signed-off-by: WhiteChi <whitechi73@outlook.com>
This commit is contained in:
parent
e41b7515d3
commit
6f1ba71664
@ -50,6 +50,36 @@ internal object MsgSvc: BaseSvc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getMsgByQMsgId(
|
||||||
|
chatType: Int,
|
||||||
|
peerId: String,
|
||||||
|
qqMsgId: Long
|
||||||
|
): Result<MsgRecord> {
|
||||||
|
val contact = MessageHelper.generateContact(chatType, peerId)
|
||||||
|
|
||||||
|
val msg = withTimeoutOrNull(5000) {
|
||||||
|
val service = QRoute.api(IMsgService::class.java)
|
||||||
|
suspendCancellableCoroutine { continuation ->
|
||||||
|
service.getMsgsByMsgId(contact, arrayListOf(qqMsgId)) { code, _, msgRecords ->
|
||||||
|
if (code == 0 && msgRecords.isNotEmpty()) {
|
||||||
|
continuation.resume(msgRecords.first())
|
||||||
|
} else {
|
||||||
|
continuation.resume(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continuation.invokeOnCancellation {
|
||||||
|
continuation.resume(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (msg != null) {
|
||||||
|
Result.success(msg)
|
||||||
|
} else {
|
||||||
|
Result.failure(Exception("获取消息失败"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 什么鸟屎都获取不到
|
* 什么鸟屎都获取不到
|
||||||
*/
|
*/
|
||||||
@ -59,7 +89,7 @@ internal object MsgSvc: BaseSvc() {
|
|||||||
seq: Long
|
seq: Long
|
||||||
): Result<MsgRecord> {
|
): Result<MsgRecord> {
|
||||||
val contact = MessageHelper.generateContact(chatType, peerId)
|
val contact = MessageHelper.generateContact(chatType, peerId)
|
||||||
val msg = withTimeoutOrNull(60 * 1000) {
|
val msg = withTimeoutOrNull(1000) {
|
||||||
val service = QRoute.api(IMsgService::class.java)
|
val service = QRoute.api(IMsgService::class.java)
|
||||||
suspendCancellableCoroutine { continuation ->
|
suspendCancellableCoroutine { continuation ->
|
||||||
service.getMsgsBySeqs(contact, arrayListOf(seq)) { code, _, msgRecords ->
|
service.getMsgsBySeqs(contact, arrayListOf(seq)) { code, _, msgRecords ->
|
||||||
|
@ -2,6 +2,7 @@ package moe.fuqiuluo.qqinterface.servlet.msg.convert
|
|||||||
|
|
||||||
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
||||||
import com.tencent.qqnt.kernel.nativeinterface.MsgElement
|
import com.tencent.qqnt.kernel.nativeinterface.MsgElement
|
||||||
|
import moe.fuqiuluo.qqinterface.servlet.MsgSvc
|
||||||
import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc
|
import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc
|
||||||
import moe.fuqiuluo.shamrock.helper.ContactHelper
|
import moe.fuqiuluo.shamrock.helper.ContactHelper
|
||||||
import moe.fuqiuluo.shamrock.helper.Level
|
import moe.fuqiuluo.shamrock.helper.Level
|
||||||
@ -252,7 +253,11 @@ internal sealed class MessageElemConverter: IMessageConvert {
|
|||||||
} else {
|
} else {
|
||||||
MessageDB.getInstance().messageMappingDao()
|
MessageDB.getInstance().messageMappingDao()
|
||||||
.queryByMsgSeq(chatType, peerId, reply.replayMsgSeq?.toInt() ?: 0)?.msgHashId
|
.queryByMsgSeq(chatType, peerId, reply.replayMsgSeq?.toInt() ?: 0)?.msgHashId
|
||||||
?: MessageHelper.generateMsgIdHash(chatType, reply.sourceMsgIdInRecords)
|
?:
|
||||||
|
kotlin.run {
|
||||||
|
LogCenter.log("消息映射关系未找到: Message($reply)", Level.WARN)
|
||||||
|
MessageHelper.generateMsgIdHash(chatType, reply.sourceMsgIdInRecords)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return MessageSegment(
|
return MessageSegment(
|
||||||
|
@ -5,7 +5,9 @@ import moe.fuqiuluo.shamrock.helper.MessageHelper
|
|||||||
import com.tencent.qqnt.kernel.nativeinterface.*
|
import com.tencent.qqnt.kernel.nativeinterface.*
|
||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import moe.fuqiuluo.qqinterface.servlet.MsgSvc
|
||||||
import moe.fuqiuluo.qqinterface.servlet.msg.convert.toCQCode
|
import moe.fuqiuluo.qqinterface.servlet.msg.convert.toCQCode
|
||||||
import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc
|
import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc
|
||||||
import moe.fuqiuluo.shamrock.remote.service.config.ShamrockConfig
|
import moe.fuqiuluo.shamrock.remote.service.config.ShamrockConfig
|
||||||
@ -16,6 +18,8 @@ import moe.fuqiuluo.shamrock.remote.service.data.push.MessageTempSource
|
|||||||
import moe.fuqiuluo.shamrock.remote.service.data.push.PostType
|
import moe.fuqiuluo.shamrock.remote.service.data.push.PostType
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import java.util.HashMap
|
import java.util.HashMap
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
internal object AioListener: IKernelMsgListener {
|
internal object AioListener: IKernelMsgListener {
|
||||||
override fun onRecvMsg(msgList: ArrayList<MsgRecord>) {
|
override fun onRecvMsg(msgList: ArrayList<MsgRecord>) {
|
||||||
@ -97,10 +101,28 @@ internal object AioListener: IKernelMsgListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAddSendMsg(record: MsgRecord) {
|
override fun onAddSendMsg(tmpRecord: MsgRecord) {
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
try {
|
try {
|
||||||
val msgHash = MessageHelper.generateMsgIdHash(record.chatType, record.msgId)
|
val msgHash = MessageHelper.generateMsgIdHash(tmpRecord.chatType, tmpRecord.msgId)
|
||||||
|
|
||||||
|
val record = suspendCoroutine<MsgRecord?> {
|
||||||
|
GlobalScope.launch {
|
||||||
|
while (true) {
|
||||||
|
MsgSvc.getMsgByQMsgId(tmpRecord.chatType, tmpRecord.peerUin.toString(), tmpRecord.msgId).onSuccess { record ->
|
||||||
|
if (record.sendStatus == MsgConstant.KSENDSTATUSSUCCESS ||
|
||||||
|
record.sendStatus == MsgConstant.KSENDSTATUSSUCCESSNOSEQ
|
||||||
|
) {
|
||||||
|
it.resume(record)
|
||||||
|
} else if (record.sendStatus == MsgConstant.KSENDSTATUSFAILED) {
|
||||||
|
it.resume(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delay(50)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} ?: return@launch
|
||||||
|
|
||||||
MessageHelper.saveMsgMapping(
|
MessageHelper.saveMsgMapping(
|
||||||
hash = msgHash,
|
hash = msgHash,
|
||||||
qqMsgId = record.msgId,
|
qqMsgId = record.msgId,
|
||||||
@ -114,7 +136,7 @@ internal object AioListener: IKernelMsgListener {
|
|||||||
val rawMsg = record.elements.toCQCode(record.chatType, record.peerUin.toString())
|
val rawMsg = record.elements.toCQCode(record.chatType, record.peerUin.toString())
|
||||||
if (rawMsg.isEmpty()) return@launch
|
if (rawMsg.isEmpty()) return@launch
|
||||||
|
|
||||||
LogCenter.log("发送消息($msgHash|${record.msgSeq}): $rawMsg")
|
LogCenter.log("发送消息($msgHash | ${record.msgSeq} | ${record.msgId}): $rawMsg")
|
||||||
|
|
||||||
if (!ShamrockConfig.enableSelfMsg())
|
if (!ShamrockConfig.enableSelfMsg())
|
||||||
return@launch
|
return@launch
|
||||||
|
@ -247,13 +247,12 @@ internal object PrimitiveListener {
|
|||||||
val tipText = if (detail.has(11, 9)) detail[11, 9, 2].asUtf8String else ""
|
val tipText = if (detail.has(11, 9)) detail[11, 9, 2].asUtf8String else ""
|
||||||
val mapping = MessageHelper.getMsgMappingBySeq(MsgConstant.KCHATTYPEGROUP, msgSeq.toInt())
|
val mapping = MessageHelper.getMsgMappingBySeq(MsgConstant.KCHATTYPEGROUP, msgSeq.toInt())
|
||||||
if (mapping == null) {
|
if (mapping == null) {
|
||||||
LogCenter.log("由于缺失消息映射关系,消息撤回事件无法推送!", Level.WARN)
|
LogCenter.log("由于缺失消息映射关系(seq = $msgSeq),消息撤回事件无法推送!", Level.WARN)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val msgHash = mapping.msgHashId
|
val msgHash = mapping.msgHashId
|
||||||
val operator = ContactHelper.getUinByUidAsync(operatorUid).toLong()
|
val operator = ContactHelper.getUinByUidAsync(operatorUid).toLong()
|
||||||
val target = ContactHelper.getUinByUidAsync(targetUid).toLong()
|
val target = ContactHelper.getUinByUidAsync(targetUid).toLong()
|
||||||
|
|
||||||
LogCenter.log("群消息撤回($groupCode): $operator -> $target, seq = $msgSeq, hash = $msgHash, tip = $tipText")
|
LogCenter.log("群消息撤回($groupCode): $operator -> $target, seq = $msgSeq, hash = $msgHash, tip = $tipText")
|
||||||
|
|
||||||
if(!GlobalEventTransmitter.GroupNoticeTransmitter
|
if(!GlobalEventTransmitter.GroupNoticeTransmitter
|
||||||
|
Loading…
x
Reference in New Issue
Block a user