Add a stable factory-method for AnnouncementImage

This commit is contained in:
Him188 2021-07-05 15:32:03 +08:00
parent b239c57679
commit 5c89645056
2 changed files with 10 additions and 3 deletions

View File

@ -11,7 +11,6 @@ package net.mamoe.mirai.contact.announcement
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import net.mamoe.mirai.utils.MiraiInternalApi
/**
@ -23,7 +22,7 @@ import net.mamoe.mirai.utils.MiraiInternalApi
*/
@SerialName(AnnouncementImage.SERIAL_NAME)
@Serializable
public class AnnouncementImage @MiraiInternalApi public constructor(
public class AnnouncementImage private constructor(
public val id: String,
public val height: String,
public val width: String,
@ -32,6 +31,14 @@ public class AnnouncementImage @MiraiInternalApi public constructor(
public companion object {
public const val SERIAL_NAME: String = "AnnouncementImage"
/**
* 创建 [AnnouncementImage] 实例.
*/
@JvmStatic
public fun create(id: String, height: String, width: String): AnnouncementImage {
return AnnouncementImage(id, height, width)
}
}
override fun toString(): String {

View File

@ -56,7 +56,7 @@ internal class GroupAnnouncementImage @MiraiInternalApi constructor(
@SerialName("w") val width: String,
@SerialName("id") val id: String
) : JsonStruct {
fun toPublic(): AnnouncementImage = AnnouncementImage(id, height, width)
fun toPublic(): AnnouncementImage = AnnouncementImage.create(id, height, width)
}
@Serializable