tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
28
pulls
pipelines
handle multiple ingests for posts
awarm.space
3 months ago
0265ad44
632093e6
+25
-13
1 changed file
expand all
collapse all
unified
split
app
api
inngest
functions
index_post_mention.ts
+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
49
-
await supabaseServerClient.from("bsky_posts").insert({
49
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
54
-
await supabaseServerClient.from("document_mentions_in_bsky").insert({
54
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
64
-
const notification: Notification = {
65
65
-
id: v7(),
66
66
-
recipient: pub.identity_did,
67
67
-
data: {
68
68
-
type: "quote",
69
69
-
bsky_post_uri: bsky_post.uri,
70
70
-
document_uri: documentUri,
71
71
-
},
72
72
-
};
73
73
-
await supabaseServerClient.from("notifications").insert(notification);
74
74
-
await pingIdentityToUpdateNotification(pub.identity_did);
64
64
+
// Check if a notification already exists for this post and recipient
65
65
+
const { data: existingNotification } = await supabaseServerClient
66
66
+
.from("notifications")
67
67
+
.select("id")
68
68
+
.eq("recipient", pub.identity_did)
69
69
+
.eq("data->>type", "quote")
70
70
+
.eq("data->>bsky_post_uri", bsky_post.uri)
71
71
+
.eq("data->>document_uri", documentUri)
72
72
+
.single();
73
73
+
74
74
+
if (!existingNotification) {
75
75
+
const notification: Notification = {
76
76
+
id: v7(),
77
77
+
recipient: pub.identity_did,
78
78
+
data: {
79
79
+
type: "quote",
80
80
+
bsky_post_uri: bsky_post.uri,
81
81
+
document_uri: documentUri,
82
82
+
},
83
83
+
};
84
84
+
await supabaseServerClient.from("notifications").insert(notification);
85
85
+
await pingIdentityToUpdateNotification(pub.identity_did);
86
86
+
}
75
87
}
76
88
});
77
89
},