Forráskód Böngészése

Deprecate `XmlMessage` and `JsonMessage` in favour of `ServiceMessage`

Him188 5 éve
szülő
commit
e3084c5f7d

+ 3 - 1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/convension.kt

@@ -338,7 +338,8 @@ internal fun List<ImMsgBody.Elem>.joinToMessageChain(groupIdOrZero: Long, bot: B
                     /**
                      * [JsonMessage]
                      */
-                    1 -> list.add(JsonMessage(content))
+                    1 -> @Suppress("DEPRECATION_ERROR")
+                    list.add(JsonMessage(content))
                     /**
                      * [LongMessage], [ForwardMessage]
                      */
@@ -355,6 +356,7 @@ internal fun List<ImMsgBody.Elem>.joinToMessageChain(groupIdOrZero: Long, bot: B
                     // 104 新群员入群的消息
                     else -> {
                         if (element.richMsg.serviceId == 60 || content.startsWith("<?")) {
+                            @Suppress("DEPRECATION_ERROR")
                             list.add(XmlMessage(element.richMsg.serviceId, content))
                         } else list.add(ServiceMessage(element.richMsg.serviceId, content))
                     }

+ 40 - 4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/RichMessage.kt

@@ -15,6 +15,7 @@ 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
 import kotlin.annotation.AnnotationTarget.*
 import kotlin.jvm.JvmMultifileClass
@@ -40,7 +41,12 @@ interface RichMessage : MessageContent {
 
         @MiraiExperimentalAPI
         @SinceMirai("0.30.0")
-        fun share(url: String, title: String? = null, content: String? = null, coverUrl: String? = null): XmlMessage =
+        fun share(
+            url: String,
+            title: String? = null,
+            content: String? = null,
+            coverUrl: String? = null
+        ): ServiceMessage =
             buildXmlMessage(60) {
                 templateId = 12345
                 serviceId = 1
@@ -61,6 +67,20 @@ interface RichMessage : MessageContent {
                 }
             }
 
+        @PlannedRemoval("1.0.0")
+        @JvmName("share")
+        @Deprecated(
+            "for binary compatibility", level = DeprecationLevel.HIDDEN
+        )
+        @Suppress("DEPRECATION_ERROR")
+        @MiraiExperimentalAPI
+        fun shareDeprecated(
+            url: String,
+            title: String? = null,
+            content: String? = null,
+            coverUrl: String? = null
+        ): XmlMessage = share(url, title, content, coverUrl) as XmlMessage
+
         override val typeName: String
             get() = "RichMessage"
     }
@@ -120,8 +140,17 @@ open class ServiceMessage(@MiraiExperimentalAPI val serviceId: Int, final overri
  *
  * @see LightApp 一些 json 消息实际上是 [LightApp]
  */
+@PlannedRemoval("1.0.0")
+@Deprecated("use ServiceMessage with serviceId 1",
+    level = DeprecationLevel.ERROR,
+    replaceWith = ReplaceWith("ServiceMessage"))
+@Suppress("DEPRECATION_ERROR")
 @MiraiExperimentalAPI
-class JsonMessage(content: String) : ServiceMessage(1, content) {
+class JsonMessage
+@Deprecated("use ServiceMessage with serviceId 1",
+    level = DeprecationLevel.ERROR,
+    replaceWith = ReplaceWith("ServiceMessage(1, content)"))
+constructor(content: String) : ServiceMessage(1, content) {
     @Suppress("DEPRECATION")
     companion object Key : Message.Key<JsonMessage> {
         override val typeName: String get() = "JsonMessage"
@@ -136,7 +165,12 @@ class JsonMessage(content: String) : ServiceMessage(1, content) {
  *
  * @see buildXmlMessage 使用 DSL 构造一个 XML 消息
  */
+@PlannedRemoval("1.0.0")
+@Deprecated("use ServiceMessage with serviceId 1",
+    level = DeprecationLevel.ERROR,
+    replaceWith = ReplaceWith("ServiceMessage"))
 @MiraiExperimentalAPI
+@Suppress("DEPRECATION_ERROR")
 @SinceMirai("0.27.0")
 class XmlMessage @MiraiExperimentalAPI("Maybe replaced with an enum")
 constructor(serviceId: Int = 60, content: String) : ServiceMessage(serviceId, content) {
@@ -182,10 +216,11 @@ commonElem=CommonElem#750141174 {
 /**
  * 构造一条 XML 消息
  */
+@Suppress("DEPRECATION_ERROR")
 @JvmSynthetic
 @SinceMirai("0.27.0")
 @MiraiExperimentalAPI
-inline fun buildXmlMessage(serviceId: Int, block: @XmlMessageDsl XmlMessageBuilder.() -> Unit): XmlMessage =
+inline fun buildXmlMessage(serviceId: Int, block: @XmlMessageDsl XmlMessageBuilder.() -> Unit): ServiceMessage =
     XmlMessage(serviceId, XmlMessageBuilder().apply(block).text)
 
 @Target(CLASS, FUNCTION, TYPE)
@@ -261,4 +296,5 @@ class XmlMessageBuilder(
 @SinceMirai("0.27.0")
 @MiraiExperimentalAPI
 @Deprecated("specify serviceId explicitly", ReplaceWith("buildXmlMessage(60, block)"))
-inline fun buildXmlMessage(block: @XmlMessageDsl XmlMessageBuilder.() -> Unit): XmlMessage = buildXmlMessage(60, block)
+inline fun buildXmlMessage(block: @XmlMessageDsl XmlMessageBuilder.() -> Unit): ServiceMessage =
+    buildXmlMessage(60, block)

+ 2 - 1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/impl.kt

@@ -198,7 +198,7 @@ internal inline fun <T> List<T>.indexOfFirst(offset: Int, predicate: (T) -> Bool
 
 @OptIn(MiraiExperimentalAPI::class)
 @JvmSynthetic
-@Suppress("UNCHECKED_CAST")
+@Suppress("UNCHECKED_CAST", "DEPRECATION_ERROR")
 internal fun <M : Message> MessageChain.firstOrNullImpl(key: Message.Key<M>): M? = when (key) {
     At -> firstIsInstanceOrNull<At>()
     AtAll -> firstIsInstanceOrNull<AtAll>()
@@ -221,6 +221,7 @@ internal fun <M : Message> MessageChain.firstOrNullImpl(key: Message.Key<M>): M?
     OnlineMessageSource.Incoming.FromFriend -> firstIsInstanceOrNull<OnlineMessageSource.Incoming.FromFriend>()
     OnlineMessageSource -> firstIsInstanceOrNull<OnlineMessageSource>()
     XmlMessage -> firstIsInstanceOrNull<XmlMessage>()
+    LongMessage -> firstIsInstanceOrNull()
     JsonMessage -> firstIsInstanceOrNull<JsonMessage>()
     RichMessage -> firstIsInstanceOrNull<RichMessage>()
     LightApp -> firstIsInstanceOrNull<LightApp>()