Browse Source

SEND IMAGE SUPPORT

Him188 5 years ago
parent
commit
359be12356

+ 16 - 1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/Msg.kt

@@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable
 import kotlinx.serialization.protobuf.ProtoNumberType
 import kotlinx.serialization.protobuf.ProtoNumberType
 import kotlinx.serialization.protobuf.ProtoType
 import kotlinx.serialization.protobuf.ProtoType
 import net.mamoe.mirai.qqandroid.io.ProtoBuf
 import net.mamoe.mirai.qqandroid.io.ProtoBuf
+import net.mamoe.mirai.qqandroid.io.serialization.toByteArray
 import net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY
 import net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY
 
 
 @Serializable
 @Serializable
@@ -624,7 +625,7 @@ internal class ImMsgBody : ProtoBuf {
     internal class NotOnlineImage(
     internal class NotOnlineImage(
         @SerialId(1) val filePath: String = "",
         @SerialId(1) val filePath: String = "",
         @SerialId(2) val fileLen: Int = 0,
         @SerialId(2) val fileLen: Int = 0,
-        @SerialId(3) val downloadPath: ByteArray = EMPTY_BYTE_ARRAY,
+        @SerialId(3) val downloadPath: String = "",
         @SerialId(4) val oldVerSendFile: ByteArray = EMPTY_BYTE_ARRAY,
         @SerialId(4) val oldVerSendFile: ByteArray = EMPTY_BYTE_ARRAY,
         @SerialId(5) val imgType: Int = 0,
         @SerialId(5) val imgType: Int = 0,
         @SerialId(6) val previewsImage: ByteArray = EMPTY_BYTE_ARRAY,
         @SerialId(6) val previewsImage: ByteArray = EMPTY_BYTE_ARRAY,
@@ -653,6 +654,20 @@ internal class ImMsgBody : ProtoBuf {
         @SerialId(29) val pbReserve: ByteArray = EMPTY_BYTE_ARRAY
         @SerialId(29) val pbReserve: ByteArray = EMPTY_BYTE_ARRAY
     ) : ProtoBuf
     ) : ProtoBuf
 
 
+    @Serializable // 非官方.
+    internal data class PbReserve(
+        @SerialId(1) val unknown1: Int = 1,
+        @SerialId(2) val unknown2: Int = 0,
+        @SerialId(6) val unknown3: Int = 0,
+        @SerialId(8) val hint: String = "[动画表情]",
+        @SerialId(10) val unknown5: Int = 0,
+        @SerialId(15) val unknwon6: Int = 5
+    ) : ProtoBuf {
+        companion object {
+            val DEFAULT: ByteArray = PbReserve().toByteArray(serializer())
+        }
+    }
+
     @Serializable
     @Serializable
     internal class OnlineImage(
     internal class OnlineImage(
         @SerialId(1) val guid: ByteArray = EMPTY_BYTE_ARRAY,
         @SerialId(1) val guid: ByteArray = EMPTY_BYTE_ARRAY,

+ 11 - 1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/MessageQQA.kt

@@ -3,6 +3,7 @@ package net.mamoe.mirai.qqandroid.utils
 import net.mamoe.mirai.data.ImageLink
 import net.mamoe.mirai.data.ImageLink
 import net.mamoe.mirai.message.data.*
 import net.mamoe.mirai.message.data.*
 import net.mamoe.mirai.qqandroid.network.protocol.data.proto.ImMsgBody
 import net.mamoe.mirai.qqandroid.network.protocol.data.proto.ImMsgBody
+import net.mamoe.mirai.utils.io.hexToBytes
 
 
 
 
 internal fun MessageChain.toRichTextElems(): MutableList<ImMsgBody.Elem> {
 internal fun MessageChain.toRichTextElems(): MutableList<ImMsgBody.Elem> {
@@ -20,7 +21,16 @@ internal fun MessageChain.toRichTextElems(): MutableList<ImMsgBody.Elem> {
                 elems.add(
                 elems.add(
                     ImMsgBody.Elem(
                     ImMsgBody.Elem(
                         notOnlineImage = ImMsgBody.NotOnlineImage(
                         notOnlineImage = ImMsgBody.NotOnlineImage(
-                            filePath = it.id.value
+                            filePath = it.id.value, // 错了, 应该是 2B23D705CAD1F2CF3710FE582692FCC4.jpg
+                            fileLen = 1149, // 假的
+                            downloadPath = it.id.value,
+                            imgType = 1000, // 不确定
+                            picMd5 = "2B 23 D7 05 CA D1 F2 CF 37 10 FE 58 26 92 FC C4".hexToBytes(),
+                            picHeight = 66,
+                            picWidth = 66,
+                            resId = it.id.value,
+                            bizType = 5,
+                            pbReserve = ImMsgBody.PbReserve.DEFAULT // 可能还可以改变 `[动画表情]`
                         )
                         )
                     )
                     )
                 )
                 )

+ 1 - 1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt

@@ -14,7 +14,7 @@ fun Image(id: String) = Image(ImageId(id))
  * 由接收消息时构建, 可直接发送
  * 由接收消息时构建, 可直接发送
  *
  *
  * @param id 这个图片的 [ImageId]
  * @param id 这个图片的 [ImageId]
- */
+ */ // TODO: 2020/1/31 去掉 Image.  将 Image 改为 interface/class
 inline class Image(inline val id: ImageId) : Message {
 inline class Image(inline val id: ImageId) : Message {
     override fun toString(): String = "[${id.value}]"
     override fun toString(): String = "[${id.value}]"