mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Wait for task marker backfill before opening links
This commit is contained in:
@@ -168,6 +168,24 @@ export function ChannelRouteScreen({
|
||||
const effectiveAgentConversationReplyId = isChannelTasksEnabled
|
||||
? targetAgentConversationReplyId
|
||||
: null;
|
||||
const targetAgentConversationBackfillKey =
|
||||
effectiveAgentConversationReplyId && !selectedPostId
|
||||
? [
|
||||
channelId,
|
||||
effectiveAgentConversationReplyId,
|
||||
targetMessageId ?? "",
|
||||
targetThreadRootId ?? "",
|
||||
].join(":")
|
||||
: null;
|
||||
const [
|
||||
completedTargetAgentConversationBackfillKey,
|
||||
setCompletedTargetAgentConversationBackfillKey,
|
||||
] = React.useState<string | null>(null);
|
||||
const targetAgentConversationBackfillPending = Boolean(
|
||||
targetAgentConversationBackfillKey &&
|
||||
completedTargetAgentConversationBackfillKey !==
|
||||
targetAgentConversationBackfillKey,
|
||||
);
|
||||
|
||||
// Reset spliced target events when the channel context changes (channel
|
||||
// switch or entering/leaving a forum post). Tied to channel identity rather
|
||||
@@ -201,6 +219,7 @@ export function ChannelRouteScreen({
|
||||
!targetThreadRootId) ||
|
||||
selectedPostId
|
||||
) {
|
||||
setCompletedTargetAgentConversationBackfillKey(null);
|
||||
return () => {
|
||||
isCancelled = true;
|
||||
};
|
||||
@@ -233,21 +252,29 @@ export function ChannelRouteScreen({
|
||||
effectiveAgentConversationReplyId ?? targetMessageId,
|
||||
effectiveAgentConversationReplyId,
|
||||
targetThreadRootId,
|
||||
).then((events) => {
|
||||
if (!isCancelled) {
|
||||
queryClient.setQueryData<RelayEvent[]>(
|
||||
channelMessagesKey(channelId),
|
||||
(currentEvents) => mergeRouteEvents(currentEvents, events),
|
||||
);
|
||||
setTargetMessageEvents((currentEvents) => {
|
||||
const eventsById = new Map<string, RelayEvent>();
|
||||
for (const event of [...currentEvents, ...events]) {
|
||||
eventsById.set(event.id, event);
|
||||
}
|
||||
return Array.from(eventsById.values());
|
||||
});
|
||||
}
|
||||
});
|
||||
)
|
||||
.then((events) => {
|
||||
if (!isCancelled) {
|
||||
queryClient.setQueryData<RelayEvent[]>(
|
||||
channelMessagesKey(channelId),
|
||||
(currentEvents) => mergeRouteEvents(currentEvents, events),
|
||||
);
|
||||
setTargetMessageEvents((currentEvents) => {
|
||||
const eventsById = new Map<string, RelayEvent>();
|
||||
for (const event of [...currentEvents, ...events]) {
|
||||
eventsById.set(event.id, event);
|
||||
}
|
||||
return Array.from(eventsById.values());
|
||||
});
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
if (!isCancelled && targetAgentConversationBackfillKey) {
|
||||
setCompletedTargetAgentConversationBackfillKey(
|
||||
targetAgentConversationBackfillKey,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
isCancelled = true;
|
||||
@@ -257,6 +284,7 @@ export function ChannelRouteScreen({
|
||||
channelId,
|
||||
queryClient,
|
||||
effectiveAgentConversationReplyId,
|
||||
targetAgentConversationBackfillKey,
|
||||
targetMessageId,
|
||||
targetThreadRootId,
|
||||
]);
|
||||
@@ -283,6 +311,9 @@ export function ChannelRouteScreen({
|
||||
}}
|
||||
selectedForumPostId={selectedPostId}
|
||||
targetAgentConversationReplyId={effectiveAgentConversationReplyId}
|
||||
targetAgentConversationBackfillPending={
|
||||
targetAgentConversationBackfillPending
|
||||
}
|
||||
targetForumReplyId={targetReplyId}
|
||||
targetMessageEvents={targetMessageEvents}
|
||||
targetMessageId={targetMessageId}
|
||||
|
||||
@@ -88,6 +88,7 @@ export function ChannelScreen({
|
||||
onCloseForumPost,
|
||||
onSelectForumPost,
|
||||
selectedForumPostId,
|
||||
targetAgentConversationBackfillPending = false,
|
||||
targetAgentConversationReplyId,
|
||||
targetForumReplyId,
|
||||
targetMessageEvents,
|
||||
@@ -743,6 +744,7 @@ export function ChannelScreen({
|
||||
goChannel,
|
||||
messageProfilesReady,
|
||||
openAgentConversation,
|
||||
targetBackfillPending: targetAgentConversationBackfillPending,
|
||||
targetAgentConversationReplyId: isChannelTasksEnabled
|
||||
? targetAgentConversationReplyId
|
||||
: null,
|
||||
|
||||
@@ -12,6 +12,7 @@ export type ChannelScreenProps = {
|
||||
onCloseForumPost: () => void;
|
||||
onSelectForumPost: (postId: string) => void;
|
||||
selectedForumPostId: string | null;
|
||||
targetAgentConversationBackfillPending?: boolean;
|
||||
targetAgentConversationReplyId: string | null;
|
||||
targetForumReplyId: string | null;
|
||||
targetMessageEvents: RelayEvent[];
|
||||
|
||||
@@ -31,6 +31,7 @@ type UseAgentConversationRouteTargetInput = {
|
||||
input: OpenAgentConversationInput,
|
||||
options?: { publishMarker?: boolean },
|
||||
) => void;
|
||||
targetBackfillPending: boolean;
|
||||
targetAgentConversationReplyId: string | null;
|
||||
timelineMessages: readonly TimelineMessage[];
|
||||
};
|
||||
@@ -63,6 +64,7 @@ export function useAgentConversationRouteTarget({
|
||||
goChannel,
|
||||
messageProfilesReady,
|
||||
openAgentConversation,
|
||||
targetBackfillPending,
|
||||
targetAgentConversationReplyId,
|
||||
timelineMessages,
|
||||
}: UseAgentConversationRouteTargetInput) {
|
||||
@@ -98,6 +100,9 @@ export function useAgentConversationRouteTarget({
|
||||
if (!sourceMessage) {
|
||||
return;
|
||||
}
|
||||
if (!marker && targetBackfillPending) {
|
||||
return;
|
||||
}
|
||||
if (!marker?.agentPubkey && !agentLookupReady) {
|
||||
return;
|
||||
}
|
||||
@@ -160,6 +165,7 @@ export function useAgentConversationRouteTarget({
|
||||
goChannel,
|
||||
messageProfilesReady,
|
||||
openAgentConversation,
|
||||
targetBackfillPending,
|
||||
targetAgentConversationReplyId,
|
||||
timelineMessages,
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user