Switch to using setVote()
parent
60c72087ff
commit
9a6df95ade
|
@ -51,48 +51,6 @@ export async function post(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 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,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function repost(store: RootStoreModel, uri: string, cid: string) {
|
export async function repost(store: RootStoreModel, uri: string, cid: string) {
|
||||||
return await store.api.app.bsky.feed.repost.create(
|
return await store.api.app.bsky.feed.repost.create(
|
||||||
{did: store.me.did || ''},
|
{did: store.me.did || ''},
|
||||||
|
|
|
@ -72,45 +72,44 @@ export class FeedItemModel implements GetTimeline.FeedItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _clearVotes() {
|
|
||||||
if (this.myState.upvote) {
|
|
||||||
await apilib.unupvote(this.rootStore, this.myState.upvote)
|
|
||||||
runInAction(() => {
|
|
||||||
this.upvoteCount--
|
|
||||||
this.myState.upvote = undefined
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if (this.myState.downvote) {
|
|
||||||
await apilib.undownvote(this.rootStore, this.myState.downvote)
|
|
||||||
runInAction(() => {
|
|
||||||
this.downvoteCount--
|
|
||||||
this.myState.downvote = undefined
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async toggleUpvote() {
|
async toggleUpvote() {
|
||||||
const wasntUpvoted = !this.myState.upvote
|
const wasntUpvoted = !this.myState.upvote
|
||||||
await this._clearVotes()
|
const res = await this.rootStore.api.app.bsky.feed.setVote({
|
||||||
if (wasntUpvoted) {
|
subject: {
|
||||||
const res = await apilib.upvote(this.rootStore, this.uri, this.cid)
|
uri: this.uri,
|
||||||
runInAction(() => {
|
cid: this.cid,
|
||||||
this.upvoteCount++
|
},
|
||||||
this.myState.upvote = res.uri
|
direction: wasntUpvoted ? 'up' : 'none',
|
||||||
})
|
})
|
||||||
|
runInAction(() => {
|
||||||
|
if (wasntUpvoted) {
|
||||||
|
this.upvoteCount++
|
||||||
|
} else {
|
||||||
|
this.upvoteCount--
|
||||||
}
|
}
|
||||||
|
this.myState.upvote = res.data.upvote
|
||||||
|
this.myState.downvote = res.data.downvote
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async toggleDownvote() {
|
async toggleDownvote() {
|
||||||
const wasntDownvoted = !this.myState.downvote
|
const wasntDownvoted = !this.myState.downvote
|
||||||
await this._clearVotes()
|
const res = await this.rootStore.api.app.bsky.feed.setVote({
|
||||||
if (wasntDownvoted) {
|
subject: {
|
||||||
const res = await apilib.downvote(this.rootStore, this.uri, this.cid)
|
uri: this.uri,
|
||||||
runInAction(() => {
|
cid: this.cid,
|
||||||
this.downvoteCount++
|
},
|
||||||
this.myState.downvote = res.uri
|
direction: wasntDownvoted ? 'down' : 'none',
|
||||||
})
|
})
|
||||||
|
runInAction(() => {
|
||||||
|
if (wasntDownvoted) {
|
||||||
|
this.downvoteCount++
|
||||||
|
} else {
|
||||||
|
this.downvoteCount--
|
||||||
}
|
}
|
||||||
|
this.myState.upvote = res.data.upvote
|
||||||
|
this.myState.downvote = res.data.downvote
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async toggleRepost() {
|
async toggleRepost() {
|
||||||
|
|
|
@ -112,45 +112,44 @@ export class PostThreadViewPostModel implements GetPostThread.Post {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _clearVotes() {
|
|
||||||
if (this.myState.upvote) {
|
|
||||||
await apilib.unupvote(this.rootStore, this.myState.upvote)
|
|
||||||
runInAction(() => {
|
|
||||||
this.upvoteCount--
|
|
||||||
this.myState.upvote = undefined
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if (this.myState.downvote) {
|
|
||||||
await apilib.undownvote(this.rootStore, this.myState.downvote)
|
|
||||||
runInAction(() => {
|
|
||||||
this.downvoteCount--
|
|
||||||
this.myState.downvote = undefined
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async toggleUpvote() {
|
async toggleUpvote() {
|
||||||
const wasntUpvoted = !this.myState.upvote
|
const wasntUpvoted = !this.myState.upvote
|
||||||
await this._clearVotes()
|
const res = await this.rootStore.api.app.bsky.feed.setVote({
|
||||||
if (wasntUpvoted) {
|
subject: {
|
||||||
const res = await apilib.upvote(this.rootStore, this.uri, this.cid)
|
uri: this.uri,
|
||||||
runInAction(() => {
|
cid: this.cid,
|
||||||
this.upvoteCount++
|
},
|
||||||
this.myState.upvote = res.uri
|
direction: wasntUpvoted ? 'up' : 'none',
|
||||||
})
|
})
|
||||||
|
runInAction(() => {
|
||||||
|
if (wasntUpvoted) {
|
||||||
|
this.upvoteCount++
|
||||||
|
} else {
|
||||||
|
this.upvoteCount--
|
||||||
}
|
}
|
||||||
|
this.myState.upvote = res.data.upvote
|
||||||
|
this.myState.downvote = res.data.downvote
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async toggleDownvote() {
|
async toggleDownvote() {
|
||||||
const wasntDownvoted = !this.myState.downvote
|
const wasntDownvoted = !this.myState.downvote
|
||||||
await this._clearVotes()
|
const res = await this.rootStore.api.app.bsky.feed.setVote({
|
||||||
if (wasntDownvoted) {
|
subject: {
|
||||||
const res = await apilib.downvote(this.rootStore, this.uri, this.cid)
|
uri: this.uri,
|
||||||
runInAction(() => {
|
cid: this.cid,
|
||||||
this.downvoteCount++
|
},
|
||||||
this.myState.downvote = res.uri
|
direction: wasntDownvoted ? 'down' : 'none',
|
||||||
})
|
})
|
||||||
|
runInAction(() => {
|
||||||
|
if (wasntDownvoted) {
|
||||||
|
this.downvoteCount++
|
||||||
|
} else {
|
||||||
|
this.downvoteCount--
|
||||||
}
|
}
|
||||||
|
this.myState.upvote = res.data.upvote
|
||||||
|
this.myState.downvote = res.data.downvote
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async toggleRepost() {
|
async toggleRepost() {
|
||||||
|
|
Loading…
Reference in New Issue