mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 09:50:16 +08:00
Fix #245
This commit is contained in:
parent
ca216bc492
commit
c425a809ba
@ -328,7 +328,6 @@ internal class GroupImpl(
|
||||
msg
|
||||
) {
|
||||
source = it
|
||||
source.startWaitingSequenceId(this)
|
||||
}.sendAndExpect()
|
||||
if (response is MessageSvc.PbSendMsg.Response.Failed) {
|
||||
when (response.resultType) {
|
||||
@ -352,6 +351,7 @@ internal class GroupImpl(
|
||||
"Timeout awaiting sequenceId for group message(${message.contentToString()
|
||||
.take(10)}). Some features may not work properly"
|
||||
}
|
||||
bot.network.logger.warning(e)
|
||||
}
|
||||
|
||||
return MessageReceipt(source, this, botAsMember)
|
||||
|
@ -17,8 +17,8 @@ import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.contact.Member
|
||||
import net.mamoe.mirai.contact.QQ
|
||||
import net.mamoe.mirai.event.asyncFromEventOrNull
|
||||
import net.mamoe.mirai.event.internal.MiraiAtomicBoolean
|
||||
import net.mamoe.mirai.event.subscribingGetAsync
|
||||
import net.mamoe.mirai.message.data.MessageChain
|
||||
import net.mamoe.mirai.message.data.MessageSource
|
||||
import net.mamoe.mirai.message.data.OnlineMessageSource
|
||||
@ -27,7 +27,6 @@ import net.mamoe.mirai.qqandroid.network.protocol.data.proto.MsgComm
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.SourceMsg
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.OnlinePush
|
||||
import net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
|
||||
|
||||
private fun <T> T.toJceDataImpl(): ImMsgBody.SourceMsg
|
||||
@ -104,6 +103,7 @@ internal class MessageSourceToTempImpl(
|
||||
}
|
||||
|
||||
internal class MessageSourceToGroupImpl(
|
||||
coroutineScope: CoroutineScope,
|
||||
override val random: Int,
|
||||
override val time: Int,
|
||||
override val originalMessage: MessageChain,
|
||||
@ -115,29 +115,25 @@ internal class MessageSourceToGroupImpl(
|
||||
override val bot: Bot
|
||||
get() = sender
|
||||
override var isRecalledOrPlanned: MiraiAtomicBoolean = MiraiAtomicBoolean(false)
|
||||
private lateinit var sequenceIdDeferred: Deferred<Int>
|
||||
|
||||
private val sequenceIdDeferred: Deferred<Int?> =
|
||||
coroutineScope.asyncFromEventOrNull<OnlinePush.PbPushGroupMsg.SendGroupMessageReceipt, Int>(
|
||||
timeoutMillis = 3000
|
||||
) {
|
||||
if (it.messageRandom == this@MessageSourceToGroupImpl.random) {
|
||||
it.sequenceId
|
||||
} else null
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
override val sequenceId: Int
|
||||
get() = when {
|
||||
sequenceIdDeferred.isCompleted -> sequenceIdDeferred.getCompleted()
|
||||
sequenceIdDeferred.isCompleted -> sequenceIdDeferred.getCompleted() ?: 0
|
||||
!sequenceIdDeferred.isActive -> 0
|
||||
else -> error("sequenceId not yet available")
|
||||
}
|
||||
|
||||
@OptIn(MiraiExperimentalAPI::class)
|
||||
internal fun startWaitingSequenceId(coroutineScope: CoroutineScope) {
|
||||
sequenceIdDeferred =
|
||||
coroutineScope.subscribingGetAsync<OnlinePush.PbPushGroupMsg.SendGroupMessageReceipt, Int>(
|
||||
timeoutMillis = 3000
|
||||
) {
|
||||
if (it.messageRandom == this@MessageSourceToGroupImpl.id) {
|
||||
it.sequenceId
|
||||
} else null
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun ensureSequenceIdAvailable() = sequenceIdDeferred.join()
|
||||
suspend fun ensureSequenceIdAvailable() = kotlin.run { sequenceIdDeferred.await() }
|
||||
|
||||
private val jceData by lazy {
|
||||
val elements = originalMessage.toRichTextElems(forGroup = false, withGeneralFlags = true)
|
||||
|
@ -37,7 +37,6 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.login.ConfigPushSvc
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.Heartbeat
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.StatSvc
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.WtLogin
|
||||
import net.mamoe.mirai.qqandroid.utils.NoRouteToHostException
|
||||
import net.mamoe.mirai.qqandroid.utils.PlatformSocket
|
||||
import net.mamoe.mirai.qqandroid.utils.SocketException
|
||||
import net.mamoe.mirai.qqandroid.utils.io.readPacketExact
|
||||
@ -315,7 +314,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
||||
this@QQAndroidBotNetworkHandler.launch {
|
||||
logger.info { "Awaiting ConfigPushSvc.PushReq" }
|
||||
val resp =
|
||||
subscribingGetOrNull<ConfigPushSvc.PushReq.PushReqResponse, ConfigPushSvc.PushReq.PushReqResponse>(
|
||||
syncFromEventOrNull<ConfigPushSvc.PushReq.PushReqResponse, ConfigPushSvc.PushReq.PushReqResponse>(
|
||||
10_000) { it }
|
||||
|
||||
when (resp) {
|
||||
@ -337,7 +336,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
||||
}
|
||||
|
||||
withTimeoutOrNull(30000) {
|
||||
launch { subscribingGet<MessageSvc.PbGetMsg.GetMsgSuccess, Unit> { Unit } }
|
||||
launch { syncFromEvent<MessageSvc.PbGetMsg.GetMsgSuccess, Unit> { Unit } }
|
||||
MessageSvc.PbGetMsg(bot.client, MsgSvc.SyncFlag.START, currentTimeSeconds).sendAndExpect<Packet>()
|
||||
} ?: error("timeout syncing friend message history")
|
||||
|
||||
|
@ -468,6 +468,7 @@ internal class MessageSvc {
|
||||
): OutgoingPacket {
|
||||
|
||||
val source = MessageSourceToGroupImpl(
|
||||
group,
|
||||
random = Random.nextInt().absoluteValue,
|
||||
sender = client.bot,
|
||||
target = group,
|
||||
|
Loading…
Reference in New Issue
Block a user