mirror of
https://github.com/block/buzz.git
synced 2026-11-30 21:21:48 +00:00
Signed-off-by: Matt Toohey <contact@matttoohey.com> Signed-off-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co>
79 lines
2.4 KiB
TypeScript
79 lines
2.4 KiB
TypeScript
import * as React from "react";
|
|
|
|
import {
|
|
mergeCurrentProfileIntoLookup,
|
|
profileLookupsEqual,
|
|
type UserProfileLookup,
|
|
} from "@/features/profile/lib/identity";
|
|
import type {
|
|
ChannelMember,
|
|
ManagedAgent,
|
|
Profile,
|
|
RelayAgent,
|
|
} from "@/shared/api/types";
|
|
import {
|
|
mergeAgentNamesIntoProfiles,
|
|
mergeMemberAgentFlagsIntoProfiles,
|
|
} from "./useChannelActivityTyping";
|
|
|
|
/**
|
|
* The channel screen's message-row profile lookup: the `users-batch` query
|
|
* profiles overlaid with the current profile, managed/relay agent names, and
|
|
* channel-member agent flags.
|
|
*
|
|
* Member agent flags (`role === "bot"` or `isAgent`) ride along in the lookup
|
|
* so a member-only bot — known through channel membership alone, with no
|
|
* profile `isAgent` flag and no managed/relay/feed presence — still passes
|
|
* MessageRow's per-pubkey `profiles[pk]?.isAgent` check; rows no longer see
|
|
* a member-derived agent set.
|
|
*
|
|
* The returned reference is stabilised across renders when no profile value
|
|
* changed: the raw merge gets a fresh identity whenever the `users-batch`
|
|
* query re-keys — which typing churn triggers constantly — and that identity
|
|
* flows to MessageRow's `prev.profiles === next.profiles` memo check, so an
|
|
* unstable reference re-renders the whole timeline per keystroke. Consumers
|
|
* read profiles by pubkey value only, never treating identity as a change
|
|
* signal, so returning the stale-but-value-identical reference is safe.
|
|
*/
|
|
export function useMessageProfiles({
|
|
channelMembers,
|
|
currentProfile,
|
|
currentPubkey,
|
|
managedAgents,
|
|
profiles,
|
|
relayAgents,
|
|
}: {
|
|
channelMembers: ChannelMember[] | undefined;
|
|
currentProfile: Profile | undefined;
|
|
currentPubkey: string | undefined;
|
|
managedAgents: ManagedAgent[];
|
|
profiles: UserProfileLookup | undefined;
|
|
relayAgents: RelayAgent[];
|
|
}): UserProfileLookup {
|
|
const raw = React.useMemo(() => {
|
|
const base = mergeCurrentProfileIntoLookup(profiles, currentProfile) ?? {};
|
|
return mergeMemberAgentFlagsIntoProfiles(
|
|
mergeAgentNamesIntoProfiles(
|
|
base,
|
|
managedAgents,
|
|
relayAgents,
|
|
currentPubkey,
|
|
),
|
|
channelMembers,
|
|
);
|
|
}, [
|
|
channelMembers,
|
|
currentProfile,
|
|
currentPubkey,
|
|
managedAgents,
|
|
profiles,
|
|
relayAgents,
|
|
]);
|
|
|
|
const ref = React.useRef(raw);
|
|
if (!profileLookupsEqual(ref.current, raw)) {
|
|
ref.current = raw;
|
|
}
|
|
return ref.current;
|
|
}
|