Commit 50934f9b authored by Him188's avatar Him188

Ensure binary compatibility until 1.1.0

parent 0de76149
...@@ -98,7 +98,7 @@ internal fun MessageChain.toRichTextElems(forGroup: Boolean, withGeneralFlags: B ...@@ -98,7 +98,7 @@ internal fun MessageChain.toRichTextElems(forGroup: Boolean, withGeneralFlags: B
} }
when (it) { when (it) {
is PlainText -> elements.add(ImMsgBody.Elem(text = ImMsgBody.Text(str = it.stringValue))) is PlainText -> elements.add(ImMsgBody.Elem(text = ImMsgBody.Text(str = it.content)))
is CustomMessage -> { is CustomMessage -> {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
elements.add( elements.add(
...@@ -250,7 +250,7 @@ private fun MessageChain.cleanupRubbishMessageElements(): MessageChain { ...@@ -250,7 +250,7 @@ private fun MessageChain.cleanupRubbishMessageElements(): MessageChain {
} }
if (last is VipFace && element is PlainText) { if (last is VipFace && element is PlainText) {
val l = last as VipFace val l = last as VipFace
if (element.length == 4 + (l.count / 10) + l.kind.name.length) { if (element.content.length == 4 + (l.count / 10) + l.kind.name.length) {
last = element last = element
return@forEach return@forEach
} }
......
...@@ -52,7 +52,7 @@ internal fun SingleMessage.estimateLength(upTo: Int): Int { ...@@ -52,7 +52,7 @@ internal fun SingleMessage.estimateLength(upTo: Int): Int {
return when (this) { return when (this) {
is QuoteReply -> 444 + this.source.originalMessage.estimateLength(upTo) // Magic number is QuoteReply -> 444 + this.source.originalMessage.estimateLength(upTo) // Magic number
is Image -> 260 // Magic number is Image -> 260 // Magic number
is PlainText -> stringValue.chineseLength(upTo) is PlainText -> content.chineseLength(upTo)
is At -> display.chineseLength(upTo) is At -> display.chineseLength(upTo)
is AtAll -> display.chineseLength(upTo) is AtAll -> display.chineseLength(upTo)
else -> this.toString().chineseLength(upTo) else -> this.toString().chineseLength(upTo)
......
...@@ -32,9 +32,7 @@ import kotlin.jvm.JvmSynthetic ...@@ -32,9 +32,7 @@ import kotlin.jvm.JvmSynthetic
data class At data class At
@Suppress("DataClassPrivateConstructor") @Suppress("DataClassPrivateConstructor")
private constructor(val target: Long, val display: String) : private constructor(val target: Long, val display: String) :
MessageContent, MessageContent {
CharSequence by display,
Comparable<String> by display {
/** /**
* 构造一个 [At] 实例. 这是唯一的公开的构造方式. * 构造一个 [At] 实例. 这是唯一的公开的构造方式.
...@@ -63,7 +61,7 @@ private constructor(val target: Long, val display: String) : ...@@ -63,7 +61,7 @@ private constructor(val target: Long, val display: String) :
// 自动为消息补充 " " // 自动为消息补充 " "
override fun followedBy(tail: Message): MessageChain { override fun followedBy(tail: Message): MessageChain {
if (tail is PlainText && tail.stringValue.startsWith(' ')) { if (tail is PlainText && tail.content.startsWith(' ')) {
return super.followedBy(tail) return super.followedBy(tail)
} }
return super.followedBy(PlainText(" ")) + tail return super.followedBy(PlainText(" ")) + tail
......
...@@ -27,9 +27,7 @@ private const val displayA = "@全体成员" ...@@ -27,9 +27,7 @@ private const val displayA = "@全体成员"
*/ */
object AtAll : object AtAll :
Message.Key<AtAll>, Message.Key<AtAll>,
MessageContent, MessageContent {
CharSequence by displayA,
Comparable<String> by displayA {
@SinceMirai("0.31.2") @SinceMirai("0.31.2")
const val display = displayA const val display = displayA
...@@ -49,7 +47,7 @@ object AtAll : ...@@ -49,7 +47,7 @@ object AtAll :
// 自动为消息补充 " " // 自动为消息补充 " "
override fun followedBy(tail: Message): MessageChain { override fun followedBy(tail: Message): MessageChain {
if (tail is PlainText && tail.stringValue.startsWith(' ')) { if (tail is PlainText && tail.content.startsWith(' ')) {
return super.followedBy(tail) return super.followedBy(tail)
} }
return super.followedBy(PlainText(" ")) + tail return super.followedBy(PlainText(" ")) + tail
......
...@@ -21,8 +21,7 @@ import kotlin.jvm.JvmName ...@@ -21,8 +21,7 @@ import kotlin.jvm.JvmName
data class Face data class Face
@Suppress("DataClassPrivateConstructor") @Suppress("DataClassPrivateConstructor")
private constructor(val id: Int, private val stringValue: String) : // used in delegation private constructor(val id: Int, private val stringValue: String) : // used in delegation
MessageContent, MessageContent {
CharSequence by stringValue, Comparable<String> by stringValue {
constructor(id: Int) : this(id, "[mirai:face:$id]") constructor(id: Int) : this(id, "[mirai:face:$id]")
override fun toString(): String = stringValue override fun toString(): String = stringValue
......
...@@ -279,7 +279,7 @@ interface Message { // must be interface. Don't consider any changes. ...@@ -279,7 +279,7 @@ interface Message { // must be interface. Don't consider any changes.
@SinceMirai("0.39.3") @SinceMirai("0.39.3")
fun Message.isContentEmpty(): Boolean = when (this) { fun Message.isContentEmpty(): Boolean = when (this) {
is MessageMetadata -> true is MessageMetadata -> true
is PlainText -> this.stringValue.isEmpty() is PlainText -> this.content.isEmpty()
is MessageChain -> this.all { it.isContentEmpty() } is MessageChain -> this.all { it.isContentEmpty() }
else -> false else -> false
} }
...@@ -339,6 +339,25 @@ interface SingleMessage : Message { ...@@ -339,6 +339,25 @@ interface SingleMessage : Message {
DeprecationLevel.ERROR DeprecationLevel.ERROR
) )
/* final */ override infix fun eq(other: String): Boolean = this.contentToString() == other /* final */ override infix fun eq(other: String): Boolean = this.contentToString() == other
@PlannedRemoval("1.1.0")
@JvmSynthetic
@SinceMirai("1.0.0")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
fun length(): Int = this.toString().length
@PlannedRemoval("1.1.0")
@JvmSynthetic
@SinceMirai("1.0.0")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
fun charAt(index: Int): Char = this.toString()[index]
@PlannedRemoval("1.1.0")
@JvmSynthetic
@SinceMirai("1.0.0")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
fun subSequence(start: Int, end: Int): CharSequence = this.toString().subSequence(start, end)
} }
/** /**
......
...@@ -32,20 +32,6 @@ internal class TestConstrainSingleMessage : ConstrainSingle<TestConstrainSingleM ...@@ -32,20 +32,6 @@ internal class TestConstrainSingleMessage : ConstrainSingle<TestConstrainSingleM
override val key: Message.Key<TestConstrainSingleMessage> override val key: Message.Key<TestConstrainSingleMessage>
get() = Key get() = Key
override val length: Int
get() = TODO("Not yet implemented")
override fun get(index: Int): Char {
TODO("Not yet implemented")
}
override fun subSequence(startIndex: Int, endIndex: Int): CharSequence {
TODO("Not yet implemented")
}
override fun compareTo(other: String): Int {
TODO("Not yet implemented")
}
} }
@OptIn(MiraiExperimentalAPI::class) @OptIn(MiraiExperimentalAPI::class)
......
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