a tool for shared writing and social publishing

handle multiple ingests for posts

+25 -13
+25 -13
app/api/inngest/functions/index_post_mention.ts
··· 46 46 ).toString(); 47 47 48 48 await step.run("index-bsky-post", async () => { 49 - await supabaseServerClient.from("bsky_posts").insert({ 49 + await supabaseServerClient.from("bsky_posts").upsert({ 50 50 uri: bsky_post.uri, 51 51 cid: bsky_post.cid, 52 52 post_view: bsky_post as Json, 53 53 }); 54 - await supabaseServerClient.from("document_mentions_in_bsky").insert({ 54 + await supabaseServerClient.from("document_mentions_in_bsky").upsert({ 55 55 uri: bsky_post.uri, 56 56 document: documentUri, 57 57 link: event.data.document_link, ··· 61 61 await step.run("create-notification", async () => { 62 62 // Only create notification if the quote is from someone other than the author 63 63 if (bsky_post.author.did !== pub.identity_did) { 64 - const notification: Notification = { 65 - id: v7(), 66 - recipient: pub.identity_did, 67 - data: { 68 - type: "quote", 69 - bsky_post_uri: bsky_post.uri, 70 - document_uri: documentUri, 71 - }, 72 - }; 73 - await supabaseServerClient.from("notifications").insert(notification); 74 - await pingIdentityToUpdateNotification(pub.identity_did); 64 + // Check if a notification already exists for this post and recipient 65 + const { data: existingNotification } = await supabaseServerClient 66 + .from("notifications") 67 + .select("id") 68 + .eq("recipient", pub.identity_did) 69 + .eq("data->>type", "quote") 70 + .eq("data->>bsky_post_uri", bsky_post.uri) 71 + .eq("data->>document_uri", documentUri) 72 + .single(); 73 + 74 + if (!existingNotification) { 75 + const notification: Notification = { 76 + id: v7(), 77 + recipient: pub.identity_did, 78 + data: { 79 + type: "quote", 80 + bsky_post_uri: bsky_post.uri, 81 + document_uri: documentUri, 82 + }, 83 + }; 84 + await supabaseServerClient.from("notifications").insert(notification); 85 + await pingIdentityToUpdateNotification(pub.identity_did); 86 + } 75 87 } 76 88 }); 77 89 },