mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
fix get_group_msg_history
This commit is contained in:
parent
0bca46bba3
commit
5584a41af0
@ -297,7 +297,7 @@ internal object MsgSvc : BaseSvc() {
|
||||
time = msg.contentHead?.msgTime?.toInt() ?: 0,
|
||||
msgType = MessageHelper.obtainDetailTypeByMsgType(chatType),
|
||||
msgId = 0, // MessageHelper.generateMsgIdHash(chatType, msg.content!!.msgViaRandom), msgViaRandom 为空
|
||||
realId = msg.contentHead!!.msgSeq?.toInt() ?: 0,
|
||||
msgSeq = msg.contentHead!!.msgSeq ?: 0,
|
||||
sender = MessageSender(
|
||||
msg.msgHead?.peer ?: 0,
|
||||
msg.msgHead?.responseGrp?.memberCard?.ifEmpty { msg.msgHead?.forward?.friendName }
|
||||
|
@ -1,5 +1,6 @@
|
||||
package moe.fuqiuluo.shamrock.remote.action.handlers
|
||||
|
||||
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
||||
import moe.fuqiuluo.shamrock.helper.db.MessageDB
|
||||
import moe.fuqiuluo.shamrock.remote.action.ActionSession
|
||||
import moe.fuqiuluo.shamrock.remote.action.IActionHandler
|
||||
@ -10,11 +11,16 @@ internal object GetGroupMsgHistory: IActionHandler() {
|
||||
override suspend fun internalHandle(session: ActionSession): String {
|
||||
val groupId = session.getLong("group_id")
|
||||
val cnt = session.getIntOrNull("count") ?: 20
|
||||
val startId = session.getIntOrNull("message_seq")?.let {
|
||||
val startId = session.getIntOrNull("message_id")?.let {
|
||||
if (it == 0) return@let 0L
|
||||
MessageDB.getInstance()
|
||||
.messageMappingDao()
|
||||
.queryByMsgHashId(it)?.qqMsgId
|
||||
} ?: session.getIntOrNull("message_seq")?.let {
|
||||
if (it == 0) return@let 0L
|
||||
MessageDB.getInstance()
|
||||
.messageMappingDao()
|
||||
.queryByMsgSeq(MsgConstant.KCHATTYPEGROUP, groupId.toString(), it)?.qqMsgId
|
||||
} ?: 0L
|
||||
return GetHistoryMsg("group", groupId.toString(), cnt, startId, session.echo)
|
||||
}
|
||||
|
@ -28,11 +28,16 @@ internal object GetHistoryMsg : IActionHandler() {
|
||||
val peerId = session.getLong(if (msgType == "group") "group_id" else "user_id").toString()
|
||||
val cnt = session.getIntOrNull("count") ?: 20
|
||||
|
||||
val startId = session.getIntOrNull("message_seq")?.let {
|
||||
val startId = session.getIntOrNull("message_id")?.let {
|
||||
if (it == 0) return@let 0L
|
||||
MessageDB.getInstance()
|
||||
.messageMappingDao()
|
||||
.queryByMsgHashId(it)?.qqMsgId
|
||||
} ?: session.getIntOrNull("message_seq")?.let {
|
||||
if (it == 0) return@let 0L
|
||||
MessageDB.getInstance()
|
||||
.messageMappingDao()
|
||||
.queryByMsgSeq(MessageHelper.obtainMessageTypeByDetailType(msgType), peerId, it)?.qqMsgId
|
||||
} ?: 0L
|
||||
|
||||
return invoke(msgType, peerId, cnt, startId, echo = session.echo)
|
||||
@ -74,7 +79,7 @@ internal object GetHistoryMsg : IActionHandler() {
|
||||
time = msg.msgTime.toInt(),
|
||||
msgType = MessageHelper.obtainDetailTypeByMsgType(msg.chatType),
|
||||
msgId = msgHash,
|
||||
realId = msg.msgSeq.toInt(),
|
||||
msgSeq = msg.msgSeq,
|
||||
sender = MessageSender(
|
||||
msg.senderUin, msg.sendNickName, "unknown", 0, msg.senderUid, msg.senderUid
|
||||
),
|
||||
@ -92,12 +97,11 @@ internal object GetHistoryMsg : IActionHandler() {
|
||||
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,
|
||||
msgSeq = msg.msgSeq,
|
||||
sender = MessageSender(
|
||||
msg.senderUin, msg.sendNickName
|
||||
.ifEmpty { msg.sendMemberName }
|
||||
@ -107,7 +111,8 @@ internal object GetHistoryMsg : IActionHandler() {
|
||||
message = msg.elements.toSegments(
|
||||
chatType,
|
||||
if (chatType == MsgConstant.KCHATTYPEGUILD) msg.guildId else msg.peerUin.toString(),
|
||||
msg.channelId ?: peerId).toListMap(),
|
||||
msg.channelId ?: peerId
|
||||
).toListMap(),
|
||||
peerId = msg.peerUin,
|
||||
groupId = if (msg.chatType == MsgConstant.KCHATTYPEGROUP) msg.peerUin else 0,
|
||||
targetId = if (msg.chatType != MsgConstant.KCHATTYPEGROUP) msg.peerUin else 0
|
||||
|
@ -25,12 +25,11 @@ internal object GetMsg: IActionHandler() {
|
||||
val msg = MsgSvc.getMsg(msgHash).onFailure {
|
||||
return logic("Obtain msg failed, please check your msg_id.", echo)
|
||||
}.getOrThrow()
|
||||
val seq = msg.msgSeq.toInt()
|
||||
return ok(MessageDetail(
|
||||
time = msg.msgTime.toInt(),
|
||||
msgType = MessageHelper.obtainDetailTypeByMsgType(msg.chatType),
|
||||
msgId = msgHash,
|
||||
realId = seq,
|
||||
msgSeq = msg.msgSeq,
|
||||
sender = MessageSender(
|
||||
msg.senderUin, msg.sendNickName
|
||||
.ifEmpty { msg.sendMemberName }
|
||||
|
@ -95,11 +95,18 @@ fun Routing.messageAction() {
|
||||
getOrPost("/get_group_msg_history") {
|
||||
val peerId = fetchOrThrow("group_id")
|
||||
val cnt = fetchOrNull("count")?.toInt() ?: 20
|
||||
val startId = fetchOrNull("message_seq")?.toInt()?.let {
|
||||
if (it == 0) return@let 0L
|
||||
val startId = fetchOrNull("message_id")?.let {
|
||||
val messageId = it.toInt()
|
||||
if (messageId == 0) return@let 0L
|
||||
MessageDB.getInstance()
|
||||
.messageMappingDao()
|
||||
.queryByMsgHashId(it)?.qqMsgId
|
||||
.queryByMsgHashId(messageId)?.qqMsgId
|
||||
} ?: fetchOrNull("message_seq")?.let {
|
||||
val messageSeq = it.toInt()
|
||||
if (messageSeq == 0) return@let 0L
|
||||
MessageDB.getInstance()
|
||||
.messageMappingDao()
|
||||
.queryByMsgSeq(MsgConstant.KCHATTYPEGROUP, peerId, messageSeq)?.qqMsgId
|
||||
} ?: 0L
|
||||
call.respondText(GetHistoryMsg("group", peerId, cnt, startId), ContentType.Application.Json)
|
||||
}
|
||||
@ -173,7 +180,9 @@ fun Routing.messageAction() {
|
||||
SendMessage(
|
||||
chatType = chatType,
|
||||
peerId = peerId,
|
||||
message = if (isJsonObject("message")) listOf(fetchPostJsonObject("message")).jsonArray else fetchPostJsonArray("message"),
|
||||
message = if (isJsonObject("message")) listOf(fetchPostJsonObject("message")).jsonArray else fetchPostJsonArray(
|
||||
"message"
|
||||
),
|
||||
fromId = groupId ?: userId ?: "",
|
||||
retryCnt = retryCnt,
|
||||
recallDuration = recallDuration
|
||||
@ -235,7 +244,9 @@ fun Routing.messageAction() {
|
||||
SendMessage(
|
||||
chatType = MsgConstant.KCHATTYPEGROUP,
|
||||
peerId = groupId,
|
||||
message = if (isJsonObject("message")) listOf(fetchPostJsonObject("message")).jsonArray else fetchPostJsonArray("message"),
|
||||
message = if (isJsonObject("message")) listOf(fetchPostJsonObject("message")).jsonArray else fetchPostJsonArray(
|
||||
"message"
|
||||
),
|
||||
retryCnt = retryCnt,
|
||||
recallDuration = recallDuration
|
||||
)
|
||||
@ -298,7 +309,9 @@ fun Routing.messageAction() {
|
||||
SendMessage(
|
||||
chatType = chatType,
|
||||
peerId = userId,
|
||||
message = if (isJsonObject("message")) listOf(fetchPostJsonObject("message")).jsonArray else fetchPostJsonArray("message"),
|
||||
message = if (isJsonObject("message")) listOf(fetchPostJsonObject("message")).jsonArray else fetchPostJsonArray(
|
||||
"message"
|
||||
),
|
||||
fromId = groupId ?: userId ?: "",
|
||||
retryCnt = retryCnt,
|
||||
recallDuration = recallDuration
|
||||
|
@ -20,7 +20,7 @@ internal data class MessageDetail(
|
||||
@SerialName("time") val time: Int,
|
||||
@SerialName("message_type") val msgType: String,
|
||||
@SerialName("message_id") val msgId: Int,
|
||||
@SerialName("real_id") val realId: Int,
|
||||
@SerialName("message_seq") val msgSeq: Long,
|
||||
@SerialName("sender") val sender: MessageSender,
|
||||
@SerialName("message") val message: List<Map<String, JsonElement>>,
|
||||
@SerialName("group_id") val groupId: Long = 0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user