From 71e9de360809907c33df70b5da5033946325c209 Mon Sep 17 00:00:00 2001 From: cssxsh Date: Thu, 13 Apr 2023 18:57:04 +0800 Subject: [PATCH] =?UTF-8?q?[core]=20=E6=94=AF=E6=8C=81=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=BE=A4=E5=85=AC=E5=91=8A=E5=9B=BE=E7=89=87=20URL=20(#2619)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: announcement protocol * add: api dump --- .../android/api/android.api | 1 + .../compatibility-validation/jvm/api/jvm.api | 1 + .../contact/announcement/AnnouncementImage.kt | 7 +++- .../contact/announcement/AnnouncementsImpl.kt | 10 ++--- .../contact/announcement/GroupAnnouncement.kt | 5 ++- .../contact/announcement/AnnouncementsImpl.kt | 37 ------------------- .../contact/announcement/AnnouncementsImpl.kt | 18 --------- 7 files changed, 14 insertions(+), 65 deletions(-) delete mode 100644 mirai-core/src/jvmBaseMain/kotlin/contact/announcement/AnnouncementsImpl.kt delete mode 100644 mirai-core/src/nativeMain/kotlin/contact/announcement/AnnouncementsImpl.kt diff --git a/mirai-core-api/compatibility-validation/android/api/android.api b/mirai-core-api/compatibility-validation/android/api/android.api index 3e2d2df89..eec8413e7 100644 --- a/mirai-core-api/compatibility-validation/android/api/android.api +++ b/mirai-core-api/compatibility-validation/android/api/android.api @@ -803,6 +803,7 @@ public final class net/mamoe/mirai/contact/announcement/AnnouncementImage { public fun equals (Ljava/lang/Object;)Z public final fun getHeight ()I public final fun getId ()Ljava/lang/String; + public final fun getUrl ()Ljava/lang/String; public final fun getWidth ()I public fun hashCode ()I public fun toString ()Ljava/lang/String; diff --git a/mirai-core-api/compatibility-validation/jvm/api/jvm.api b/mirai-core-api/compatibility-validation/jvm/api/jvm.api index 9edc7b3cd..ebd6187cc 100644 --- a/mirai-core-api/compatibility-validation/jvm/api/jvm.api +++ b/mirai-core-api/compatibility-validation/jvm/api/jvm.api @@ -803,6 +803,7 @@ public final class net/mamoe/mirai/contact/announcement/AnnouncementImage { public fun equals (Ljava/lang/Object;)Z public final fun getHeight ()I public final fun getId ()Ljava/lang/String; + public final fun getUrl ()Ljava/lang/String; public final fun getWidth ()I public fun hashCode ()I public fun toString ()Ljava/lang/String; diff --git a/mirai-core-api/src/commonMain/kotlin/contact/announcement/AnnouncementImage.kt b/mirai-core-api/src/commonMain/kotlin/contact/announcement/AnnouncementImage.kt index 85dcf7289..fc8d34a60 100644 --- a/mirai-core-api/src/commonMain/kotlin/contact/announcement/AnnouncementImage.kt +++ b/mirai-core-api/src/commonMain/kotlin/contact/announcement/AnnouncementImage.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -31,6 +31,11 @@ public class AnnouncementImage private constructor( ) { // For stability, do not make it `data class`. + /** + * @since 2.15 + */ + public val url: String get() = "https://gdynamic.qpic.cn/gdynamic/$id/628" + public companion object { public const val SERIAL_NAME: String = "AnnouncementImage" diff --git a/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt b/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt index 9118bddfe..2f05a229d 100644 --- a/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Mamoe Technologies and contributors. + * Copyright 2019-2023 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -48,12 +48,7 @@ import net.mamoe.mirai.utils.* import net.mamoe.mirai.utils.Either.Companion.onLeft import net.mamoe.mirai.utils.Either.Companion.rightOrNull -internal expect class AnnouncementsImpl( - group: GroupImpl, - logger: MiraiLogger, -) : CommonAnnouncementsImpl - -internal abstract class CommonAnnouncementsImpl( +internal class AnnouncementsImpl( protected val group: GroupImpl, protected val logger: MiraiLogger, ) : Announcements { @@ -412,6 +407,7 @@ internal object AnnouncementProtocol { showPopup = settings.tipWindowType == 0 requireConfirmation = settings.confirmRequired == 1 showEditCard = settings.isShowEditCard == 1 + image = msg.images.firstOrNull()?.toPublic() }, fid = fid, allConfirmed = isAllConfirm != 0, diff --git a/mirai-core/src/commonMain/kotlin/contact/announcement/GroupAnnouncement.kt b/mirai-core/src/commonMain/kotlin/contact/announcement/GroupAnnouncement.kt index 131410178..57f4ebcc4 100644 --- a/mirai-core/src/commonMain/kotlin/contact/announcement/GroupAnnouncement.kt +++ b/mirai-core/src/commonMain/kotlin/contact/announcement/GroupAnnouncement.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2023 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -63,7 +63,8 @@ internal class GroupAnnouncementImage @MiraiInternalApi constructor( @Serializable internal data class GroupAnnouncementMsg( val text: String, - val text_face: String? = null, + @SerialName("text_face") val textFace: String? = null, + @SerialName("pics") val images: List = emptyList(), // val title: String? = null // no title any more ) diff --git a/mirai-core/src/jvmBaseMain/kotlin/contact/announcement/AnnouncementsImpl.kt b/mirai-core/src/jvmBaseMain/kotlin/contact/announcement/AnnouncementsImpl.kt deleted file mode 100644 index faa2a4646..000000000 --- a/mirai-core/src/jvmBaseMain/kotlin/contact/announcement/AnnouncementsImpl.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2019-2022 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. - * - * https://github.com/mamoe/mirai/blob/dev/LICENSE - */ - -package net.mamoe.mirai.internal.contact.announcement - -import kotlinx.coroutines.runBlocking -import net.mamoe.mirai.contact.announcement.OnlineAnnouncement -import net.mamoe.mirai.internal.contact.GroupImpl -import net.mamoe.mirai.internal.contact.announcement.AnnouncementProtocol.toAnnouncement -import net.mamoe.mirai.utils.MiraiLogger -import net.mamoe.mirai.utils.stream -import java.util.stream.Stream - -internal actual class AnnouncementsImpl actual constructor( - group: GroupImpl, - logger: MiraiLogger, -) : CommonAnnouncementsImpl(group, logger) { - override fun asStream(): Stream { - return stream { - var i = 1 - while (true) { - val result = runBlocking { getGroupAnnouncementList(i++) } ?: break - - if (result.inst.isNullOrEmpty() && result.feeds.isNullOrEmpty()) break - - result.inst?.let { yieldAll(it) } - result.feeds?.let { yieldAll(it) } - } - }.map { it.toAnnouncement(group) } - } -} diff --git a/mirai-core/src/nativeMain/kotlin/contact/announcement/AnnouncementsImpl.kt b/mirai-core/src/nativeMain/kotlin/contact/announcement/AnnouncementsImpl.kt deleted file mode 100644 index 964c88f13..000000000 --- a/mirai-core/src/nativeMain/kotlin/contact/announcement/AnnouncementsImpl.kt +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2019-2022 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. - * - * https://github.com/mamoe/mirai/blob/dev/LICENSE - */ - -package net.mamoe.mirai.internal.contact.announcement - -import net.mamoe.mirai.internal.contact.GroupImpl -import net.mamoe.mirai.utils.MiraiLogger - -internal actual class AnnouncementsImpl actual constructor( - group: GroupImpl, - logger: MiraiLogger -) : CommonAnnouncementsImpl(group, logger) \ No newline at end of file