Commit 2501cbb5 authored by Him188's avatar Him188

Ensure binary compatibility

parent 50934f9b
...@@ -236,6 +236,7 @@ private fun MessageChain.cleanupRubbishMessageElements(): MessageChain { ...@@ -236,6 +236,7 @@ private fun MessageChain.cleanupRubbishMessageElements(): MessageChain {
var last: SingleMessage? = null var last: SingleMessage? = null
return buildMessageChain(initialSize = this.count()) { return buildMessageChain(initialSize = this.count()) {
this@cleanupRubbishMessageElements.forEach { element -> this@cleanupRubbishMessageElements.forEach { element ->
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
if (last is LongMessage && element is PlainText) { if (last is LongMessage && element is PlainText) {
if (element == UNSUPPORTED_MERGED_MESSAGE_PLAIN) { if (element == UNSUPPORTED_MERGED_MESSAGE_PLAIN) {
last = element last = element
...@@ -347,16 +348,18 @@ internal fun List<ImMsgBody.Elem>.joinToMessageChain(groupIdOrZero: Long, bot: B ...@@ -347,16 +348,18 @@ internal fun List<ImMsgBody.Elem>.joinToMessageChain(groupIdOrZero: Long, bot: B
val resId = this.firstIsInstanceOrNull<ImMsgBody.GeneralFlags>()?.longTextResid val resId = this.firstIsInstanceOrNull<ImMsgBody.GeneralFlags>()?.longTextResid
if (resId != null) { if (resId != null) {
list.add(LongMessage(content, resId)) // TODO: 2020/4/29 解析长消息
list.add(ServiceMessage(35, content)) // resId
} else { } else {
list.add(ForwardMessageInternal(content)) // TODO: 2020/4/29 解析合并转发
list.add(ServiceMessage(35, content))
} }
} }
// 104 新群员入群的消息 // 104 新群员入群的消息
else -> { else -> {
if (element.richMsg.serviceId == 60 || content.startsWith("<?")) { if (element.richMsg.serviceId == 60 || content.startsWith("<?")) {
@Suppress("DEPRECATION_ERROR") @Suppress("DEPRECATION_ERROR") // bin comp
list.add(XmlMessage(element.richMsg.serviceId, content)) list.add(XmlMessage(element.richMsg.serviceId, content))
} else list.add(ServiceMessage(element.richMsg.serviceId, content)) } else list.add(ServiceMessage(element.richMsg.serviceId, content))
} }
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
package net.mamoe.mirai.message.data package net.mamoe.mirai.message.data
import net.mamoe.mirai.contact.Contact
import net.mamoe.mirai.utils.MiraiExperimentalAPI import net.mamoe.mirai.utils.MiraiExperimentalAPI
import net.mamoe.mirai.utils.PlannedRemoval import net.mamoe.mirai.utils.PlannedRemoval
import net.mamoe.mirai.utils.SinceMirai import net.mamoe.mirai.utils.SinceMirai
...@@ -105,10 +104,8 @@ data class LightApp(override val content: String) : RichMessage { ...@@ -105,10 +104,8 @@ data class LightApp(override val content: String) : RichMessage {
/** /**
* 服务消息, 如 [XmlMessage]. * 服务消息, 如 [XmlMessage].
*/ */
@MiraiExperimentalAPI
@SinceMirai("0.37.3") @SinceMirai("0.37.3")
open class ServiceMessage(@MiraiExperimentalAPI val serviceId: Int, final override val content: String) : RichMessage { open class ServiceMessage(val serviceId: Int, final override val content: String) : RichMessage {
@Suppress("DEPRECATION")
companion object Key : Message.Key<ServiceMessage> { companion object Key : Message.Key<ServiceMessage> {
override val typeName: String get() = "ServiceMessage" override val typeName: String get() = "ServiceMessage"
} }
...@@ -133,6 +130,8 @@ open class ServiceMessage(@MiraiExperimentalAPI val serviceId: Int, final overri ...@@ -133,6 +130,8 @@ open class ServiceMessage(@MiraiExperimentalAPI val serviceId: Int, final overri
/** /**
* Json 消息. * Json 消息.
* *
* 由于 [serviceId] 不准确, 请使用 [ServiceMessage] 并手动指定 `serviceId`
*
* @see LightApp 一些 json 消息实际上是 [LightApp] * @see LightApp 一些 json 消息实际上是 [LightApp]
*/ */
@PlannedRemoval("1.0.0") @PlannedRemoval("1.0.0")
...@@ -156,6 +155,8 @@ constructor(content: String) : ServiceMessage(1, content) { ...@@ -156,6 +155,8 @@ constructor(content: String) : ServiceMessage(1, content) {
/** /**
* XML 消息, 如分享, 卡片等. * XML 消息, 如分享, 卡片等.
* *
* 由于 [serviceId] 不准确, 请使用 [ServiceMessage] 并手动指定 `serviceId`
*
* @param serviceId 目前未知, 一般为 60 * @param serviceId 目前未知, 一般为 60
* *
* @see buildXmlMessage 使用 DSL 构造一个 XML 消息 * @see buildXmlMessage 使用 DSL 构造一个 XML 消息
...@@ -179,27 +180,6 @@ constructor(serviceId: Int = 60, content: String) : ServiceMessage(serviceId, co ...@@ -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 { commonElem=CommonElem#750141174 {
businessType=0x00000001(1) businessType=0x00000001(1)
...@@ -293,3 +273,16 @@ class XmlMessageBuilder( ...@@ -293,3 +273,16 @@ class XmlMessageBuilder(
@Deprecated("specify serviceId explicitly", ReplaceWith("buildXmlMessage(60, block)")) @Deprecated("specify serviceId explicitly", ReplaceWith("buildXmlMessage(60, block)"))
inline fun buildXmlMessage(block: @XmlMessageDsl XmlMessageBuilder.() -> Unit): ServiceMessage = inline fun buildXmlMessage(block: @XmlMessageDsl XmlMessageBuilder.() -> Unit): ServiceMessage =
buildXmlMessage(60, block) 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)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment