From b246f2da781b16b7deb5cc8be5c50dc99ef26603 Mon Sep 17 00:00:00 2001 From: Timothy Cardoza Date: Thu, 19 Mar 2026 18:39:35 -0500 Subject: [PATCH] true bucket sharing handling --- src/store/index.ts | 56 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/src/store/index.ts b/src/store/index.ts index a0fd7fa..c7a8619 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -648,8 +648,22 @@ export const matchesFilter = (task: Task) => { ) || bucketRefs.some(context => context.id === (ctx as { bucketId: string }).bucketId); if (!inCurrentBucket) return false; } else { - if (hasHandoffBucket) return false; - if (task.ownerId !== (ctx as { userId: string }).userId) return false; + const targetUserId = (ctx as { userId: string }).userId; + const targetPersonalContext = getPersonalContext(targetUserId); + const inTargetPersonalContext = !!targetPersonalContext && task.shareRefs.some(ref => + ref.kind === "user" && + ( + ref.contextId === targetPersonalContext.id || + ref.key === targetPersonalContext.key || + normalizeContextKey(targetPersonalContext.displayName) === ref.key + ) + ); + + if (targetPersonalContext) { + if (!inTargetPersonalContext) return false; + } else if (task.ownerId !== targetUserId) { + return false; + } } if (isPersonalView && inAnyBucket && !inPinnedBucket && task.ownerId !== currentUserId) return false; @@ -2050,20 +2064,24 @@ const checkForHandoffs = (task: Task, updates: Partial): Partial => if (!currentUserId || task.ownerId !== currentUserId) return updates; const refs = updates.shareRefs || task.shareRefs; + const senderPersonalContext = getPersonalContext(currentUserId); + const stripSenderPersonalContext = (inputRefs: TaskShareRef[]) => + senderPersonalContext + ? inputRefs.filter(existingRef => !( + existingRef.kind === "user" && + (existingRef.contextId === senderPersonalContext.id || existingRef.key === senderPersonalContext.key) + )) + : inputRefs; + for (const ref of refs) { const context = getContextByRef(ref); if (!context || context.policy !== "handoff") continue; + const nextShareRefs = stripSenderPersonalContext(refs); + const labelTags = updates.labelTags || task.labelTags; + const noteRefs = updates.noteRefs || task.noteRefs; + const favoriteTag = (updates.tags || task.tags || []).find(tag => tag.endsWith("_favorite__")); + if (context.kind === "user" && context.targetUserId) { - const senderPersonalContext = getPersonalContext(currentUserId); - const nextShareRefs = senderPersonalContext - ? refs.filter(existingRef => !( - existingRef.kind === "user" && - (existingRef.contextId === senderPersonalContext.id || existingRef.key === senderPersonalContext.key) - )) - : refs; - const labelTags = updates.labelTags || task.labelTags; - const noteRefs = updates.noteRefs || task.noteRefs; - const favoriteTag = (updates.tags || task.tags || []).find(tag => tag.endsWith("_favorite__")); return { ...updates, ownerId: context.targetUserId, @@ -2071,6 +2089,14 @@ const checkForHandoffs = (task: Task, updates: Partial): Partial => tags: buildTaskTags(labelTags, nextShareRefs, noteRefs, favoriteTag) }; } + + if (context.kind === "bucket") { + return { + ...updates, + shareRefs: nextShareRefs, + tags: buildTaskTags(labelTags, nextShareRefs, noteRefs, favoriteTag) + }; + } } return updates; @@ -2689,8 +2715,12 @@ export const loadTasksForOwner = async (userId: string) => { if (!pb.authStore.isValid || !userId) return; try { + const targetPersonalContext = getPersonalContext(userId); + const filter = targetPersonalContext + ? `tags ~ "${buildShareTag(targetPersonalContext.displayName)}"` + : relationFilter("user", userId); const records = await pb.collection(TASGRID_COLLECTION).getFullList({ - filter: relationFilter("user", userId), + filter, sort: '-created', fields: LIST_FIELDS, requestKey: `owner-context-${userId}`