Skip to content

Commit

Permalink
Merge pull request #15 from simple-robot/dev/fix-14
Browse files Browse the repository at this point in the history
修复 TelegramMessageEntity$Simple 的多态序列化注册错误
  • Loading branch information
ForteScarlet authored Jul 18, 2024
2 parents ceabed8 + f25fc9e commit 7661553
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/P.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ object P {
override val description: String get() = DESCRIPTION
override val homepage: String get() = HOMEPAGE

const val VERSION = "0.0.5"
const val NEXT_VERSION = "0.0.6"
const val VERSION = "0.0.6"
const val NEXT_VERSION = "0.0.7"

override val snapshotVersion = "$NEXT_VERSION-SNAPSHOT"
override val version = if (isSnapshot()) snapshotVersion else VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
import com.google.devtools.ksp.processing.SymbolProcessorProvider
import com.google.devtools.ksp.symbol.KSAnnotated
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.Modifier
import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.ksp.toClassName
Expand Down Expand Up @@ -81,6 +82,8 @@ private class IncludeMessageElementsProcessor(val environment: SymbolProcessorEn
.filterIsInstance<KSClassDeclaration>()
// 是一个可序列化的具体的类
.filter { !it.isAbstract() }
// isAbstract 无法判断 sealed
.filter { Modifier.SEALED !in it.modifiers }
// 是 BaseMessageElement 的子类
.filter { baseDeclarationType.isAssignableFrom(it.asStarProjectedType()) }
.onEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ public sealed class TelegramMessageEntity : TelegramMessageElement, PlainText {
@SerialName("telegram.m.message_entity.simple")
public class Simple internal constructor(
override val text: String,
override val type: String,
private val typeValue: String,
override val sourceEntity: MessageEntity?
) : TelegramMessageEntity()
) : TelegramMessageEntity() {
override val type: String
get() = typeValue
}

/**
* An implementation with type [MessageEntityType.TEXT_LINK]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ internal fun StdlibMessage.toMessages(): Messages {
else -> {
TelegramMessageEntity.Simple(
text = text.substring(entity),
type = entity.type,
typeValue = entity.type,
entity
)
}
Expand Down

0 comments on commit 7661553

Please sign in to comment.