Files
radicle-desktop/src/lib/roles.ts
T
Rūdolfs Ošiņš 974235b1fe Share comment thread building between patch views
Revision and ReviewPage built threads and checked who may resolve a
comment with their own near-identical copies.
2026-10-01 18:20:24 +02:00

44 lines
1.1 KiB
TypeScript

import { publicKeyFromDid } from "@app/lib/utils";
export function isDelegate(
publicKey: string | undefined,
delegates: string[],
): true | undefined {
if (!publicKey) {
return undefined;
}
return (
delegates.some(delegate => publicKeyFromDid(delegate) === publicKey) ||
undefined
);
}
export function isDelegateOrAuthor(
publicKey: string | undefined,
delegates: string[],
author: string,
): true | undefined {
return (
isDelegate(publicKey, delegates) ||
publicKey === publicKeyFromDid(author) ||
undefined
);
}
/// The protocol lets the comment author, the review author or the revision
/// author resolve a review comment; delegates may do anything.
export function canResolveReviewComment(
publicKey: string,
delegates: string[],
authors: {
comment: string | undefined;
review: string | undefined;
revision: string | undefined;
},
): boolean {
if (isDelegate(publicKey, delegates)) return true;
return [authors.comment, authors.review, authors.revision].some(
did => did !== undefined && publicKeyFromDid(did) === publicKey,
);
}