mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(posts): render per-post IDs on initial board load
This commit is contained in:
@@ -22,7 +22,7 @@ import useHide from '../../hooks/use-hide';
|
||||
import useStateString from '../../hooks/use-state-string';
|
||||
import useScrollToReply from '../../hooks/use-scroll-to-reply';
|
||||
import { useCurrentTime } from '../../hooks/use-current-time';
|
||||
import { useSubplebbitField } from '../../hooks/use-stable-subplebbit';
|
||||
import { useBoardPseudonymityMode } from '../../hooks/use-board-pseudonymity-mode';
|
||||
import CommentContent from '../comment-content';
|
||||
import CommentMedia from '../comment-media';
|
||||
import EditMenu from '../edit-menu/edit-menu';
|
||||
@@ -214,11 +214,11 @@ const PostInfo = ({
|
||||
const alertThresholdSeconds = getAlertThresholdSeconds();
|
||||
const isOverThreshold = isAwaitingApproval && timeWaiting > alertThresholdSeconds;
|
||||
|
||||
const userID = address && getShortAddress(address); // shortened to 8 chars for display; users can verify the full user ID via "Copy user ID" in the post menu to guard against spoofing
|
||||
const userID = address ? getShortAddress(address) : shortAddress;
|
||||
const userIDBackgroundColor = hashStringToColor(userID);
|
||||
const userIDTextColor = getTextColorForBackground(userIDBackgroundColor);
|
||||
|
||||
const pseudonymityMode = useSubplebbitField(subplebbitAddress, (sub) => sub?.features?.pseudonymityMode);
|
||||
const pseudonymityMode = useBoardPseudonymityMode(subplebbitAddress);
|
||||
const showUserID = pseudonymityMode === 'per-post';
|
||||
|
||||
const handleUserAddressClick = useAuthorAddressClick();
|
||||
|
||||
@@ -21,7 +21,7 @@ import useHide from '../../hooks/use-hide';
|
||||
import useStateString from '../../hooks/use-state-string';
|
||||
import useScrollToReply from '../../hooks/use-scroll-to-reply';
|
||||
import { useCurrentTime } from '../../hooks/use-current-time';
|
||||
import { useSubplebbitField } from '../../hooks/use-stable-subplebbit';
|
||||
import { useBoardPseudonymityMode } from '../../hooks/use-board-pseudonymity-mode';
|
||||
import CommentContent from '../comment-content';
|
||||
import CommentMedia from '../comment-media';
|
||||
import LoadingEllipsis from '../loading-ellipsis';
|
||||
@@ -192,7 +192,7 @@ const PostInfoAndMedia = ({ post, postReplyCount = 0, roles, threadNumber }: Pos
|
||||
const canDeleteFailedPost = hasFailedState && typeof post?.index === 'number';
|
||||
const postMenuProps = selectPostMenuProps(post);
|
||||
|
||||
const pseudonymityMode = useSubplebbitField(subplebbitAddress, (sub) => sub?.features?.pseudonymityMode);
|
||||
const pseudonymityMode = useBoardPseudonymityMode(subplebbitAddress);
|
||||
const showUserID = pseudonymityMode === 'per-post';
|
||||
|
||||
const handleUserAddressClick = useAuthorAddressClick();
|
||||
@@ -205,7 +205,7 @@ const PostInfoAndMedia = ({ post, postReplyCount = 0, roles, threadNumber }: Pos
|
||||
return Math.max(domCount, 1);
|
||||
})();
|
||||
|
||||
const userID = address && getShortAddress(address); // shortened to 8 chars for display; users can verify the full user ID via "Copy user ID" in the post menu to guard against spoofing
|
||||
const userID = address ? getShortAddress(address) : shortAddress;
|
||||
const userIDBackgroundColor = hashStringToColor(userID);
|
||||
const userIDTextColor = getTextColorForBackground(userIDBackgroundColor);
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useDirectoryByAddress } from './use-directories';
|
||||
import { useSubplebbitField } from './use-stable-subplebbit';
|
||||
|
||||
/**
|
||||
* Prefer authoritative live board metadata when available, but fall back to the
|
||||
* bundled directory entry so known boards can render IDs immediately on first load.
|
||||
*/
|
||||
export const useBoardPseudonymityMode = (subplebbitAddress: string | undefined): string | undefined => {
|
||||
const directory = useDirectoryByAddress(subplebbitAddress);
|
||||
const livePseudonymityMode = useSubplebbitField(subplebbitAddress, (sub) => sub?.features?.pseudonymityMode);
|
||||
|
||||
return livePseudonymityMode ?? directory?.features?.pseudonymityMode;
|
||||
};
|
||||
@@ -50,6 +50,7 @@ const CACHE_MAX_AGE_MS = 60 * 60 * 1000; // 1 hour
|
||||
let cacheCommunities: DirectoryCommunity[] | null = null;
|
||||
let cacheMetadata: DirectoriesMetadata | null = null;
|
||||
let inFlightGitHubFetch: Promise<DirectoriesData> | null = null;
|
||||
const DIRECTORY_ALIAS_SUFFIXES = ['.bso', '.eth'] as const;
|
||||
|
||||
const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null;
|
||||
|
||||
@@ -134,6 +135,30 @@ const adaptV2Directories = (value: Record<string, unknown>): DirectoryCommunity[
|
||||
return dedupeCommunities(communities);
|
||||
};
|
||||
|
||||
const getDirectoryAddressLookupKey = (address: string): string => {
|
||||
for (const suffix of DIRECTORY_ALIAS_SUFFIXES) {
|
||||
if (address.endsWith(suffix)) {
|
||||
return address.slice(0, -suffix.length);
|
||||
}
|
||||
}
|
||||
|
||||
return address;
|
||||
};
|
||||
|
||||
const findDirectoryByAddress = (directories: DirectoryCommunity[], address: string | undefined): DirectoryCommunity | undefined => {
|
||||
if (!address) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const exactMatch = directories.find((community) => community.address === address);
|
||||
if (exactMatch) {
|
||||
return exactMatch;
|
||||
}
|
||||
|
||||
const addressLookupKey = getDirectoryAddressLookupKey(address);
|
||||
return directories.find((community) => getDirectoryAddressLookupKey(community.address) === addressLookupKey);
|
||||
};
|
||||
|
||||
const adaptV1Communities = (value: Record<string, unknown>): DirectoryCommunity[] => {
|
||||
if (!Array.isArray(value.communities)) {
|
||||
return [];
|
||||
@@ -376,7 +401,7 @@ export const useDirectoryAddresses = () => {
|
||||
|
||||
export const useDirectoryByAddress = (address: string | undefined) => {
|
||||
const directories = useDirectories();
|
||||
return useMemo(() => (address ? directories.find((c) => c.address === address) : undefined), [directories, address]);
|
||||
return useMemo(() => findDirectoryByAddress(directories, address), [directories, address]);
|
||||
};
|
||||
|
||||
export const useDirectoriesMetadata = () => {
|
||||
|
||||
Reference in New Issue
Block a user