Ensure binary compatibility

This commit is contained in:
Him188 2020-04-29 15:49:01 +08:00
parent 50934f9b7d
commit 2501cbb59a
2 changed files with 24 additions and 28 deletions

View File

@ -236,6 +236,7 @@ private fun MessageChain.cleanupRubbishMessageElements(): MessageChain {
var last: SingleMessage? = null
return buildMessageChain(initialSize = this.count()) {
this@cleanupRubbishMessageElements.forEach { element ->
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
if (last is LongMessage && element is PlainText) {
if (element == UNSUPPORTED_MERGED_MESSAGE_PLAIN) {
last = element
@ -347,16 +348,18 @@ internal fun List<ImMsgBody.Elem>.joinToMessageChain(groupIdOrZero: Long, bot: B
val resId = this.firstIsInstanceOrNull<ImMsgBody.GeneralFlags>()?.longTextResid
if (resId != null) {
list.add(LongMessage(content, resId))
// TODO: 2020/4/29 解析长消息
list.add(ServiceMessage(35, content)) // resId
} else {
list.add(ForwardMessageInternal(content))
// TODO: 2020/4/29 解析合并转发
list.add(ServiceMessage(35, content))
}
}
// 104 新群员入群的消息
else -> {
if (element.richMsg.serviceId == 60 || content.startsWith("<?")) {
@Suppress("DEPRECATION_ERROR")
@Suppress("DEPRECATION_ERROR") // bin comp
list.add(XmlMessage(element.richMsg.serviceId, content))
} else list.add(ServiceMessage(element.richMsg.serviceId, content))
}

View File

@ -13,7 +13,6 @@
package net.mamoe.mirai.message.data
import net.mamoe.mirai.contact.Contact
import net.mamoe.mirai.utils.MiraiExperimentalAPI
import net.mamoe.mirai.utils.PlannedRemoval
import net.mamoe.mirai.utils.SinceMirai
@ -105,10 +104,8 @@ data class LightApp(override val content: String) : RichMessage {
/**
* 服务消息, [XmlMessage].
*/
@MiraiExperimentalAPI
@SinceMirai("0.37.3")
open class ServiceMessage(@MiraiExperimentalAPI val serviceId: Int, final override val content: String) : RichMessage {
@Suppress("DEPRECATION")
open class ServiceMessage(val serviceId: Int, final override val content: String) : RichMessage {
companion object Key : Message.Key<ServiceMessage> {
override val typeName: String get() = "ServiceMessage"
}
@ -133,6 +130,8 @@ open class ServiceMessage(@MiraiExperimentalAPI val serviceId: Int, final overri
/**
* Json 消息.
*
* 由于 [serviceId] 不准确, 请使用 [ServiceMessage] 并手动指定 `serviceId`
*
* @see LightApp 一些 json 消息实际上是 [LightApp]
*/
@PlannedRemoval("1.0.0")
@ -156,6 +155,8 @@ constructor(content: String) : ServiceMessage(1, content) {
/**
* XML 消息, 如分享, 卡片等.
*
* 由于 [serviceId] 不准确, 请使用 [ServiceMessage] 并手动指定 `serviceId`
*
* @param serviceId 目前未知, 一般为 60
*
* @see buildXmlMessage 使用 DSL 构造一个 XML 消息
@ -179,27 +180,6 @@ constructor(serviceId: Int = 60, content: String) : ServiceMessage(serviceId, co
}
}
/**
* 长消息.
*
* 不需要手动区分长消息和普通消息, [Contact.sendMessage] 时会自动判断.
*/
@SinceMirai("0.31.0")
@MiraiExperimentalAPI
class LongMessage internal constructor(content: String, val resId: String) : ServiceMessage(35, content) {
companion object Key : Message.Key<LongMessage> {
override val typeName: String get() = "LongMessage"
}
}
/**
* 合并转发消息
* @suppress API 非常不稳定
*/
@OptIn(MiraiExperimentalAPI::class)
@SinceMirai("0.39.0")
internal class ForwardMessageInternal(content: String) : ServiceMessage(35, content)
/*
commonElem=CommonElem#750141174 {
businessType=0x00000001(1)
@ -293,3 +273,16 @@ class XmlMessageBuilder(
@Deprecated("specify serviceId explicitly", ReplaceWith("buildXmlMessage(60, block)"))
inline fun buildXmlMessage(block: @XmlMessageDsl XmlMessageBuilder.() -> Unit): ServiceMessage =
buildXmlMessage(60, block)
@SinceMirai("0.31.0")
@MiraiExperimentalAPI
internal class LongMessage internal constructor(content: String, val resId: String) : ServiceMessage(35, content) {
companion object Key : Message.Key<LongMessage> {
override val typeName: String get() = "LongMessage"
}
}
@OptIn(MiraiExperimentalAPI::class)
@SinceMirai("0.39.0")
internal class ForwardMessageInternal(content: String) : ServiceMessage(35, content)