Commit cc2343e2 authored by Him188's avatar Him188

Simplify logical process

parent c15651b9
......@@ -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
}
/**
......
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