diff --git a/packages/frontpage/lib/api/comment.ts b/packages/frontpage/lib/api/comment.ts index 09530ae..adb259b 100644 --- a/packages/frontpage/lib/api/comment.ts +++ b/packages/frontpage/lib/api/comment.ts @@ -38,6 +38,7 @@ export async function createComment({ parent, post, content, + rkey, }); invariant(cid, "Failed to create comment, rkey/cid missing"); diff --git a/packages/frontpage/lib/api/post.ts b/packages/frontpage/lib/api/post.ts index 35d6e1a..8335359 100644 --- a/packages/frontpage/lib/api/post.ts +++ b/packages/frontpage/lib/api/post.ts @@ -32,6 +32,7 @@ export async function createPost({ const { cid } = await atproto.createPost({ title: title, url: url, + rkey, }); invariant(cid, "Failed to create comment, rkey/cid missing"); diff --git a/packages/frontpage/lib/api/relayHandler.ts b/packages/frontpage/lib/api/relayHandler.ts index 2b0da11..bbcd4a3 100644 --- a/packages/frontpage/lib/api/relayHandler.ts +++ b/packages/frontpage/lib/api/relayHandler.ts @@ -143,7 +143,7 @@ export async function handleVote({ op, repo, rkey }: HandlerInput) { switch (hydratedRecord.subject.uri.collection) { case atprotoPost.PostCollection: - const postVote = await dbVote.uncached_doesCommentVoteExist(repo, rkey); + const postVote = await dbVote.uncached_doesPostVoteExist(repo, rkey); if (!postVote) { const createdDbPostVote = await dbVote.createPostVote({ repo, diff --git a/packages/frontpage/lib/api/vote.ts b/packages/frontpage/lib/api/vote.ts index daedb24..d3d402a 100644 --- a/packages/frontpage/lib/api/vote.ts +++ b/packages/frontpage/lib/api/vote.ts @@ -47,6 +47,7 @@ export async function createVote({ } const { cid } = await atproto.createVote({ + rkey, subjectRkey, subjectCid, subjectCollection, @@ -70,7 +71,7 @@ export async function deleteVote({ rkey }: db.DeleteVoteInput) { const user = await ensureUser(); try { - // await db.deleteVote({ authorDid: user.did, rkey }); + await db.deleteVote({ authorDid: user.did, rkey }); await atproto.deleteVote(user.did, rkey); } catch (e) { diff --git a/packages/frontpage/lib/data/atproto/comment.ts b/packages/frontpage/lib/data/atproto/comment.ts index 09d80d4..1bfa8e1 100644 --- a/packages/frontpage/lib/data/atproto/comment.ts +++ b/packages/frontpage/lib/data/atproto/comment.ts @@ -34,9 +34,15 @@ export type CommentInput = { parent?: { cid: string; rkey: string; authorDid: DID }; post: { cid: string; rkey: string; authorDid: DID }; content: string; + rkey: string; }; -export async function createComment({ parent, post, content }: CommentInput) { +export async function createComment({ + parent, + post, + content, + rkey, +}: CommentInput) { // Collapse newlines into a single \n\n and trim whitespace const sanitizedContent = content.replace(/\n\n+/g, "\n\n").trim(); const record = { @@ -64,6 +70,7 @@ export async function createComment({ parent, post, content }: CommentInput) { const result = await atprotoCreateRecord({ record, collection: CommentCollection, + rkey, }); return { diff --git a/packages/frontpage/lib/data/atproto/post.ts b/packages/frontpage/lib/data/atproto/post.ts index 6b8c76c..3a79028 100644 --- a/packages/frontpage/lib/data/atproto/post.ts +++ b/packages/frontpage/lib/data/atproto/post.ts @@ -22,9 +22,10 @@ export type Post = z.infer; export type PostInput = { title: string; url: string; + rkey: string; }; -export async function createPost({ title, url }: PostInput) { +export async function createPost({ title, url, rkey }: PostInput) { const record = { title, url, createdAt: new Date().toISOString() }; const parseResult = PostRecord.safeParse(record); if (!parseResult.success) { @@ -36,6 +37,7 @@ export async function createPost({ title, url }: PostInput) { const result = await atprotoCreateRecord({ record, collection: PostCollection, + rkey, }); return { diff --git a/packages/frontpage/lib/data/atproto/record.ts b/packages/frontpage/lib/data/atproto/record.ts index df9569a..26667fb 100644 --- a/packages/frontpage/lib/data/atproto/record.ts +++ b/packages/frontpage/lib/data/atproto/record.ts @@ -14,11 +14,13 @@ const CreateRecordResponse = z.object({ type CreateRecordInput = { record: unknown; collection: string; + rkey: string; }; export async function atprotoCreateRecord({ record, collection, + rkey, }: CreateRecordInput) { const user = await ensureUser(); const pdsUrl = new URL(user.pdsUrl); @@ -32,6 +34,7 @@ export async function atprotoCreateRecord({ body: JSON.stringify({ repo: user.did, collection, + rkey, validate: false, record: record, }), diff --git a/packages/frontpage/lib/data/atproto/vote.ts b/packages/frontpage/lib/data/atproto/vote.ts index 30e77e5..68027a6 100644 --- a/packages/frontpage/lib/data/atproto/vote.ts +++ b/packages/frontpage/lib/data/atproto/vote.ts @@ -33,9 +33,11 @@ export type VoteInput = { subjectCid: string; subjectCollection: string; subjectAuthorDid: DID; + rkey: string; }; export async function createVote({ + rkey, subjectRkey, subjectCid, subjectCollection, @@ -61,6 +63,7 @@ export async function createVote({ const response = await atprotoCreateRecord({ collection: VoteCollection, record: record, + rkey, }); return {