diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-11-15 13:19:21 -0600 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-11-15 13:19:21 -0600 |
commit | 9a6df95adecaf3935fdbd58d893fca6489a040b9 (patch) | |
tree | 55715a9903d276315279be837af5ecabaa98fe41 /src/state/models/post-thread-view.ts | |
parent | 60c72087ff0bc13453d2a1602b92b41baf1c2a6a (diff) | |
download | voidsky-9a6df95adecaf3935fdbd58d893fca6489a040b9.tar.zst |
Switch to using setVote()
Diffstat (limited to 'src/state/models/post-thread-view.ts')
-rw-r--r-- | src/state/models/post-thread-view.ts | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/src/state/models/post-thread-view.ts b/src/state/models/post-thread-view.ts index 385aa2e8e..3d9f56ae3 100644 --- a/src/state/models/post-thread-view.ts +++ b/src/state/models/post-thread-view.ts @@ -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() { const wasntUpvoted = !this.myState.upvote - await this._clearVotes() - if (wasntUpvoted) { - const res = await apilib.upvote(this.rootStore, this.uri, this.cid) - runInAction(() => { + const res = await this.rootStore.api.app.bsky.feed.setVote({ + subject: { + uri: this.uri, + cid: this.cid, + }, + direction: wasntUpvoted ? 'up' : 'none', + }) + runInAction(() => { + if (wasntUpvoted) { this.upvoteCount++ - this.myState.upvote = res.uri - }) - } + } else { + this.upvoteCount-- + } + this.myState.upvote = res.data.upvote + this.myState.downvote = res.data.downvote + }) } async toggleDownvote() { const wasntDownvoted = !this.myState.downvote - await this._clearVotes() - if (wasntDownvoted) { - const res = await apilib.downvote(this.rootStore, this.uri, this.cid) - runInAction(() => { + const res = await this.rootStore.api.app.bsky.feed.setVote({ + subject: { + uri: this.uri, + cid: this.cid, + }, + direction: wasntDownvoted ? 'down' : 'none', + }) + runInAction(() => { + if (wasntDownvoted) { this.downvoteCount++ - this.myState.downvote = res.uri - }) - } + } else { + this.downvoteCount-- + } + this.myState.upvote = res.data.upvote + this.myState.downvote = res.data.downvote + }) } async toggleRepost() { |