mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-07 05:49:14 +08:00
Fix messageSourceKind for OfflineMessageSource in QuoteReply
This commit is contained in:
parent
fec93d3cb8
commit
b65afd8533
@ -336,14 +336,18 @@ internal fun List<MsgComm.Msg>.toMessageChain(
|
||||
} else {
|
||||
+OfflineMessageSourceImplData(bot, this@toMessageChain, botId)
|
||||
}
|
||||
elements.joinToMessageChain(groupIdOrZero, botId, this)
|
||||
elements.joinToMessageChain(groupIdOrZero, messageSourceKind, botId, this)
|
||||
addAll(ptts)
|
||||
}.cleanupRubbishMessageElements()
|
||||
}
|
||||
|
||||
// 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
|
||||
if (elements.isEmpty())
|
||||
error("elements for SourceMsg is empty")
|
||||
@ -351,9 +355,10 @@ internal fun ImMsgBody.SourceMsg.toMessageChain(botId: Long, groupIdOrZero: Long
|
||||
+OfflineMessageSourceImplData(
|
||||
delegate = this@toMessageChain,
|
||||
botId = botId,
|
||||
messageSourceKind = messageSourceKind,
|
||||
groupIdOrZero = groupIdOrZero
|
||||
)
|
||||
elements.joinToMessageChain(groupIdOrZero, botId, this)
|
||||
elements.joinToMessageChain(groupIdOrZero, messageSourceKind, botId, this)
|
||||
}.cleanupRubbishMessageElements()
|
||||
}
|
||||
|
||||
@ -416,13 +421,27 @@ internal inline fun <reified R> Iterable<*>.firstIsInstanceOrNull(): R? {
|
||||
|
||||
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())
|
||||
var marketFace: MarketFaceImpl? = null
|
||||
this.forEach { element ->
|
||||
when {
|
||||
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.customFace != null -> list.add(OnlineGroupImageImpl(element.customFace))
|
||||
|
@ -7,7 +7,6 @@
|
||||
* 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
|
||||
|
||||
@ -108,14 +107,15 @@ internal fun OfflineMessageSourceImplData(
|
||||
delegate: List<MsgComm.Msg>,
|
||||
botId: Long,
|
||||
): OfflineMessageSourceImplData {
|
||||
val head = delegate.first().msgHead
|
||||
val kind = when {
|
||||
delegate.first().msgHead.groupInfo != null -> {
|
||||
head.groupInfo != null -> {
|
||||
MessageSourceKind.GROUP
|
||||
}
|
||||
delegate.first().msgHead.c2cTmpMsgHead != null -> {
|
||||
head.c2cTmpMsgHead != null -> {
|
||||
MessageSourceKind.TEMP
|
||||
}
|
||||
bot?.getStranger(delegate.first().msgHead.fromUin) != null -> {
|
||||
bot?.getStranger(head.fromUin) != null -> {
|
||||
MessageSourceKind.STRANGER
|
||||
}
|
||||
else -> {
|
||||
@ -124,13 +124,13 @@ internal fun OfflineMessageSourceImplData(
|
||||
}
|
||||
return OfflineMessageSourceImplData(
|
||||
kind = kind,
|
||||
time = delegate.first().msgHead.msgTime,
|
||||
fromId = delegate.first().msgHead.fromUin,
|
||||
targetId = delegate.first().msgHead.groupInfo?.groupCode ?: delegate.first().msgHead.toUin,
|
||||
time = head.msgTime,
|
||||
fromId = head.fromUin,
|
||||
targetId = head.groupInfo?.groupCode ?: head.toUin,
|
||||
originalMessage = delegate.toMessageChain(
|
||||
null,
|
||||
botId,
|
||||
groupIdOrZero = delegate.first().msgHead.groupInfo?.groupCode ?: 0,
|
||||
groupIdOrZero = head.groupInfo?.groupCode ?: 0,
|
||||
onlineSource = false,
|
||||
messageSourceKind = kind
|
||||
),
|
||||
@ -165,15 +165,16 @@ internal fun OfflineMessageSourceImplData(
|
||||
internal fun OfflineMessageSourceImplData(
|
||||
delegate: ImMsgBody.SourceMsg,
|
||||
botId: Long,
|
||||
messageSourceKind: MessageSourceKind,
|
||||
groupIdOrZero: Long,
|
||||
): OfflineMessageSourceImplData {
|
||||
return OfflineMessageSourceImplData(
|
||||
kind = if (delegate.srcMsg == null) MessageSourceKind.GROUP else MessageSourceKind.FRIEND,
|
||||
kind = messageSourceKind,
|
||||
ids = delegate.origSeqs,
|
||||
internalIds = delegate.pbReserve.loadAs(SourceMsg.ResvAttr.serializer())
|
||||
.origUids?.mapToIntArray { it.toInt() } ?: intArrayOf(),
|
||||
time = delegate.time,
|
||||
originalMessageLazy = lazy { delegate.toMessageChain(botId, groupIdOrZero) },
|
||||
originalMessageLazy = lazy { delegate.toMessageChain(botId, messageSourceKind, groupIdOrZero) },
|
||||
fromId = delegate.senderUin,
|
||||
targetId = when {
|
||||
groupIdOrZero != 0L -> groupIdOrZero
|
||||
|
Loading…
Reference in New Issue
Block a user