From 1fbc4cf1f2279cf4cf6804ff02616515e82d2a38 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 8 Nov 2022 12:14:51 -0600 Subject: Finish the upvote/downvote implementation --- src/state/lib/api.ts | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'src/state/lib/api.ts') diff --git a/src/state/lib/api.ts b/src/state/lib/api.ts index 3d2d26a56..efaac5c7b 100644 --- a/src/state/lib/api.ts +++ b/src/state/lib/api.ts @@ -50,21 +50,45 @@ export async function post( ) } -export async function like(store: RootStoreModel, uri: string, cid: string) { - return await store.api.app.bsky.feed.like.create( +export async function upvote(store: RootStoreModel, uri: string, cid: string) { + return await store.api.app.bsky.feed.vote.create( {did: store.me.did || ''}, { subject: {uri, cid}, + direction: 'up', createdAt: new Date().toISOString(), }, ) } -export async function unlike(store: RootStoreModel, likeUri: string) { - const likeUrip = new AtUri(likeUri) - return await store.api.app.bsky.feed.like.delete({ - did: likeUrip.hostname, - rkey: likeUrip.rkey, +export async function unupvote(store: RootStoreModel, upvoteUri: string) { + const urip = new AtUri(upvoteUri) + return await store.api.app.bsky.feed.vote.delete({ + did: urip.hostname, + rkey: urip.rkey, + }) +} + +export async function downvote( + store: RootStoreModel, + uri: string, + cid: string, +) { + return await store.api.app.bsky.feed.vote.create( + {did: store.me.did || ''}, + { + subject: {uri, cid}, + direction: 'down', + createdAt: new Date().toISOString(), + }, + ) +} + +export async function undownvote(store: RootStoreModel, downvoteUri: string) { + const urip = new AtUri(downvoteUri) + return await store.api.app.bsky.feed.vote.delete({ + did: urip.hostname, + rkey: urip.rkey, }) } -- cgit 1.4.1