From f1ab918ecd3bfe9ac5ceee7e79586645844d9623 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sat, 20 Jul 2019 03:20:06 +0900 Subject: [PATCH] Fix question (#5197) --- src/remote/activitypub/models/note.ts | 4 +--- src/remote/activitypub/models/question.ts | 2 +- src/remote/activitypub/renderer/note.ts | 4 ---- src/remote/activitypub/type.ts | 3 +-- src/server/activitypub.ts | 22 ---------------------- src/services/note/create.ts | 1 - 6 files changed, 3 insertions(+), 33 deletions(-) diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index 14425d7496..31e1ea10e7 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -215,8 +215,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s const apEmojis = emojis.map(emoji => emoji.name); - const questionUri = note._misskey_question; - const poll = await extractPollFromQuestion(note._misskey_question || note, resolver).catch(() => undefined); + const poll = await extractPollFromQuestion(note, resolver).catch(() => undefined); // ユーザーの情報が古かったらついでに更新しておく if (actor.lastFetchedAt == null || Date.now() - actor.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24) { @@ -239,7 +238,6 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s apMentions, apHashtags, apEmojis, - questionUri, poll, uri: note.id }, silent); diff --git a/src/remote/activitypub/models/question.ts b/src/remote/activitypub/models/question.ts index 01086a7cf8..5c889db431 100644 --- a/src/remote/activitypub/models/question.ts +++ b/src/remote/activitypub/models/question.ts @@ -15,7 +15,7 @@ export async function extractPollFromQuestion(source: string | IObject, resolver } const multiple = !question.oneOf; - const expiresAt = question.endTime ? new Date(question.endTime) : null; + const expiresAt = question.endTime ? new Date(question.endTime) : question.closed ? new Date(question.closed) : null; if (multiple && !question.anyOf) { throw new Error('invalid question'); diff --git a/src/remote/activitypub/renderer/note.ts b/src/remote/activitypub/renderer/note.ts index c66af2667b..cbdff7d203 100644 --- a/src/remote/activitypub/renderer/note.ts +++ b/src/remote/activitypub/renderer/note.ts @@ -90,14 +90,11 @@ export default async function renderNote(note: Note, dive = true): Promise poll = await Polls.findOne({ noteId: note.id }); } - let question: string | undefined; if (poll) { if (text == null) text = ''; const url = `${config.url}/notes/${note.id}`; // TODO: i18n text += `\n[リモートで結果を表示](${url})`; - - question = `${config.url}/questions/${note.id}`; } let apText = text; @@ -156,7 +153,6 @@ export default async function renderNote(note: Note, dive = true): Promise content, _misskey_content: text, _misskey_quote: quote, - _misskey_question: question, published: note.createdAt.toISOString(), to, cc, diff --git a/src/remote/activitypub/type.ts b/src/remote/activitypub/type.ts index 66163d39b0..bc9d14190a 100644 --- a/src/remote/activitypub/type.ts +++ b/src/remote/activitypub/type.ts @@ -74,17 +74,16 @@ export interface INote extends IObject { type: 'Note' | 'Question' | 'Article' | 'Audio' | 'Document' | 'Image' | 'Page' | 'Video'; _misskey_content?: string; _misskey_quote?: string; - _misskey_question?: string; } export interface IQuestion extends IObject { type: 'Note' | 'Question'; _misskey_content?: string; _misskey_quote?: string; - _misskey_question?: string; oneOf?: IQuestionChoice[]; anyOf?: IQuestionChoice[]; endTime?: Date; + closed?: Date; } export const isQuestion = (object: IObject): object is IQuestion => diff --git a/src/server/activitypub.ts b/src/server/activitypub.ts index 12fccbfa7d..0f1373d78f 100644 --- a/src/server/activitypub.ts +++ b/src/server/activitypub.ts @@ -109,28 +109,6 @@ router.get('/notes/:note/activity', async ctx => { setResponseType(ctx); }); -// question -router.get('/questions/:question', async (ctx, next) => { - const pollNote = await Notes.findOne({ - id: ctx.params.question, - userHost: null, - visibility: In(['public', 'home']), - localOnly: false, - hasPoll: true - }); - - if (pollNote == null) { - ctx.status = 404; - return; - } - - const user = await Users.findOne(pollNote.userId).then(ensure); - const poll = await Polls.findOne({ noteId: pollNote.id }).then(ensure); - - ctx.body = renderActivity(await renderQuestion(user as ILocalUser, pollNote, poll)); - setResponseType(ctx); -}); - // outbox router.get('/users/:user/outbox', Outbox); diff --git a/src/services/note/create.ts b/src/services/note/create.ts index dd47632caa..c38eb1898e 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -100,7 +100,6 @@ type Option = { apMentions?: User[] | null; apHashtags?: string[] | null; apEmojis?: string[] | null; - questionUri?: string | null; uri?: string | null; app?: App | null; };