refactor: migrate 5chan to the community hooks API (#1073)

* refactor(community-api): migrate 5chan to community hooks

* fix(review): address PR feedback

* fix(review): preserve legacy board context fallbacks

* fix(review): address latest bot feedback

* fix(review): use communityAddress in edit menu privileges
This commit is contained in:
Tommaso Casaburi
2026-03-13 13:25:10 +08:00
committed by GitHub
parent 9dc4d96d27
commit d7703953fb
105 changed files with 2659 additions and 1491 deletions
+10 -4
View File
@@ -1,5 +1,9 @@
import type { Comment } from '@bitsocialnet/bitsocial-react-hooks';
import useSubplebbitsStore from '@bitsocialnet/bitsocial-react-hooks/dist/stores/subplebbits';
import communitiesStore from '@bitsocialnet/bitsocial-react-hooks/dist/stores/communities';
type CommunityLike = {
roles?: Record<string, { role?: string }>;
};
/**
* Checks if a text matches a pattern according to various pattern matching rules:
@@ -138,12 +142,14 @@ export const displayNameMatchesPattern = (comment: Comment, pattern: string): bo
* @returns True if the user has the specified role, false otherwise
*/
export const userHasRole = (comment: Comment, role: string): boolean => {
if (!role || !comment?.author?.address || !comment?.subplebbitAddress) {
const communityAddress = (comment as { communityAddress?: string }).communityAddress ?? comment?.subplebbitAddress;
if (!role || !comment?.author?.address || !communityAddress) {
return false;
}
const subplebbits = useSubplebbitsStore.getState().subplebbits;
const subplebbit = subplebbits[comment.subplebbitAddress];
const communities = communitiesStore.getState().communities;
const subplebbit = communities[communityAddress] as CommunityLike | undefined;
if (!subplebbit?.roles) {
return false;