Scope folder realtime refreshes by device
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
export interface RealtimeRefreshScope {
|
||||
projectId?: string;
|
||||
projectIds?: string[];
|
||||
deviceId?: string;
|
||||
deviceIds?: string[];
|
||||
conversationUpdatedNotes?: string[];
|
||||
}
|
||||
|
||||
@@ -16,6 +18,7 @@ export type RefreshThrottleDecision =
|
||||
|
||||
interface RealtimeEventPayload {
|
||||
projectId?: string;
|
||||
deviceId?: string;
|
||||
note?: string;
|
||||
}
|
||||
|
||||
@@ -44,16 +47,35 @@ export function shouldRefreshRealtimeEvent(input: {
|
||||
.filter((value): value is string => Boolean(value?.trim()))
|
||||
.map((value) => value.trim()),
|
||||
);
|
||||
const deviceScopeIds = new Set(
|
||||
[input.deviceId, ...(input.deviceIds ?? [])]
|
||||
.filter((value): value is string => Boolean(value?.trim()))
|
||||
.map((value) => value.trim()),
|
||||
);
|
||||
let matchedScopedIdentifier = false;
|
||||
|
||||
if (projectScopeIds.size > 0) {
|
||||
if (!payload || typeof payload.projectId !== "string" || !payload.projectId.trim()) {
|
||||
return true;
|
||||
if (payload && typeof payload.projectId === "string" && payload.projectId.trim()) {
|
||||
if (!projectScopeIds.has(payload.projectId.trim())) {
|
||||
return false;
|
||||
}
|
||||
matchedScopedIdentifier = true;
|
||||
}
|
||||
if (!projectScopeIds.has(payload.projectId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (deviceScopeIds.size > 0) {
|
||||
if (payload && typeof payload.deviceId === "string" && payload.deviceId.trim()) {
|
||||
if (!deviceScopeIds.has(payload.deviceId.trim())) {
|
||||
return false;
|
||||
}
|
||||
matchedScopedIdentifier = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((projectScopeIds.size > 0 || deviceScopeIds.size > 0) && !matchedScopedIdentifier) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (input.eventType === "conversation.updated" && input.conversationUpdatedNotes?.length) {
|
||||
if (!payload || typeof payload.note !== "string" || !payload.note.trim()) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user