Merge remote-tracking branch 'origin/master'

This commit is contained in:
jiahua.liu 2020-02-04 14:30:24 +08:00
commit 44585d2df6
6 changed files with 75 additions and 16 deletions

View File

@ -44,9 +44,6 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin
TODO("not implemented")
}
override val isOnline: Boolean
get() = true
override suspend fun queryProfile(): Profile {
TODO("not implemented")
}

View File

@ -169,7 +169,7 @@ internal object KnownPacketFactories {
PacketLogger.verbose("包类型(flag2) = $flag2. (可能是 ${if (flag2 == 2) "OicqRequest" else "Uni"})")
val flag3 = readByte().toInt()
check(flag3 == 0) { "Illegal flag3. Expected 0, whereas got $flag3. flag1=$flag1, flag2=$flag2" }
check(flag3 == 0) { "Illegal flag3. Expected 0, whereas got $flag3. flag1=$flag1, flag2=$flag2. Remaining=${this.readBytes().toUHexString()}" }
readString(readInt() - 4)// uinAccount

View File

@ -14,7 +14,6 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY
import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket
import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacketFactory
import net.mamoe.mirai.qqandroid.network.protocol.packet.buildOutgoingUniPacket
import net.mamoe.mirai.utils.io.debugIfFail
internal class FriendList {
@ -22,7 +21,7 @@ internal class FriendList {
internal object GetTroopMemberList :
OutgoingPacketFactory<GetTroopMemberList.Response>("friendlist.GetTroopMemberListReq") {
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response {
val res = this.debugIfFail { this.decodeUniPacket(GetTroopMemberListResp.serializer()) }
val res = this.decodeUniPacket(GetTroopMemberListResp.serializer())
return Response(
res.vecTroopMember,
res.nextUin

View File

@ -2,9 +2,7 @@
package net.mamoe.mirai.contact
import net.mamoe.mirai.utils.LockFreeLinkedList
import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils.joinToString
import net.mamoe.mirai.utils.*
/**
@ -24,10 +22,12 @@ class ContactList<C : Contact>(@MiraiInternalAPI val delegate: LockFreeLinkedLis
operator fun get(id: Long): C = delegate[id]
fun getOrNull(id: Long): C? = delegate.getOrNull(id)
fun containsId(id: Long): Boolean = delegate.getOrNull(id) != null
@Deprecated("Use contains instead", ReplaceWith("contains(id)"))
fun containsId(id: Long): Boolean = contains(id)
val size: Int get() = delegate.size
operator fun contains(element: C): Boolean = delegate.contains(element)
operator fun contains(id: Long): Boolean = delegate.getOrNull(id) != null
fun containsAll(elements: Collection<C>): Boolean = elements.all { contains(it) }
fun isEmpty(): Boolean = delegate.isEmpty()
inline fun forEach(block: (C) -> Unit) = delegate.forEach(block)
@ -50,5 +50,35 @@ inline fun <C : Contact> LockFreeLinkedList<C>.filteringGetOrNull(filter: (C) ->
return null
}
fun <C : Contact> LockFreeLinkedList<C>.getOrAdd(id: Long, supplier: () -> C): C =
filteringGetOrAdd({ it.id == id }, supplier)
/**
* Collect all the elements into a [MutableList] then cast it as a [List]
*/
fun <E : Contact> ContactList<E>.toList(): List<E> = toMutableList()
/**
* Collect all the elements into a [MutableList].
*/
@UseExperimental(MiraiInternalAPI::class)
fun <E : Contact> ContactList<E>.toMutableList(): MutableList<E> = this.delegate.toMutableList()
/**
* Collect all the elements into a [MutableSet] then cast it as a [Set]
*/
fun <E : Contact> ContactList<E>.toSet(): Set<E> = toMutableSet()
/**
* Collect all the elements into a [MutableSet].
*/
@UseExperimental(MiraiInternalAPI::class)
fun <E : Contact> ContactList<E>.toMutableSet(): MutableSet<E> = this.delegate.toMutableSet()
/**
* Builds a [Sequence] containing all the elements in [this] in the same order.
*
* Note that the sequence is dynamic, that is, elements are yielded atomically only when it is required
*/
@UseExperimental(MiraiInternalAPI::class)
fun <E : Contact> ContactList<E>.asSequence(): Sequence<E> {
return this.delegate.asSequence()
}

View File

@ -22,9 +22,9 @@ import net.mamoe.mirai.data.Profile
*/
interface QQ : Contact, CoroutineScope {
/**
* 是否在线. 这个属性的值将会与服务器同步更新.
* QQ 号码
*/
val isOnline: Boolean
override val id: Long
/**
* 请求头像下载链接

View File

@ -19,12 +19,12 @@ inline fun <E> LockFreeLinkedList<E>.joinToString(
}.dropLast(separator.length) + postfix
/**
* Returns a [List] containing all the elements in [this] in the same order
* Collect all the elements into a [MutableList] then cast it as a [List]
*/
fun <E> LockFreeLinkedList<E>.toList(): List<E> = toMutableList()
/**
* Returns a [MutableList] containing all the elements in [this] in the same order
* Collect all the elements into a [MutableList].
*/
fun <E> LockFreeLinkedList<E>.toMutableList(): MutableList<E> {
val list = mutableListOf<E>()
@ -32,6 +32,33 @@ fun <E> LockFreeLinkedList<E>.toMutableList(): MutableList<E> {
return list
}
/**
* Collect all the elements into a [MutableSet] then cast it as a [Set]
*/
fun <E> LockFreeLinkedList<E>.toSet(): Set<E> = toMutableSet()
/**
* Collect all the elements into a [MutableSet].
*/
fun <E> LockFreeLinkedList<E>.toMutableSet(): MutableSet<E> {
val list = mutableSetOf<E>()
this.forEach { list.add(it) }
return list
}
/**
* Builds a [Sequence] containing all the elements in [this] in the same order.
*
* Note that the sequence is dynamic, that is, elements are yielded atomically only when it is required
*/
fun <E> LockFreeLinkedList<E>.asSequence(): Sequence<E> {
return sequence {
forEach {
yield(it)
}
}
}
/**
* Implementation of lock-free LinkedList.
*
@ -87,6 +114,9 @@ open class LockFreeLinkedList<E> {
open operator fun plusAssign(element: E) = this.addLast(element)
/**
* 过滤并获取, 获取不到则添加一个元素.
*/
inline fun filteringGetOrAdd(filter: (E) -> Boolean, noinline supplier: () -> E): E {
val node = LazyNode(tail, supplier)
@ -149,6 +179,9 @@ open class LockFreeLinkedList<E> {
}
}
/**
* 动态计算的大小
*/
val size: Int get() = head.countChildIterate<Node<E>>({ it.nextNode }, { it !is Tail }) - 1 // empty head is always included
open operator fun contains(element: E): Boolean {