Fix question (#5197)

This commit is contained in:
MeiMei 2019-07-20 03:20:06 +09:00 committed by syuilo
parent 42af8c7695
commit f1ab918ecd
6 changed files with 3 additions and 33 deletions

View file

@ -215,8 +215,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s
const apEmojis = emojis.map(emoji => emoji.name); const apEmojis = emojis.map(emoji => emoji.name);
const questionUri = note._misskey_question; const poll = await extractPollFromQuestion(note, resolver).catch(() => undefined);
const poll = await extractPollFromQuestion(note._misskey_question || note, resolver).catch(() => undefined);
// ユーザーの情報が古かったらついでに更新しておく // ユーザーの情報が古かったらついでに更新しておく
if (actor.lastFetchedAt == null || Date.now() - actor.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24) { 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, apMentions,
apHashtags, apHashtags,
apEmojis, apEmojis,
questionUri,
poll, poll,
uri: note.id uri: note.id
}, silent); }, silent);

View file

@ -15,7 +15,7 @@ export async function extractPollFromQuestion(source: string | IObject, resolver
} }
const multiple = !question.oneOf; 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) { if (multiple && !question.anyOf) {
throw new Error('invalid question'); throw new Error('invalid question');

View file

@ -90,14 +90,11 @@ export default async function renderNote(note: Note, dive = true): Promise<any>
poll = await Polls.findOne({ noteId: note.id }); poll = await Polls.findOne({ noteId: note.id });
} }
let question: string | undefined;
if (poll) { if (poll) {
if (text == null) text = ''; if (text == null) text = '';
const url = `${config.url}/notes/${note.id}`; const url = `${config.url}/notes/${note.id}`;
// TODO: i18n // TODO: i18n
text += `\n[リモートで結果を表示](${url})`; text += `\n[リモートで結果を表示](${url})`;
question = `${config.url}/questions/${note.id}`;
} }
let apText = text; let apText = text;
@ -156,7 +153,6 @@ export default async function renderNote(note: Note, dive = true): Promise<any>
content, content,
_misskey_content: text, _misskey_content: text,
_misskey_quote: quote, _misskey_quote: quote,
_misskey_question: question,
published: note.createdAt.toISOString(), published: note.createdAt.toISOString(),
to, to,
cc, cc,

View file

@ -74,17 +74,16 @@ export interface INote extends IObject {
type: 'Note' | 'Question' | 'Article' | 'Audio' | 'Document' | 'Image' | 'Page' | 'Video'; type: 'Note' | 'Question' | 'Article' | 'Audio' | 'Document' | 'Image' | 'Page' | 'Video';
_misskey_content?: string; _misskey_content?: string;
_misskey_quote?: string; _misskey_quote?: string;
_misskey_question?: string;
} }
export interface IQuestion extends IObject { export interface IQuestion extends IObject {
type: 'Note' | 'Question'; type: 'Note' | 'Question';
_misskey_content?: string; _misskey_content?: string;
_misskey_quote?: string; _misskey_quote?: string;
_misskey_question?: string;
oneOf?: IQuestionChoice[]; oneOf?: IQuestionChoice[];
anyOf?: IQuestionChoice[]; anyOf?: IQuestionChoice[];
endTime?: Date; endTime?: Date;
closed?: Date;
} }
export const isQuestion = (object: IObject): object is IQuestion => export const isQuestion = (object: IObject): object is IQuestion =>

View file

@ -109,28 +109,6 @@ router.get('/notes/:note/activity', async ctx => {
setResponseType(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 // outbox
router.get('/users/:user/outbox', Outbox); router.get('/users/:user/outbox', Outbox);

View file

@ -100,7 +100,6 @@ type Option = {
apMentions?: User[] | null; apMentions?: User[] | null;
apHashtags?: string[] | null; apHashtags?: string[] | null;
apEmojis?: string[] | null; apEmojis?: string[] | null;
questionUri?: string | null;
uri?: string | null; uri?: string | null;
app?: App | null; app?: App | null;
}; };