From 8d115782657126d60f2a02b64d95968ea4b22570 Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 21 Feb 2020 22:29:58 +0800 Subject: [PATCH] Use newly introduced linear processing --- .../packet/chat/receive/MessageSvc.kt | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt index 57bddbfdb..9d415b113 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt @@ -9,7 +9,7 @@ package net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive -import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.Deferred import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.io.core.ByteReadPacket import kotlinx.io.core.discardExact @@ -19,11 +19,10 @@ import net.mamoe.mirai.contact.MemberPermission import net.mamoe.mirai.data.MemberInfo import net.mamoe.mirai.data.MultiPacket import net.mamoe.mirai.data.Packet -import net.mamoe.mirai.event.ListeningStatus import net.mamoe.mirai.event.events.BotJoinGroupEvent import net.mamoe.mirai.event.events.BotOfflineEvent import net.mamoe.mirai.event.events.MemberJoinEvent -import net.mamoe.mirai.event.subscribe +import net.mamoe.mirai.event.subscribingGetAsync import net.mamoe.mirai.message.FriendMessage import net.mamoe.mirai.message.data.MessageChain import net.mamoe.mirai.message.data.MessageSource @@ -279,17 +278,14 @@ internal class MessageSvc { override val groupId: Long, override val sourceMessage: MessageChain ) : MessageSource { - lateinit var sequenceIdDeferred: CompletableDeferred + lateinit var sequenceIdDeferred: Deferred + @UseExperimental(MiraiExperimentalAPI::class) fun startWaitingSequenceId(contact: Contact) { - sequenceIdDeferred = CompletableDeferred() - contact.subscribe { event -> - if (event.messageRandom == messageUid.toInt()) { - sequenceIdDeferred.complete(event.sequenceId) - return@subscribe ListeningStatus.STOPPED - } - - return@subscribe ListeningStatus.LISTENING + sequenceIdDeferred = contact.subscribingGetAsync { + if (it.messageRandom == messageUid.toInt()) { + it.sequenceId + } else null } }