Simplify logical process

This commit is contained in:
Him188 2019-11-13 19:54:13 +08:00
parent c15651b9f7
commit cc2343e220

View File

@ -36,17 +36,17 @@ class OverFileSizeMaxException : IllegalStateException()
*/
suspend fun Group.uploadImage(image: ExternalImage): ImageId = withSession {
val userContext = coroutineContext
GroupImageIdRequestPacket(bot.qqAccount, internalId, image, sessionKey)
.sendAndExpectAsync<GroupImageIdRequestPacket.Response, Unit> {
val response = GroupImageIdRequestPacket(bot.qqAccount, internalId, image, sessionKey).sendAndExpect<GroupImageIdRequestPacket.Response>()
withContext(userContext) {
when (it) {
when (response) {
is GroupImageIdRequestPacket.Response.RequireUpload -> httpClient.postImage(
htcmd = "0x6ff0071",
uin = bot.qqAccount,
groupId = GroupId(id),
imageInput = image.input,
inputSize = image.inputSize,
uKeyHex = it.uKey.toUHexString("")
uKeyHex = response.uKey.toUHexString("")
)
is GroupImageIdRequestPacket.Response.AlreadyExists -> {
@ -55,8 +55,8 @@ suspend fun Group.uploadImage(image: ExternalImage): ImageId = withSession {
is GroupImageIdRequestPacket.Response.OverFileSizeMax -> throw OverFileSizeMaxException()
}
}
}.join()
image.groupImageId
return image.groupImageId
}
/**