Filter goal refreshes by conversation note
This commit is contained in:
@@ -254,9 +254,11 @@ export function NativeAppBridge() {
|
||||
export function RealtimeRefresh({
|
||||
events,
|
||||
projectId,
|
||||
conversationUpdatedNotes,
|
||||
}: {
|
||||
events: BossEventName[];
|
||||
projectId?: string;
|
||||
conversationUpdatedNotes?: string[];
|
||||
}) {
|
||||
const router = useRouter();
|
||||
|
||||
@@ -268,21 +270,40 @@ export function RealtimeRefresh({
|
||||
...events,
|
||||
]));
|
||||
const shouldRefresh = (event: Event) => {
|
||||
if (!projectId || !("data" in event) || typeof event.data !== "string" || !event.data.trim()) {
|
||||
return true;
|
||||
let payload: { projectId?: string; note?: string } | null = null;
|
||||
const eventData = "data" in event && typeof event.data === "string" ? event.data : "";
|
||||
const hasPayloadData = Boolean(eventData.trim());
|
||||
|
||||
if (hasPayloadData) {
|
||||
try {
|
||||
const parsed = JSON.parse(eventData) as { projectId?: string; note?: string };
|
||||
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
||||
payload = parsed;
|
||||
}
|
||||
} catch {
|
||||
payload = null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
const payload = JSON.parse(event.data) as { projectId?: string };
|
||||
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
||||
|
||||
if (projectId) {
|
||||
if (!payload || typeof payload.projectId !== "string" || !payload.projectId.trim()) {
|
||||
return true;
|
||||
}
|
||||
if (typeof payload.projectId !== "string" || !payload.projectId.trim()) {
|
||||
return true;
|
||||
if (payload.projectId !== projectId) {
|
||||
return false;
|
||||
}
|
||||
return payload.projectId === projectId;
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.type === "conversation.updated" && conversationUpdatedNotes?.length) {
|
||||
if (!payload || typeof payload.note !== "string" || !payload.note.trim()) {
|
||||
return false;
|
||||
}
|
||||
if ((payload.note) && !conversationUpdatedNotes.includes(payload.note)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
const listenerMap = new Map<string, (event: Event) => void>();
|
||||
|
||||
@@ -306,7 +327,7 @@ export function RealtimeRefresh({
|
||||
}
|
||||
source.close();
|
||||
};
|
||||
}, [events, projectId, router]);
|
||||
}, [conversationUpdatedNotes, events, projectId, router]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user