From cc2343e220c0a886f1dc00c62130c0b4c3778fd3 Mon Sep 17 00:00:00 2001 From: Him188 <Him188@mamoe.net> Date: Wed, 13 Nov 2019 19:54:13 +0800 Subject: [PATCH] Simplify logical process --- .../protocol/tim/packet/action/UploadImage.kt | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/UploadImage.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/UploadImage.kt index 753507315..a3bb4c412 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/UploadImage.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/UploadImage.kt @@ -36,27 +36,27 @@ class OverFileSizeMaxException : IllegalStateException() */ suspend fun Group.uploadImage(image: ExternalImage): ImageId = withSession { val userContext = coroutineContext - GroupImageIdRequestPacket(bot.qqAccount, internalId, image, sessionKey) - .sendAndExpectAsync<GroupImageIdRequestPacket.Response, Unit> { - withContext(userContext) { - when (it) { - is GroupImageIdRequestPacket.Response.RequireUpload -> httpClient.postImage( - htcmd = "0x6ff0071", - uin = bot.qqAccount, - groupId = GroupId(id), - imageInput = image.input, - inputSize = image.inputSize, - uKeyHex = it.uKey.toUHexString("") - ) + val response = GroupImageIdRequestPacket(bot.qqAccount, internalId, image, sessionKey).sendAndExpect<GroupImageIdRequestPacket.Response>() - is GroupImageIdRequestPacket.Response.AlreadyExists -> { - } + withContext(userContext) { + when (response) { + is GroupImageIdRequestPacket.Response.RequireUpload -> httpClient.postImage( + htcmd = "0x6ff0071", + uin = bot.qqAccount, + groupId = GroupId(id), + imageInput = image.input, + inputSize = image.inputSize, + uKeyHex = response.uKey.toUHexString("") + ) - is GroupImageIdRequestPacket.Response.OverFileSizeMax -> throw OverFileSizeMaxException() - } + is GroupImageIdRequestPacket.Response.AlreadyExists -> { } - }.join() - image.groupImageId + + is GroupImageIdRequestPacket.Response.OverFileSizeMax -> throw OverFileSizeMaxException() + } + } + + return image.groupImageId } /**