fix(routing): treat group/channel peer.kind as equivalent (land #31135 by @Sid-Qin)

Landed-from: #31135
Contributor: @Sid-Qin
Co-authored-by: Sid <sidqin0410@gmail.com>
This commit is contained in:
Peter Steinberger
2026-03-02 01:46:46 +00:00
parent e076665e5e
commit 70ee256ae0
3 changed files with 82 additions and 1 deletions

View File

@@ -262,12 +262,24 @@ function hasRolesConstraint(match: NormalizedBindingMatch): boolean {
return Boolean(match.roles);
}
function peerKindMatches(bindingKind: ChatType, scopeKind: ChatType): boolean {
if (bindingKind === scopeKind) {
return true;
}
const both = new Set([bindingKind, scopeKind]);
return both.has("group") && both.has("channel");
}
function matchesBindingScope(match: NormalizedBindingMatch, scope: BindingScope): boolean {
if (match.peer.state === "invalid") {
return false;
}
if (match.peer.state === "valid") {
if (!scope.peer || scope.peer.kind !== match.peer.kind || scope.peer.id !== match.peer.id) {
if (
!scope.peer ||
!peerKindMatches(match.peer.kind, scope.peer.kind) ||
scope.peer.id !== match.peer.id
) {
return false;
}
}