fix: use piefed post poll my_votes

This commit is contained in:
Xylight committed 2025-11-17 07:58:01 -08:00
1 parent dbe05459cd
commit 9945ef64cb
4 files changed
+21 -19

No files matched your search

+1 -1
View File
@@ -5888,7 +5888,7 @@ export interface components {
}
PollVoteRequest: {
post_id: number
choice_id: number
choice_id: number[]
}
PollVoteResponse: {
banned_from_community: boolean
+2 -1
View File
@@ -2432,6 +2432,7 @@ export interface PostPoll {
local_only: boolean
latest_vote?: string
choices: PollChoice[]
my_votes?: number[]
}
export interface PollChoice {
@@ -2463,7 +2464,7 @@ export interface PostEvent {
export interface PollVote {
post_id: number
choice_id: number
choice_id: number[]
}
export interface SetNote {
+7 -3
View File
@@ -1,4 +1,4 @@
import { t } from "./i18n"
import { t } from './i18n'
// eslint-disable-next-line
export function errorMessage(error: any, instance?: string): string {
@@ -6,13 +6,17 @@ export function errorMessage(error: any, instance?: string): string {
if (typeof error == 'string') {
try {
error = JSON.parse(error)
} catch {
} catch {
/* try without catch would be cool imo */
}
}
if (error?.body?.message) {
error = JSON.parse(error?.body?.message).error
error = JSON.parse(error?.body?.message)
if (error?.message) {
// probably piefed weird error format
error = error.message
}
} else if (error?.message) {
error = error?.message
} else if (error?.error && typeof error?.error === 'string') {
+11 -14
View File
@@ -19,13 +19,18 @@
let { post }: Props = $props()
let selected = $state<number | number[]>()
let selected = $state<number | number[] | undefined>(
post.poll.my_votes?.length == 1
? post.poll.my_votes[0]
: post.poll.my_votes,
)
let canVote = $state<boolean>(
!(
(post.poll.end_poll &&
publishedToDate(post.poll.end_poll).getTime() < Date.now()) ||
!profile.current.jwt
!profile.current.jwt ||
(post.poll.my_votes?.length ?? 0) > 0
),
)
let chosen = $state<number | undefined>(canVote ? undefined : -1)
@@ -53,18 +58,10 @@
canVote = false
if (typeof id !== 'number') {
await Promise.all([
id.map((i) =>
api
.voteOnPoll({
post_id: post.id,
choice_id: i,
})
.catch((err) => {
throw err
}),
),
])
await api.voteOnPoll({
post_id: post.id,
choice_id: id,
})
} else {
await api.voteOnPoll({
post_id: post.id,