mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix edit menu logic
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useAccount, useSubplebbit } from '@plebbit/plebbit-react-hooks';
|
||||
import useAnonModeStore from '../stores/use-anon-mode-store';
|
||||
import useAnonMode from './use-anon-mode';
|
||||
|
||||
interface AuthorPrivilegesProps {
|
||||
commentAuthorAddress: string;
|
||||
subplebbitAddress: string;
|
||||
postCid?: string;
|
||||
}
|
||||
|
||||
const useAuthorPrivileges = ({ commentAuthorAddress, subplebbitAddress }: AuthorPrivilegesProps) => {
|
||||
const accountAuthorAddress = useAccount()?.author?.address;
|
||||
const useAuthorPrivileges = ({ commentAuthorAddress, subplebbitAddress, postCid }: AuthorPrivilegesProps) => {
|
||||
const account = useAccount();
|
||||
const accountAuthorAddress = account?.author?.address;
|
||||
const { roles } = useSubplebbit({ subplebbitAddress }) || {};
|
||||
const { getAddressSigner } = useAnonModeStore();
|
||||
const { getAddressSigner, getThreadSigner } = useAnonModeStore();
|
||||
const { anonMode } = useAnonMode(postCid);
|
||||
|
||||
const { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor, commentAuthorRole, accountAuthorRole } = useMemo(() => {
|
||||
const commentAuthorRole = roles?.[commentAuthorAddress]?.role;
|
||||
@@ -20,13 +24,15 @@ const useAuthorPrivileges = ({ commentAuthorAddress, subplebbitAddress }: Author
|
||||
|
||||
let isAccountCommentAuthor = accountAuthorAddress === commentAuthorAddress;
|
||||
|
||||
if (!isAccountCommentAuthor) {
|
||||
const existingSigner = getAddressSigner(commentAuthorAddress);
|
||||
isAccountCommentAuthor = !!existingSigner;
|
||||
if (!isAccountCommentAuthor && anonMode) {
|
||||
const addressSigner = getAddressSigner(commentAuthorAddress);
|
||||
const threadSigner = postCid ? getThreadSigner(postCid) : null;
|
||||
|
||||
isAccountCommentAuthor = (addressSigner && addressSigner.address === commentAuthorAddress) || (threadSigner && threadSigner.address === commentAuthorAddress);
|
||||
}
|
||||
|
||||
return { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor, commentAuthorRole, accountAuthorRole };
|
||||
}, [roles, commentAuthorAddress, accountAuthorAddress, getAddressSigner]);
|
||||
}, [roles, commentAuthorAddress, accountAuthorAddress, anonMode, getAddressSigner, getThreadSigner, postCid]);
|
||||
|
||||
return { isCommentAuthorMod, isAccountMod, isAccountCommentAuthor, commentAuthorRole, accountAuthorRole };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user