Use NormalMemberImpl for properties of GroupImpl

This commit is contained in:
Him188 2021-06-26 16:04:37 +08:00
parent 03a18724fe
commit 975dd8e50b

View File

@ -79,24 +79,25 @@ internal class GroupImpl(
override val settings: GroupSettingsImpl = GroupSettingsImpl(this, groupInfo)
override var name: String by settings::name
override lateinit var owner: NormalMember
override lateinit var botAsMember: NormalMember
override lateinit var owner: NormalMemberImpl
override lateinit var botAsMember: NormalMemberImpl
override val filesRoot: RemoteFile by lazy { RemoteFileImpl(this, "/") }
override val members: ContactList<NormalMember> = ContactList(members.mapNotNullTo(ConcurrentLinkedQueue()) {
if (it.uin == bot.id) {
botAsMember = newMember(it).cast()
if (it.permission == MemberPermission.OWNER) {
owner = botAsMember
override val members: ContactList<NormalMemberImpl> =
ContactList(members.mapNotNullTo(ConcurrentLinkedQueue()) { info ->
if (info.uin == bot.id) {
botAsMember = newNormalMember(info)
if (info.permission == MemberPermission.OWNER) {
owner = botAsMember
}
null
} else newNormalMember(info).also { member ->
if (member.permission == MemberPermission.OWNER) {
owner = member
}
}
null
} else newMember(it).cast<NormalMember>().also { member ->
if (member.permission == MemberPermission.OWNER) {
owner = member
}
}
})
})
override val announcements: Announcements by lazy {
AnnouncementsImpl(
@ -128,7 +129,7 @@ internal class GroupImpl(
return true
}
override operator fun get(id: Long): NormalMember? {
override operator fun get(id: Long): NormalMemberImpl? {
if (id == bot.id) {
return botAsMember
}
@ -288,6 +289,7 @@ internal class GroupImpl(
override fun toString(): String = "Group($id)"
}
@Deprecated("use addNewNormalMember or newAnonymousMember")
internal fun Group.newMember(memberInfo: MemberInfo): Member {
this.checkIsGroupImpl()
memberInfo.anonymousId?.let { anId ->
@ -303,6 +305,32 @@ internal fun Group.newMember(memberInfo: MemberInfo): Member {
)
}
internal fun Group.addNewNormalMember(memberInfo: MemberInfo): NormalMemberImpl {
return newNormalMember(memberInfo).also {
members.delegate.add(it)
}
}
internal fun Group.newNormalMember(memberInfo: MemberInfo): NormalMemberImpl {
this.checkIsGroupImpl()
return NormalMemberImpl(
this,
this.coroutineContext,
memberInfo
)
}
internal fun Group.newAnonymousMember(memberInfo: MemberInfo): AnonymousMemberImpl? {
this.checkIsGroupImpl()
memberInfo.anonymousId?.let { anId ->
return AnonymousMemberImpl(
this, this.coroutineContext,
memberInfo, anId
)
}
return null
}
internal fun GroupImpl.newAnonymous(name: String, id: String): AnonymousMemberImpl = newMember(
MemberInfoImpl(
uin = 80000000L,