Shamrock: 修复获取历史消息丢失当前ID的消息

This commit is contained in:
WhiteChi 2023-11-11 23:02:36 +08:00
parent 80bb591a1b
commit ca62b33275
2 changed files with 42 additions and 18 deletions

View File

@ -5,6 +5,7 @@ import com.tencent.qqnt.kernel.nativeinterface.MsgRecord
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonElement
import moe.fuqiuluo.qqinterface.servlet.MsgSvc
import moe.fuqiuluo.qqinterface.servlet.msg.convert.MessageConvert import moe.fuqiuluo.qqinterface.servlet.msg.convert.MessageConvert
import moe.fuqiuluo.shamrock.helper.MessageHelper import moe.fuqiuluo.shamrock.helper.MessageHelper
import moe.fuqiuluo.shamrock.helper.db.MessageDB import moe.fuqiuluo.shamrock.helper.db.MessageDB
@ -53,7 +54,8 @@ internal object GetHistoryMsg: IActionHandler() {
return logic(result.msg ?: "获取历史消息失败", echo = echo) return logic(result.msg ?: "获取历史消息失败", echo = echo)
} }
val msgList = result.data!!.map { msg -> val msgList = ArrayList<MessageDetail>().apply {
addAll(result.data!!.map { msg ->
val msgHash = MessageHelper.generateMsgIdHash(msg.chatType, msg.msgId) val msgHash = MessageHelper.generateMsgIdHash(msg.chatType, msg.msgId)
MessageDetail( MessageDetail(
time = msg.msgTime.toInt(), time = msg.msgTime.toInt(),
@ -70,6 +72,28 @@ internal object GetHistoryMsg: IActionHandler() {
groupId = if (msg.chatType == MsgConstant.KCHATTYPEGROUP) msg.peerUin else 0, groupId = if (msg.chatType == MsgConstant.KCHATTYPEGROUP) msg.peerUin else 0,
targetId = if (msg.chatType != MsgConstant.KCHATTYPEGROUP) msg.peerUin else 0 targetId = if (msg.chatType != MsgConstant.KCHATTYPEGROUP) msg.peerUin else 0
) )
})
if (startMsgId != 0L) {
val msg = MsgSvc.getMsgByQMsgId(chatType, peerId, startMsgId).onFailure {
return logic("Obtain msg failed, please check your msg_id.", echo)
}.getOrThrow()
val seq = msg.clientSeq.toInt()
add(MessageDetail(
time = msg.msgTime.toInt(),
msgType = MessageHelper.obtainDetailTypeByMsgType(msg.chatType),
msgId = MessageHelper.generateMsgIdHash(msg.chatType, msg.msgId),
realId = seq,
sender = MessageSender(
msg.senderUin, msg.sendNickName, "unknown", 0, msg.senderUid
),
message = MessageConvert.convertMessageRecordToMsgSegment(msg).map {
it.toJson()
},
peerId = msg.peerUin,
groupId = if (msg.chatType == MsgConstant.KCHATTYPEGROUP) msg.peerUin else 0,
targetId = if (msg.chatType != MsgConstant.KCHATTYPEGROUP) msg.peerUin else 0
))
}
} }
return ok(data = GetHistoryMsgResult(msgList), echo = echo) return ok(data = GetHistoryMsgResult(msgList), echo = echo)

View File

@ -35,7 +35,7 @@ import java.util.concurrent.TimeUnit
fun Routing.otherAction() { fun Routing.otherAction() {
if (ShamrockConfig.allowShell()) { if (ShamrockConfig.allowShell()) {
getOrPost("/shell") { post("/shell") {
val runtime = Runtime.getRuntime() val runtime = Runtime.getRuntime()
val dir = fetchOrThrow("dir") val dir = fetchOrThrow("dir")
val out = StringBuilder() val out = StringBuilder()