Fix messageSourceKind for OfflineMessageSource in QuoteReply

This commit is contained in:
Him188 2021-01-10 03:12:30 +08:00
parent fec93d3cb8
commit b65afd8533
2 changed files with 35 additions and 15 deletions

View File

@ -336,14 +336,18 @@ internal fun List<MsgComm.Msg>.toMessageChain(
} else { } else {
+OfflineMessageSourceImplData(bot, this@toMessageChain, botId) +OfflineMessageSourceImplData(bot, this@toMessageChain, botId)
} }
elements.joinToMessageChain(groupIdOrZero, botId, this) elements.joinToMessageChain(groupIdOrZero, messageSourceKind, botId, this)
addAll(ptts) addAll(ptts)
}.cleanupRubbishMessageElements() }.cleanupRubbishMessageElements()
} }
// These two functions have difference method signature, don't combine. // These two functions have difference method signature, don't combine.
internal fun ImMsgBody.SourceMsg.toMessageChain(botId: Long, groupIdOrZero: Long): MessageChain { internal fun ImMsgBody.SourceMsg.toMessageChain(
botId: Long,
messageSourceKind: MessageSourceKind,
groupIdOrZero: Long
): MessageChain {
val elements = this.elems val elements = this.elems
if (elements.isEmpty()) if (elements.isEmpty())
error("elements for SourceMsg is empty") error("elements for SourceMsg is empty")
@ -351,9 +355,10 @@ internal fun ImMsgBody.SourceMsg.toMessageChain(botId: Long, groupIdOrZero: Long
+OfflineMessageSourceImplData( +OfflineMessageSourceImplData(
delegate = this@toMessageChain, delegate = this@toMessageChain,
botId = botId, botId = botId,
messageSourceKind = messageSourceKind,
groupIdOrZero = groupIdOrZero groupIdOrZero = groupIdOrZero
) )
elements.joinToMessageChain(groupIdOrZero, botId, this) elements.joinToMessageChain(groupIdOrZero, messageSourceKind, botId, this)
}.cleanupRubbishMessageElements() }.cleanupRubbishMessageElements()
} }
@ -416,13 +421,27 @@ internal inline fun <reified R> Iterable<*>.firstIsInstanceOrNull(): R? {
internal val MIRAI_CUSTOM_ELEM_TYPE = "mirai".hashCode() // 103904510 internal val MIRAI_CUSTOM_ELEM_TYPE = "mirai".hashCode() // 103904510
internal fun List<ImMsgBody.Elem>.joinToMessageChain(groupIdOrZero: Long, botId: Long, list: MessageChainBuilder) { internal fun List<ImMsgBody.Elem>.joinToMessageChain(
groupIdOrZero: Long,
messageSourceKind: MessageSourceKind,
botId: Long,
list: MessageChainBuilder
) {
// (this._miraiContentToString().soutv()) // (this._miraiContentToString().soutv())
var marketFace: MarketFaceImpl? = null var marketFace: MarketFaceImpl? = null
this.forEach { element -> this.forEach { element ->
when { when {
element.srcMsg != null -> { element.srcMsg != null -> {
list.add(QuoteReply(OfflineMessageSourceImplData(element.srcMsg, botId, groupIdOrZero))) list.add(
QuoteReply(
OfflineMessageSourceImplData(
element.srcMsg,
botId,
messageSourceKind,
groupIdOrZero
)
)
)
} }
element.notOnlineImage != null -> list.add(OnlineFriendImageImpl(element.notOnlineImage)) element.notOnlineImage != null -> list.add(OnlineFriendImageImpl(element.notOnlineImage))
element.customFace != null -> list.add(OnlineGroupImageImpl(element.customFace)) element.customFace != null -> list.add(OnlineGroupImageImpl(element.customFace))

View File

@ -7,7 +7,6 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_OVERRIDE", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
package net.mamoe.mirai.internal.message package net.mamoe.mirai.internal.message
@ -108,14 +107,15 @@ internal fun OfflineMessageSourceImplData(
delegate: List<MsgComm.Msg>, delegate: List<MsgComm.Msg>,
botId: Long, botId: Long,
): OfflineMessageSourceImplData { ): OfflineMessageSourceImplData {
val head = delegate.first().msgHead
val kind = when { val kind = when {
delegate.first().msgHead.groupInfo != null -> { head.groupInfo != null -> {
MessageSourceKind.GROUP MessageSourceKind.GROUP
} }
delegate.first().msgHead.c2cTmpMsgHead != null -> { head.c2cTmpMsgHead != null -> {
MessageSourceKind.TEMP MessageSourceKind.TEMP
} }
bot?.getStranger(delegate.first().msgHead.fromUin) != null -> { bot?.getStranger(head.fromUin) != null -> {
MessageSourceKind.STRANGER MessageSourceKind.STRANGER
} }
else -> { else -> {
@ -124,13 +124,13 @@ internal fun OfflineMessageSourceImplData(
} }
return OfflineMessageSourceImplData( return OfflineMessageSourceImplData(
kind = kind, kind = kind,
time = delegate.first().msgHead.msgTime, time = head.msgTime,
fromId = delegate.first().msgHead.fromUin, fromId = head.fromUin,
targetId = delegate.first().msgHead.groupInfo?.groupCode ?: delegate.first().msgHead.toUin, targetId = head.groupInfo?.groupCode ?: head.toUin,
originalMessage = delegate.toMessageChain( originalMessage = delegate.toMessageChain(
null, null,
botId, botId,
groupIdOrZero = delegate.first().msgHead.groupInfo?.groupCode ?: 0, groupIdOrZero = head.groupInfo?.groupCode ?: 0,
onlineSource = false, onlineSource = false,
messageSourceKind = kind messageSourceKind = kind
), ),
@ -165,15 +165,16 @@ internal fun OfflineMessageSourceImplData(
internal fun OfflineMessageSourceImplData( internal fun OfflineMessageSourceImplData(
delegate: ImMsgBody.SourceMsg, delegate: ImMsgBody.SourceMsg,
botId: Long, botId: Long,
messageSourceKind: MessageSourceKind,
groupIdOrZero: Long, groupIdOrZero: Long,
): OfflineMessageSourceImplData { ): OfflineMessageSourceImplData {
return OfflineMessageSourceImplData( return OfflineMessageSourceImplData(
kind = if (delegate.srcMsg == null) MessageSourceKind.GROUP else MessageSourceKind.FRIEND, kind = messageSourceKind,
ids = delegate.origSeqs, ids = delegate.origSeqs,
internalIds = delegate.pbReserve.loadAs(SourceMsg.ResvAttr.serializer()) internalIds = delegate.pbReserve.loadAs(SourceMsg.ResvAttr.serializer())
.origUids?.mapToIntArray { it.toInt() } ?: intArrayOf(), .origUids?.mapToIntArray { it.toInt() } ?: intArrayOf(),
time = delegate.time, time = delegate.time,
originalMessageLazy = lazy { delegate.toMessageChain(botId, groupIdOrZero) }, originalMessageLazy = lazy { delegate.toMessageChain(botId, messageSourceKind, groupIdOrZero) },
fromId = delegate.senderUin, fromId = delegate.senderUin,
targetId = when { targetId = when {
groupIdOrZero != 0L -> groupIdOrZero groupIdOrZero != 0L -> groupIdOrZero