Poll refreshing
Some checks failed
Lint / pnpm_install (pull_request) Successful in 4m10s
Test (backend) / unit (22.x) (pull_request) Successful in 9m48s
Test (frontend) / vitest (22.x) (pull_request) Successful in 5m16s
Test (backend) / e2e (22.x) (pull_request) Successful in 10m42s
Test (production install and build) / production (22.x) (pull_request) Successful in 4m36s
Test (backend) / validate-api-json (22.x) (pull_request) Successful in 5m6s
Lint / lint (backend) (pull_request) Failing after 2m40s
Lint / lint (frontend) (pull_request) Failing after 9m38s
Lint / lint (sw) (pull_request) Successful in 2m50s
Lint / typecheck (backend) (pull_request) Successful in 3m44s
Lint / lint (misskey-js) (pull_request) Successful in 18m27s
Lint / typecheck (misskey-js) (pull_request) Successful in 2m48s
Some checks failed
Lint / pnpm_install (pull_request) Successful in 4m10s
Test (backend) / unit (22.x) (pull_request) Successful in 9m48s
Test (frontend) / vitest (22.x) (pull_request) Successful in 5m16s
Test (backend) / e2e (22.x) (pull_request) Successful in 10m42s
Test (production install and build) / production (22.x) (pull_request) Successful in 4m36s
Test (backend) / validate-api-json (22.x) (pull_request) Successful in 5m6s
Lint / lint (backend) (pull_request) Failing after 2m40s
Lint / lint (frontend) (pull_request) Failing after 9m38s
Lint / lint (sw) (pull_request) Successful in 2m50s
Lint / typecheck (backend) (pull_request) Successful in 3m44s
Lint / lint (misskey-js) (pull_request) Successful in 18m27s
Lint / typecheck (misskey-js) (pull_request) Successful in 2m48s
This commit is contained in:
parent
9dbb4124da
commit
b5be382e97
7 changed files with 130 additions and 4 deletions
2
locales/index.d.ts
vendored
2
locales/index.d.ts
vendored
|
@ -6843,7 +6843,7 @@ export interface Locale extends ILocale {
|
||||||
};
|
};
|
||||||
"_tutorialCompleted": {
|
"_tutorialCompleted": {
|
||||||
/**
|
/**
|
||||||
* Misskey初心者講座 修了証
|
* Forkey初心者講座 修了証
|
||||||
*/
|
*/
|
||||||
"title": string;
|
"title": string;
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -298,6 +298,7 @@ import * as ep___notes_localTimeline from './endpoints/notes/local-timeline.js';
|
||||||
import * as ep___notes_mentions from './endpoints/notes/mentions.js';
|
import * as ep___notes_mentions from './endpoints/notes/mentions.js';
|
||||||
import * as ep___notes_polls_recommendation from './endpoints/notes/polls/recommendation.js';
|
import * as ep___notes_polls_recommendation from './endpoints/notes/polls/recommendation.js';
|
||||||
import * as ep___notes_polls_vote from './endpoints/notes/polls/vote.js';
|
import * as ep___notes_polls_vote from './endpoints/notes/polls/vote.js';
|
||||||
|
import * as ep___notes_polls_refresh from './endpoints/notes/polls/refresh.js';
|
||||||
import * as ep___notes_reactions from './endpoints/notes/reactions.js';
|
import * as ep___notes_reactions from './endpoints/notes/reactions.js';
|
||||||
import * as ep___notes_reactions_create from './endpoints/notes/reactions/create.js';
|
import * as ep___notes_reactions_create from './endpoints/notes/reactions/create.js';
|
||||||
import * as ep___notes_reactions_delete from './endpoints/notes/reactions/delete.js';
|
import * as ep___notes_reactions_delete from './endpoints/notes/reactions/delete.js';
|
||||||
|
@ -695,6 +696,7 @@ const $notes_localTimeline: Provider = { provide: 'ep:notes/local-timeline', use
|
||||||
const $notes_mentions: Provider = { provide: 'ep:notes/mentions', useClass: ep___notes_mentions.default };
|
const $notes_mentions: Provider = { provide: 'ep:notes/mentions', useClass: ep___notes_mentions.default };
|
||||||
const $notes_polls_recommendation: Provider = { provide: 'ep:notes/polls/recommendation', useClass: ep___notes_polls_recommendation.default };
|
const $notes_polls_recommendation: Provider = { provide: 'ep:notes/polls/recommendation', useClass: ep___notes_polls_recommendation.default };
|
||||||
const $notes_polls_vote: Provider = { provide: 'ep:notes/polls/vote', useClass: ep___notes_polls_vote.default };
|
const $notes_polls_vote: Provider = { provide: 'ep:notes/polls/vote', useClass: ep___notes_polls_vote.default };
|
||||||
|
const $notes_polls_refresh: Provider = { provide: 'ep:notes/polls/refresh', useClass: ep___notes_polls_refresh.default };
|
||||||
const $notes_reactions: Provider = { provide: 'ep:notes/reactions', useClass: ep___notes_reactions.default };
|
const $notes_reactions: Provider = { provide: 'ep:notes/reactions', useClass: ep___notes_reactions.default };
|
||||||
const $notes_reactions_create: Provider = { provide: 'ep:notes/reactions/create', useClass: ep___notes_reactions_create.default };
|
const $notes_reactions_create: Provider = { provide: 'ep:notes/reactions/create', useClass: ep___notes_reactions_create.default };
|
||||||
const $notes_reactions_delete: Provider = { provide: 'ep:notes/reactions/delete', useClass: ep___notes_reactions_delete.default };
|
const $notes_reactions_delete: Provider = { provide: 'ep:notes/reactions/delete', useClass: ep___notes_reactions_delete.default };
|
||||||
|
@ -1096,6 +1098,7 @@ const $reversi_verify: Provider = { provide: 'ep:reversi/verify', useClass: ep__
|
||||||
$notes_mentions,
|
$notes_mentions,
|
||||||
$notes_polls_recommendation,
|
$notes_polls_recommendation,
|
||||||
$notes_polls_vote,
|
$notes_polls_vote,
|
||||||
|
$notes_polls_refresh,
|
||||||
$notes_reactions,
|
$notes_reactions,
|
||||||
$notes_reactions_create,
|
$notes_reactions_create,
|
||||||
$notes_reactions_delete,
|
$notes_reactions_delete,
|
||||||
|
@ -1490,6 +1493,7 @@ const $reversi_verify: Provider = { provide: 'ep:reversi/verify', useClass: ep__
|
||||||
$notes_mentions,
|
$notes_mentions,
|
||||||
$notes_polls_recommendation,
|
$notes_polls_recommendation,
|
||||||
$notes_polls_vote,
|
$notes_polls_vote,
|
||||||
|
$notes_polls_refresh,
|
||||||
$notes_reactions,
|
$notes_reactions,
|
||||||
$notes_reactions_create,
|
$notes_reactions_create,
|
||||||
$notes_reactions_delete,
|
$notes_reactions_delete,
|
||||||
|
|
|
@ -298,6 +298,7 @@ import * as ep___notes_localTimeline from './endpoints/notes/local-timeline.js';
|
||||||
import * as ep___notes_mentions from './endpoints/notes/mentions.js';
|
import * as ep___notes_mentions from './endpoints/notes/mentions.js';
|
||||||
import * as ep___notes_polls_recommendation from './endpoints/notes/polls/recommendation.js';
|
import * as ep___notes_polls_recommendation from './endpoints/notes/polls/recommendation.js';
|
||||||
import * as ep___notes_polls_vote from './endpoints/notes/polls/vote.js';
|
import * as ep___notes_polls_vote from './endpoints/notes/polls/vote.js';
|
||||||
|
import * as ep___notes_polls_refresh from './endpoints/notes/polls/refresh.js';
|
||||||
import * as ep___notes_reactions from './endpoints/notes/reactions.js';
|
import * as ep___notes_reactions from './endpoints/notes/reactions.js';
|
||||||
import * as ep___notes_reactions_create from './endpoints/notes/reactions/create.js';
|
import * as ep___notes_reactions_create from './endpoints/notes/reactions/create.js';
|
||||||
import * as ep___notes_reactions_delete from './endpoints/notes/reactions/delete.js';
|
import * as ep___notes_reactions_delete from './endpoints/notes/reactions/delete.js';
|
||||||
|
@ -693,6 +694,7 @@ const eps = [
|
||||||
['notes/mentions', ep___notes_mentions],
|
['notes/mentions', ep___notes_mentions],
|
||||||
['notes/polls/recommendation', ep___notes_polls_recommendation],
|
['notes/polls/recommendation', ep___notes_polls_recommendation],
|
||||||
['notes/polls/vote', ep___notes_polls_vote],
|
['notes/polls/vote', ep___notes_polls_vote],
|
||||||
|
['notes/polls/refresh', ep___notes_polls_refresh],
|
||||||
['notes/reactions', ep___notes_reactions],
|
['notes/reactions', ep___notes_reactions],
|
||||||
['notes/reactions/create', ep___notes_reactions_create],
|
['notes/reactions/create', ep___notes_reactions_create],
|
||||||
['notes/reactions/delete', ep___notes_reactions_delete],
|
['notes/reactions/delete', ep___notes_reactions_delete],
|
||||||
|
|
105
packages/backend/src/server/api/endpoints/notes/polls/refresh.ts
Normal file
105
packages/backend/src/server/api/endpoints/notes/polls/refresh.ts
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: marie and sharkey-project
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||||
|
import { GetterService } from '@/server/api/GetterService.js';
|
||||||
|
import { UserBlockingService } from '@/core/UserBlockingService.js';
|
||||||
|
import { ApQuestionService } from '@/core/activitypub/models/ApQuestionService.js';
|
||||||
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
||||||
|
import { ApiError } from '../../../error.js';
|
||||||
|
|
||||||
|
export const meta = {
|
||||||
|
tags: ['notes'],
|
||||||
|
|
||||||
|
requireCredential: true,
|
||||||
|
|
||||||
|
prohibitMoved: true,
|
||||||
|
|
||||||
|
kind: 'read:federation',
|
||||||
|
|
||||||
|
errors: {
|
||||||
|
noSuchNote: {
|
||||||
|
message: 'No such note.',
|
||||||
|
code: 'NO_SUCH_NOTE',
|
||||||
|
id: 'ecafbd2e-c283-4d6d-aecb-1a0a33b75396',
|
||||||
|
},
|
||||||
|
|
||||||
|
noPoll: {
|
||||||
|
message: 'The note does not attach a poll.',
|
||||||
|
code: 'NO_POLL',
|
||||||
|
id: '5f979967-52d9-4314-a911-1c673727f92f',
|
||||||
|
},
|
||||||
|
|
||||||
|
noUri: {
|
||||||
|
message: 'The note has no URI defined.',
|
||||||
|
code: 'INVALID_URI',
|
||||||
|
id: 'e0cc9a04-f2e8-41e4-a5f1-4127293260ca',
|
||||||
|
},
|
||||||
|
|
||||||
|
youHaveBeenBlocked: {
|
||||||
|
message: 'You cannot refresh this poll because you have been blocked by this user.',
|
||||||
|
code: 'YOU_HAVE_BEEN_BLOCKED',
|
||||||
|
id: '85a5377e-b1e9-4617-b0b9-5bea73331e49',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// 2 calls per second
|
||||||
|
limit: {
|
||||||
|
duration: 1000,
|
||||||
|
max: 2,
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export const paramDef = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
noteId: { type: 'string', format: 'misskey:id' },
|
||||||
|
},
|
||||||
|
required: ['noteId'],
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
// TODO: ロジックをサービスに切り出す
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
||||||
|
constructor(
|
||||||
|
private getterService: GetterService,
|
||||||
|
private userBlockingService: UserBlockingService,
|
||||||
|
private apQuestionService: ApQuestionService,
|
||||||
|
private noteEntityService: NoteEntityService,
|
||||||
|
) {
|
||||||
|
super(meta, paramDef, async (ps, me) => {
|
||||||
|
// Get note
|
||||||
|
const note = await this.getterService.getNote(ps.noteId).catch(err => {
|
||||||
|
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
if (!note.hasPoll) {
|
||||||
|
throw new ApiError(meta.errors.noPoll);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check blocking
|
||||||
|
if (note.userId !== me.id) {
|
||||||
|
const blocked = await this.userBlockingService.checkBlocked(note.userId, me.id);
|
||||||
|
if (blocked) {
|
||||||
|
throw new ApiError(meta.errors.youHaveBeenBlocked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!note.uri) {
|
||||||
|
throw new ApiError(meta.errors.noUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.apQuestionService.updateQuestion(note.uri);
|
||||||
|
|
||||||
|
return await this.noteEntityService.pack(note, me, {
|
||||||
|
detail: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -81,7 +81,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<div v-if="appearNote.files && appearNote.files.length > 0">
|
<div v-if="appearNote.files && appearNote.files.length > 0">
|
||||||
<MkMediaList :mediaList="appearNote.files" :user="appearNote.user"/>
|
<MkMediaList :mediaList="appearNote.files" :user="appearNote.user"/>
|
||||||
</div>
|
</div>
|
||||||
<MkPoll v-if="appearNote.poll" :noteId="appearNote.id" :poll="appearNote.poll" :class="$style.poll"/>
|
<MkPoll v-if="appearNote.poll" :noteId="appearNote.id" :poll="appearNote.poll" :local="!appearNote.user.host" :class="$style.poll" @click.stop/>
|
||||||
<div v-if="isEnabledUrlPreview">
|
<div v-if="isEnabledUrlPreview">
|
||||||
<MkUrlPreview v-for="url in urls" :key="url" :url="url" :compact="true" :detail="false" :class="$style.urlPreview"/>
|
<MkUrlPreview v-for="url in urls" :key="url" :url="url" :compact="true" :detail="false" :class="$style.urlPreview"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -94,7 +94,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<div v-if="appearNote.files && appearNote.files.length > 0">
|
<div v-if="appearNote.files && appearNote.files.length > 0">
|
||||||
<MkMediaList :mediaList="appearNote.files" :user="appearNote.user"/>
|
<MkMediaList :mediaList="appearNote.files" :user="appearNote.user"/>
|
||||||
</div>
|
</div>
|
||||||
<MkPoll v-if="appearNote.poll" ref="pollViewer" :noteId="appearNote.id" :poll="appearNote.poll" :class="$style.poll"/>
|
<MkPoll v-if="appearNote.poll" ref="pollViewer" :noteId="appearNote.id" :poll="appearNote.poll" :local="!appearNote.user.host" :class="$style.poll"/>
|
||||||
<div v-if="isEnabledUrlPreview">
|
<div v-if="isEnabledUrlPreview">
|
||||||
<MkUrlPreview v-for="url in urls" :key="url" :url="url" :compact="true" :detail="true" style="margin-top: 6px;"/>
|
<MkUrlPreview v-for="url in urls" :key="url" :url="url" :compact="true" :detail="true" style="margin-top: 6px;"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<template>
|
<template>
|
||||||
<div :class="{ [$style.done]: closed || isVoted }">
|
<div :class="{ [$style.done]: closed || isVoted }">
|
||||||
<ul :class="$style.choices">
|
<ul :class="$style.choices">
|
||||||
<li v-for="(choice, i) in poll.choices" :key="i" :class="$style.choice" @click="vote(i)">
|
<li v-for="(choice, i) in props.poll.choices" :key="i" :class="$style.choice" @click="vote(i)">
|
||||||
<div :class="$style.bg" :style="{ 'width': `${showResult ? (choice.votes / total * 100) : 0}%` }"></div>
|
<div :class="$style.bg" :style="{ 'width': `${showResult ? (choice.votes / total * 100) : 0}%` }"></div>
|
||||||
<span :class="$style.fg">
|
<span :class="$style.fg">
|
||||||
<template v-if="choice.isVoted"><i class="ti ti-check" style="margin-right: 4px; color: var(--accent);"></i></template>
|
<template v-if="choice.isVoted"><i class="ti ti-check" style="margin-right: 4px; color: var(--accent);"></i></template>
|
||||||
|
@ -22,6 +22,8 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<span v-if="isVoted">{{ i18n.ts._poll.voted }}</span>
|
<span v-if="isVoted">{{ i18n.ts._poll.voted }}</span>
|
||||||
<span v-else-if="closed">{{ i18n.ts._poll.closed }}</span>
|
<span v-else-if="closed">{{ i18n.ts._poll.closed }}</span>
|
||||||
<span v-if="remaining > 0"> · {{ timer }}</span>
|
<span v-if="remaining > 0"> · {{ timer }}</span>
|
||||||
|
<span v-if="!closed && $i && !props.local"> · </span>
|
||||||
|
<a v-if="!closed && $i && !props.local" style="color: inherit;" @click="refreshVotes()">{{ i18n.ts.reload }}</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -35,11 +37,13 @@ import * as os from '@/os.js';
|
||||||
import { misskeyApi } from '@/scripts/misskey-api.js';
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
import { useInterval } from '@/scripts/use-interval.js';
|
import { useInterval } from '@/scripts/use-interval.js';
|
||||||
|
import { $i } from '@/account.js';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
noteId: string;
|
noteId: string;
|
||||||
poll: NonNullable<Misskey.entities.Note['poll']>;
|
poll: NonNullable<Misskey.entities.Note['poll']>;
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
|
local?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const remaining = ref(-1);
|
const remaining = ref(-1);
|
||||||
|
@ -92,6 +96,17 @@ const vote = async (id) => {
|
||||||
});
|
});
|
||||||
if (!showResult.value) showResult.value = !props.poll.multiple;
|
if (!showResult.value) showResult.value = !props.poll.multiple;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const refreshVotes = async () => {
|
||||||
|
pleaseLogin(undefined, pleaseLoginContext.value);
|
||||||
|
|
||||||
|
if (props.readOnly || closed.value) return;
|
||||||
|
await misskeyApi('notes/polls/refresh', {
|
||||||
|
noteId: props.noteId,
|
||||||
|
// Sadly due to being in the same component and the poll being a prop we require to break Vue's recommendation of not mutating the prop to update it.
|
||||||
|
// eslint-disable-next-line vue/no-mutating-props
|
||||||
|
}).then((res: any) => res.poll ? props.poll.choices = res.poll.choices : null );
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" module>
|
<style lang="scss" module>
|
||||||
|
|
Loading…
Reference in a new issue