mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-27 22:39:33 +09:00
wip
This commit is contained in:
parent
08524feb03
commit
b7a6699c35
@ -38,9 +38,7 @@ export type INote = {
|
||||
fileIds: mongo.ObjectID[];
|
||||
replyId: mongo.ObjectID;
|
||||
renoteId: mongo.ObjectID;
|
||||
poll: {
|
||||
choices: IChoice[]
|
||||
};
|
||||
poll: IPoll;
|
||||
text: string;
|
||||
tags: string[];
|
||||
tagsLower: string[];
|
||||
@ -100,6 +98,10 @@ export type INote = {
|
||||
_files?: IDriveFile[];
|
||||
};
|
||||
|
||||
export type IPoll = {
|
||||
choices: IChoice[]
|
||||
};
|
||||
|
||||
export type IChoice = {
|
||||
id: number;
|
||||
text: string;
|
||||
|
@ -14,6 +14,7 @@ import Emoji, { IEmoji } from '../../../models/emoji';
|
||||
import { ITag } from './tag';
|
||||
import { toUnicode } from 'punycode';
|
||||
import { unique, concat, difference } from '../../../prelude/array';
|
||||
import { extractPollFromQuestion } from './question';
|
||||
|
||||
const log = debug('misskey:activitypub');
|
||||
|
||||
@ -117,6 +118,9 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
|
||||
|
||||
const apEmojis = emojis.map(emoji => emoji.name);
|
||||
|
||||
const questionUri = note._misskey_question;
|
||||
const poll = questionUri ? await extractPollFromQuestion(questionUri).catch(() => undefined) : undefined;
|
||||
|
||||
// ユーザーの情報が古かったらついでに更新しておく
|
||||
if (actor.lastFetchedAt == null || Date.now() - actor.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24) {
|
||||
updatePerson(note.attributedTo);
|
||||
@ -137,6 +141,8 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
|
||||
apMentions,
|
||||
apHashtags,
|
||||
apEmojis,
|
||||
questionUri,
|
||||
poll,
|
||||
uri: note.id
|
||||
}, silent);
|
||||
}
|
||||
|
19
src/remote/activitypub/models/question.ts
Normal file
19
src/remote/activitypub/models/question.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { IChoice, IPoll } from '../../../models/note';
|
||||
import Resolver from '../resolver';
|
||||
|
||||
export async function extractPollFromQuestion(questionUri: string): Promise<IPoll> {
|
||||
const resolver = new Resolver();
|
||||
const question = await resolver.resolve(questionUri) as any;
|
||||
|
||||
const choices: IChoice[] = question.oneOf.map((x: any, i: number) => {
|
||||
return {
|
||||
id: i,
|
||||
text: x.name,
|
||||
votes: x._misskey_votes || 0,
|
||||
} as IChoice;
|
||||
});
|
||||
|
||||
return {
|
||||
choices
|
||||
};
|
||||
}
|
@ -94,14 +94,14 @@ export default async function renderNote(note: INote, dive = true): Promise<any>
|
||||
|
||||
let text = note.text;
|
||||
|
||||
const questions = [];
|
||||
let question: string;
|
||||
if (note.poll != null) {
|
||||
if (text == null) text = '';
|
||||
const url = `${config.url}/notes/${note._id}`;
|
||||
// TODO: i18n
|
||||
text += `\n\n[投票を見る](${url})`;
|
||||
|
||||
questions.push(await renderQuestion(user as ILocalUser, note));
|
||||
question = `${config.url}/questions/${note._id}`;
|
||||
}
|
||||
|
||||
let apText = text;
|
||||
@ -124,7 +124,6 @@ export default async function renderNote(note: INote, dive = true): Promise<any>
|
||||
...hashtagTags,
|
||||
...mentionTags,
|
||||
...apemojis,
|
||||
...questions,
|
||||
];
|
||||
|
||||
return {
|
||||
@ -135,6 +134,7 @@ export default async function renderNote(note: INote, dive = true): Promise<any>
|
||||
content,
|
||||
_misskey_content: text,
|
||||
_misskey_quote: quote,
|
||||
_misskey_question: question,
|
||||
published: note.createdAt.toISOString(),
|
||||
to,
|
||||
cc,
|
||||
|
@ -42,6 +42,7 @@ export interface INote extends IObject {
|
||||
type: 'Note';
|
||||
_misskey_content: string;
|
||||
_misskey_quote: string;
|
||||
_misskey_question: string;
|
||||
}
|
||||
|
||||
export interface IPerson extends IObject {
|
||||
|
@ -102,6 +102,7 @@ type Option = {
|
||||
apMentions?: IUser[];
|
||||
apHashtags?: string[];
|
||||
apEmojis?: string[];
|
||||
questionUri?: string;
|
||||
uri?: string;
|
||||
app?: IApp;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user