Skip to content

Commit

Permalink
[console] Deprecate PermitteeId.hasChild and replace with PermitteeId…
Browse files Browse the repository at this point in the history
….isChildOf (#2762)

* fix: hasChild

* fix: docs

* feat: contains

* add: api dump

* fix: isChildOf
  • Loading branch information
cssxsh authored Aug 12, 2023
1 parent fca4a3c commit 0aad162
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,7 @@ public abstract interface class net/mamoe/mirai/console/permission/PermitteeId {
public static fun getAllParentsWithSelf (Lnet/mamoe/mirai/console/permission/PermitteeId;)Lkotlin/sequences/Sequence;
public abstract fun getDirectParents ()[Lnet/mamoe/mirai/console/permission/PermitteeId;
public static fun hasChild (Lnet/mamoe/mirai/console/permission/PermitteeId;Lnet/mamoe/mirai/console/permission/PermitteeId;)Z
public static fun isChildOf (Lnet/mamoe/mirai/console/permission/PermitteeId;Lnet/mamoe/mirai/console/permission/PermitteeId;)Z
}

public final class net/mamoe/mirai/console/permission/PermitteeId$Companion {
Expand All @@ -1796,6 +1797,7 @@ public final class net/mamoe/mirai/console/permission/PermitteeId$Companion {
public final synthetic fun getPermitteeId (Lnet/mamoe/mirai/contact/User;)Lnet/mamoe/mirai/console/permission/AbstractPermitteeId$ExactUser;
public final synthetic fun getPermitteeIdOnTemp (Lnet/mamoe/mirai/contact/Member;)Lnet/mamoe/mirai/console/permission/AbstractPermitteeId$ExactGroupTemp;
public final fun hasChild (Lnet/mamoe/mirai/console/permission/PermitteeId;Lnet/mamoe/mirai/console/permission/PermitteeId;)Z
public final fun isChildOf (Lnet/mamoe/mirai/console/permission/PermitteeId;Lnet/mamoe/mirai/console/permission/PermitteeId;)Z
}

public abstract interface class net/mamoe/mirai/console/plugin/NotYetLoadedPlugin : net/mamoe/mirai/console/plugin/Plugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import net.mamoe.mirai.console.data.PluginDataExtensions
import net.mamoe.mirai.console.permission.*
import net.mamoe.mirai.console.permission.Permission.Companion.parentsWithSelf
import net.mamoe.mirai.console.permission.PermitteeId.Companion.allParentsWithSelf
import net.mamoe.mirai.console.permission.PermitteeId.Companion.hasChild
import net.mamoe.mirai.console.permission.PermitteeId.Companion.isChildOf

internal abstract class AbstractConcurrentPermissionService<P : Permission> : PermissionService<P> {
protected abstract val permissions: MutableMap<PermissionId, P>
Expand Down Expand Up @@ -75,7 +75,7 @@ internal abstract class AbstractConcurrentPermissionService<P : Permission> : Pe
override fun getPermittedPermissions(permitteeId: PermitteeId): Sequence<P> = sequence {
for ((permissionIdentifier, permissibleIdentifiers) in grantedPermissionsMap) {

val granted = permissibleIdentifiers.any { permitteeId.hasChild(it) }
val granted = permissibleIdentifiers.any { permitteeId.isChildOf(it) }

if (granted) get(permissionIdentifier)?.let { yield(it) }
}
Expand All @@ -84,7 +84,7 @@ internal abstract class AbstractConcurrentPermissionService<P : Permission> : Pe
internal fun getPermittedPermissionsAndSource(permitteeId: PermitteeId): Sequence<Pair<PermitteeId, P>> = sequence {
for ((permissionIdentifier, permissibleIdentifiers) in grantedPermissionsMap) {
permissibleIdentifiers.forEach { pid ->
if (permitteeId.hasChild(pid)) {
if (permitteeId.isChildOf(pid)) {
get(permissionIdentifier)?.let { yield(pid to it) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,19 @@ public interface PermitteeId {

public companion object {
/**
* 当 [this] 或 [this] 的任意一个直接或间接父 [PermitteeId.asString] 与 `this.asString` 相同时返回 `true`
* 当 [this] 或 [this] 的任意一个直接或间接父 [PermitteeId.asString] 与 `parent.asString` 相同时返回 `true`
*
* @since 2.16
*/
@JvmStatic
public fun PermitteeId.hasChild(child: PermitteeId): Boolean {
return allParentsWithSelf.any { it.asString() == child.asString() } // asString is for compatibility issue with external implementations
public fun PermitteeId.isChildOf(parent: PermitteeId): Boolean {
return allParentsWithSelf.any { it.asString() == parent.asString() } // asString is for compatibility issue with external implementations
}

@JvmStatic
@DeprecatedSinceMirai(warningSince = "2.16")
public fun PermitteeId.hasChild(child: PermitteeId): Boolean = isChildOf(child)

/**
* 获取所有直接或间接父类的 [PermitteeId].
*/
Expand Down

0 comments on commit 0aad162

Please sign in to comment.