Commit cc2343e2 authored by Him188's avatar Him188

Simplify logical process

parent c15651b9
......@@ -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>()
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.AlreadyExists -> {
}
is GroupImageIdRequestPacket.Response.AlreadyExists -> {
}
is GroupImageIdRequestPacket.Response.OverFileSizeMax -> throw OverFileSizeMaxException()
}
}
is GroupImageIdRequestPacket.Response.OverFileSizeMax -> throw OverFileSizeMaxException()
}
}
}.join()
image.groupImageId
return image.groupImageId
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment