From c016b822e765161a37c372c7138adc88b8377e26 Mon Sep 17 00:00:00 2001
From: cssxsh <cssxsh@gmail.com>
Date: Tue, 21 Mar 2023 22:45:42 +0800
Subject: [PATCH] =?UTF-8?q?[core]=20=E4=BF=AE=E5=A4=8D=E7=BE=A4=E5=85=AC?=
 =?UTF-8?q?=E5=91=8A=E6=9F=A5=E8=AF=A2=E5=B7=B2=E9=98=85=E8=AF=BB=E4=BA=BA?=
 =?UTF-8?q?=E5=91=98=E5=88=97=E8=A1=A8=E5=8F=AA=E8=83=BD=E8=8E=B7=E5=8F=96?=
 =?UTF-8?q?=E5=89=8D=2050=20=E4=B8=AA=E7=9A=84=E9=97=AE=E9=A2=98=20(#2530)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../contact/announcement/AnnouncementsImpl.kt | 35 ++++++++++++++++---
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt b/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt
index dea6f0c09..9118bddfe 100644
--- a/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt
+++ b/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt
@@ -148,8 +148,27 @@ internal abstract class CommonAnnouncementsImpl(
 
     override suspend fun members(fid: String, confirmed: Boolean): List<NormalMember> {
         group.checkBotPermission(MemberPermission.ADMINISTRATOR) { "Only administrator have permission see announcement confirmed detail" }
-        val detail = bot.getReadDetail(groupId = group.id, fid = fid, read = confirmed)
-        return detail.users.mapNotNull { user -> group[user.uin] }
+        val flow = flow<NormalMember> {
+            var offset = 0
+            while (true) {
+                val detail = bot.getReadDetail(
+                    groupId = group.id,
+                    fid = fid,
+                    read = confirmed,
+                    offset = offset,
+                    limit = 50
+                )
+                if (detail.users.isEmpty()) break
+                for (user in detail.users) {
+                    val member = group[user.uin] ?: continue
+                    emit(member)
+                }
+                offset += detail.users.size
+                val target = if (confirmed) detail.readTotal else detail.unreadTotal
+                if (offset == target) break
+            }
+        }
+        return flow.toList()
     }
 
     override suspend fun remind(fid: String) {
@@ -318,12 +337,18 @@ internal object AnnouncementProtocol {
     private fun <T> CgiData.loadData(serializer: KSerializer<T>): T =
         defaultJson.decodeFromJsonElement(serializer, this.data)
 
-    suspend fun QQAndroidBot.getReadDetail(groupId: Long, fid: String, read: Boolean): GroupAnnouncementReadDetail {
+    suspend fun QQAndroidBot.getReadDetail(
+        groupId: Long,
+        fid: String,
+        read: Boolean,
+        offset: Int,
+        limit: Int
+    ): GroupAnnouncementReadDetail {
         val cgi = bot.components[HttpClientProvider].getHttpClient().post {
             url("https://qun.qq.com/cgi-bin/qunapp/announce_unread")
             parameter("gc", groupId)
-            parameter("start", 0)
-            parameter("num", 3000)
+            parameter("start", offset)
+            parameter("num", limit)
             parameter("feed_id", fid)
             parameter("type", if (read) 1 else 0)
             parameter("bkn", client.wLoginSigInfo.bkn)