Commit b9d5fa4c authored by Him188's avatar Him188

Fix #107

parent a5c3e9f5
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
- 适配 8.2.7 版本(2020 年 3 月)协议 - 适配 8.2.7 版本(2020 年 3 月)协议
- 全面的 `Image` 类型: Online/Offline Image, Friend/Group Image - 全面的 `Image` 类型: Online/Offline Image, Friend/Group Image
- 修复查询图片链接时好友图片链接错误的问题 - 修复查询图片链接时好友图片链接错误的问题
- Kotlin 1.3.70
- 修复事件处理错误 (#107)
## `0.24.1` 2020/3/3 ## `0.24.1` 2020/3/3
- 修复 `Member` 的委托 `QQ` 弱引用被释放的问题 - 修复 `Member` 的委托 `QQ` 弱引用被释放的问题
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
package net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive package net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive
import io.ktor.utils.io.core.ByteReadPacket import io.ktor.utils.io.core.ByteReadPacket
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.*
import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.contact.MemberPermission import net.mamoe.mirai.contact.MemberPermission
import net.mamoe.mirai.data.MemberInfo import net.mamoe.mirai.data.MemberInfo
...@@ -18,6 +20,7 @@ import net.mamoe.mirai.data.Packet ...@@ -18,6 +20,7 @@ import net.mamoe.mirai.data.Packet
import net.mamoe.mirai.event.events.BotJoinGroupEvent import net.mamoe.mirai.event.events.BotJoinGroupEvent
import net.mamoe.mirai.event.events.BotOfflineEvent import net.mamoe.mirai.event.events.BotOfflineEvent
import net.mamoe.mirai.event.events.MemberJoinEvent import net.mamoe.mirai.event.events.MemberJoinEvent
import net.mamoe.mirai.getFriendOrNull
import net.mamoe.mirai.message.FriendMessage import net.mamoe.mirai.message.FriendMessage
import net.mamoe.mirai.message.data.MessageChain import net.mamoe.mirai.message.data.MessageChain
import net.mamoe.mirai.qqandroid.GroupImpl import net.mamoe.mirai.qqandroid.GroupImpl
...@@ -119,7 +122,7 @@ internal class MessageSvc { ...@@ -119,7 +122,7 @@ internal class MessageSvc {
object EmptyResponse : GetMsgSuccess(emptyList()) object EmptyResponse : GetMsgSuccess(emptyList())
@OptIn(MiraiInternalAPI::class, MiraiExperimentalAPI::class) @OptIn(MiraiInternalAPI::class, MiraiExperimentalAPI::class, FlowPreview::class)
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response { override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response {
// 00 00 01 0F 08 00 12 00 1A 34 08 FF C1 C4 F1 05 10 FF C1 C4 F1 05 18 E6 ED B9 C3 02 20 89 FE BE A4 06 28 8A CA 91 D1 0C 48 9B A5 BD 9B 0A 58 DE 9D 99 F8 08 60 1D 68 FF C1 C4 F1 05 70 00 20 02 2A 9D 01 08 F3 C1 C4 F1 05 10 A2 FF 8C F0 03 18 01 22 8A 01 0A 2A 08 A2 FF 8C F0 03 10 DD F1 92 B7 07 18 A6 01 20 0B 28 AE F9 01 30 F4 C1 C4 F1 05 38 A7 E3 D8 D4 84 80 80 80 01 B8 01 CD B5 01 12 08 08 01 10 00 18 00 20 00 1A 52 0A 50 0A 27 08 00 10 F4 C1 C4 F1 05 18 A7 E3 D8 D4 04 20 00 28 0C 30 00 38 86 01 40 22 4A 0C E5 BE AE E8 BD AF E9 9B 85 E9 BB 91 12 08 0A 06 0A 04 4E 4D 53 4C 12 15 AA 02 12 9A 01 0F 80 01 01 C8 01 00 F0 01 00 F8 01 00 90 02 00 12 04 4A 02 08 00 30 01 2A 15 08 97 A2 C1 F1 05 10 95 A6 F5 E5 0C 18 01 30 01 40 01 48 81 01 2A 10 08 D3 F7 B5 F1 05 10 DD F1 92 B7 07 18 01 30 01 38 00 42 00 48 00 // 00 00 01 0F 08 00 12 00 1A 34 08 FF C1 C4 F1 05 10 FF C1 C4 F1 05 18 E6 ED B9 C3 02 20 89 FE BE A4 06 28 8A CA 91 D1 0C 48 9B A5 BD 9B 0A 58 DE 9D 99 F8 08 60 1D 68 FF C1 C4 F1 05 70 00 20 02 2A 9D 01 08 F3 C1 C4 F1 05 10 A2 FF 8C F0 03 18 01 22 8A 01 0A 2A 08 A2 FF 8C F0 03 10 DD F1 92 B7 07 18 A6 01 20 0B 28 AE F9 01 30 F4 C1 C4 F1 05 38 A7 E3 D8 D4 84 80 80 80 01 B8 01 CD B5 01 12 08 08 01 10 00 18 00 20 00 1A 52 0A 50 0A 27 08 00 10 F4 C1 C4 F1 05 18 A7 E3 D8 D4 04 20 00 28 0C 30 00 38 86 01 40 22 4A 0C E5 BE AE E8 BD AF E9 9B 85 E9 BB 91 12 08 0A 06 0A 04 4E 4D 53 4C 12 15 AA 02 12 9A 01 0F 80 01 01 C8 01 00 F0 01 00 F8 01 00 90 02 00 12 04 4A 02 08 00 30 01 2A 15 08 97 A2 C1 F1 05 10 95 A6 F5 E5 0C 18 01 30 01 40 01 48 81 01 2A 10 08 D3 F7 B5 F1 05 10 DD F1 92 B7 07 18 01 30 01 38 00 42 00 48 00
val resp = readProtoBuf(MsgSvc.PbGetMsgResp.serializer()) val resp = readProtoBuf(MsgSvc.PbGetMsgResp.serializer())
...@@ -138,10 +141,9 @@ internal class MessageSvc { ...@@ -138,10 +141,9 @@ internal class MessageSvc {
return EmptyResponse return EmptyResponse
} }
val messages = resp.uinPairMsgs.asSequence() val messages = resp.uinPairMsgs.asFlow()
.filterNot { it.msg == null } .filterNot { it.msg == null }
.flatMap { it.msg!!.asSequence() } .flatMapConcat { it.msg!!.asFlow() }
.toList() // so as to inline
.mapNotNull<MsgComm.Msg, Packet> { msg -> .mapNotNull<MsgComm.Msg, Packet> { msg ->
when (msg.msgHead.msgType) { when (msg.msgHead.msgType) {
33 -> { 33 -> {
...@@ -164,7 +166,6 @@ internal class MessageSvc { ...@@ -164,7 +166,6 @@ internal class MessageSvc {
coroutineContext = bot.coroutineContext, coroutineContext = bot.coroutineContext,
id = Group.calculateGroupCodeByGroupUin(msg.msgHead.fromUin), id = Group.calculateGroupCodeByGroupUin(msg.msgHead.fromUin),
groupInfo = bot._lowLevelQueryGroupInfo(troopNum.groupCode).apply { groupInfo = bot._lowLevelQueryGroupInfo(troopNum.groupCode).apply {
this as GroupInfoImpl this as GroupInfoImpl
if (this.delegate.groupName == null) { if (this.delegate.groupName == null) {
...@@ -190,10 +191,12 @@ internal class MessageSvc { ...@@ -190,10 +191,12 @@ internal class MessageSvc {
bot.groups.delegate.addLast(newGroup) bot.groups.delegate.addLast(newGroup)
return@mapNotNull BotJoinGroupEvent(newGroup) return@mapNotNull BotJoinGroupEvent(newGroup)
} else { } else {
checkNotNull(group) { "group is null while a member is joining to" } if (group == null) {
return@mapNotNull null
}
if (group.members.contains(msg.msgHead.authUin)) { if (group.members.contains(msg.msgHead.authUin)) {
return@mapNotNull null return@mapNotNull null
} else { }
return@mapNotNull MemberJoinEvent(group.Member(object : MemberInfo { return@mapNotNull MemberJoinEvent(group.Member(object : MemberInfo {
override val nameCard: String get() = "" override val nameCard: String get() = ""
override val permission: MemberPermission get() = MemberPermission.MEMBER override val permission: MemberPermission get() = MemberPermission.MEMBER
...@@ -206,13 +209,13 @@ internal class MessageSvc { ...@@ -206,13 +209,13 @@ internal class MessageSvc {
}).also { group.members.delegate.addLast(it) }) }).also { group.members.delegate.addLast(it) })
} }
} }
}
166 -> { 166 -> {
val friend = bot.getFriendOrNull(msg.msgHead.fromUin) ?: return@mapNotNull null
return@mapNotNull when { return@mapNotNull when {
msg.msgHead.fromUin == bot.uin -> null msg.msgHead.fromUin == bot.uin -> null
!bot.firstLoginSucceed -> null !bot.firstLoginSucceed -> null
else -> FriendMessage( else -> FriendMessage(
bot.getFriend(msg.msgHead.fromUin), friend,
msg.toMessageChain() msg.toMessageChain()
) )
} }
...@@ -220,13 +223,12 @@ internal class MessageSvc { ...@@ -220,13 +223,12 @@ internal class MessageSvc {
else -> return@mapNotNull null else -> return@mapNotNull null
} }
} }
val list: List<Packet> = messages.toList()
if (resp.syncFlag == MsgSvc.SyncFlag.STOP) { if (resp.syncFlag == MsgSvc.SyncFlag.STOP) {
messages.ifEmpty { return GetMsgSuccess(list)
return EmptyResponse
}
return GetMsgSuccess(listOf(messages.last()))
} }
return Response(resp.syncFlag, messages) return Response(resp.syncFlag, list)
} }
override suspend fun QQAndroidBot.handle(packet: Response) { override suspend fun QQAndroidBot.handle(packet: Response) {
......
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