server: endpoint to fetch votes count

Changelog: Added
This commit is contained in:
Johann150 2024-01-03 17:29:46 +01:00
parent 78359daac6
commit 24f6177b94
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
3 changed files with 47 additions and 1 deletions

View file

@ -7,7 +7,7 @@ import { updatePerson } from '@/remote/activitypub/models/person.js';
import { update as updateNote } from '@/remote/activitypub/kernel/update/note.js';
/**
* Updateアクティビティを捌きます
* Handle Update activity
*/
export default async (actor: IRemoteUser, activity: IUpdate, resolver: Resolver): Promise<string> => {
if ('actor' in activity && actor.uri !== activity.actor) {

View file

@ -221,6 +221,7 @@ import * as ep___notes_hybridTimeline from './endpoints/notes/hybrid-timeline.js
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_polls_vote from './endpoints/notes/polls/vote.js';
import * as ep___notes_polls_update from './endpoints/notes/polls/update.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_delete from './endpoints/notes/reactions/delete.js';
@ -515,6 +516,7 @@ const eps = [
['notes/local-timeline', ep___notes_localTimeline],
['notes/mentions', ep___notes_mentions],
['notes/polls/vote', ep___notes_polls_vote],
['notes/polls/update', ep___notes_polls_update],
['notes/reactions', ep___notes_reactions],
['notes/reactions/create', ep___notes_reactions_create],
['notes/reactions/delete', ep___notes_reactions_delete],

View file

@ -0,0 +1,44 @@
import { getNote } from '@/server/api/common/getters.js';
import { ApiError } from '@/server/api/error.js';
import define from '@/server/api/define.js';
import { Resolver } from '@/remote/activitypub/resolver.js';
import { updateQuestion } from '@/remote/activitypub/models/question.js';
export const meta = {
tags: ['notes'],
description: 'Fetches an updated number of votes for a poll attached to a remote note.',
requireCredential: true,
kind: 'write:votes',
errors: ['NO_SUCH_NOTE'],
} as const;
export const paramDef = {
type: 'object',
properties: {
noteId: { type: 'string', format: 'misskey:id' },
},
required: ['noteId'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, user) => {
// Get votee
const note = await getNote(ps.noteId, user).catch(err => {
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError('NO_SUCH_NOTE');
throw err;
});
if (!note.hasPoll) {
throw new ApiError('NO_SUCH_NOTE', 'The note exists but does not have a poll attached.');
}
if (note.uri == null) {
throw new ApiError('NO_SUCH_NOTE', 'Can only update polls of remote notes.');
}
await updateQuestion(note.uri, new Resolver());
});