Remove inappropriate weak references

This commit is contained in:
Him188 2021-07-06 19:10:14 +08:00
parent be3c873f4f
commit d6c4b5456f
6 changed files with 5 additions and 18 deletions

View File

@ -36,7 +36,6 @@ public interface Contact : ContactOrBot, CoroutineScope {
/**
* 这个联系对象所属 [Bot].
*/
@WeakRefProperty
public override val bot: Bot
/**

View File

@ -21,7 +21,6 @@ import net.mamoe.mirai.message.action.Nudge
import net.mamoe.mirai.message.data.Message
import net.mamoe.mirai.message.data.isContentEmpty
import net.mamoe.mirai.utils.NotStableForInheritance
import net.mamoe.mirai.utils.WeakRefProperty
/**
* 代表一位群成员.
@ -41,7 +40,6 @@ public interface Member : User {
/**
* 所在的群.
*/
@WeakRefProperty
public val group: Group
/**

View File

@ -11,18 +11,13 @@ package net.mamoe.mirai.internal.contact
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import net.mamoe.mirai.Bot
import net.mamoe.mirai.contact.Contact
import net.mamoe.mirai.internal.QQAndroidBot
import net.mamoe.mirai.utils.cast
import net.mamoe.mirai.utils.getValue
import net.mamoe.mirai.utils.unsafeWeakRef
import kotlin.coroutines.CoroutineContext
internal abstract class AbstractContact(
bot: Bot,
final override val bot: QQAndroidBot,
coroutineContext: CoroutineContext,
) : Contact {
final override val coroutineContext: CoroutineContext = coroutineContext + SupervisorJob(coroutineContext[Job])
final override val bot: QQAndroidBot by bot.cast<QQAndroidBot>().unsafeWeakRef()
}

View File

@ -14,17 +14,13 @@ import net.mamoe.mirai.contact.MemberPermission
import net.mamoe.mirai.data.MemberInfo
import net.mamoe.mirai.internal.contact.info.MemberInfoImpl
import net.mamoe.mirai.utils.cast
import net.mamoe.mirai.utils.getValue
import net.mamoe.mirai.utils.unsafeWeakRef
import kotlin.coroutines.CoroutineContext
internal abstract class AbstractMember(
group: GroupImpl,
final override val group: GroupImpl,
coroutineContext: CoroutineContext,
memberInfo: MemberInfo,
) : AbstractUser(group.bot, coroutineContext, memberInfo), Member {
final override val group: GroupImpl by group.unsafeWeakRef()
final override val info: MemberInfoImpl = memberInfo.cast()
override val nameCard: String get() = info.nameCard

View File

@ -9,12 +9,12 @@
package net.mamoe.mirai.internal.contact
import net.mamoe.mirai.Bot
import net.mamoe.mirai.Mirai
import net.mamoe.mirai.contact.User
import net.mamoe.mirai.data.UserInfo
import net.mamoe.mirai.event.broadcast
import net.mamoe.mirai.event.events.*
import net.mamoe.mirai.internal.QQAndroidBot
import net.mamoe.mirai.internal.message.OfflineFriendImage
import net.mamoe.mirai.internal.message.contextualBugReportException
import net.mamoe.mirai.internal.message.getImageType
@ -40,7 +40,7 @@ import kotlin.coroutines.CoroutineContext
internal val User.info: UserInfo? get() = this.castOrNull<AbstractUser>()?.info
internal abstract class AbstractUser(
bot: Bot,
bot: QQAndroidBot,
coroutineContext: CoroutineContext,
userInfo: UserInfo,
) : User, AbstractContact(bot, coroutineContext) {

View File

@ -9,7 +9,6 @@
package net.mamoe.mirai.internal.contact
import net.mamoe.mirai.Bot
import net.mamoe.mirai.contact.OtherClient
import net.mamoe.mirai.contact.OtherClientInfo
import net.mamoe.mirai.internal.QQAndroidBot
@ -29,7 +28,7 @@ internal fun QQAndroidBot.createOtherClient(
}
internal class OtherClientImpl(
bot: Bot,
bot: QQAndroidBot,
coroutineContext: CoroutineContext,
override val info: OtherClientInfo,
) : OtherClient, AbstractContact(bot, coroutineContext) {