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[];
|
fileIds: mongo.ObjectID[];
|
||||||
replyId: mongo.ObjectID;
|
replyId: mongo.ObjectID;
|
||||||
renoteId: mongo.ObjectID;
|
renoteId: mongo.ObjectID;
|
||||||
poll: {
|
poll: IPoll;
|
||||||
choices: IChoice[]
|
|
||||||
};
|
|
||||||
text: string;
|
text: string;
|
||||||
tags: string[];
|
tags: string[];
|
||||||
tagsLower: string[];
|
tagsLower: string[];
|
||||||
@ -100,6 +98,10 @@ export type INote = {
|
|||||||
_files?: IDriveFile[];
|
_files?: IDriveFile[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type IPoll = {
|
||||||
|
choices: IChoice[]
|
||||||
|
};
|
||||||
|
|
||||||
export type IChoice = {
|
export type IChoice = {
|
||||||
id: number;
|
id: number;
|
||||||
text: string;
|
text: string;
|
||||||
|
@ -14,6 +14,7 @@ import Emoji, { IEmoji } from '../../../models/emoji';
|
|||||||
import { ITag } from './tag';
|
import { ITag } from './tag';
|
||||||
import { toUnicode } from 'punycode';
|
import { toUnicode } from 'punycode';
|
||||||
import { unique, concat, difference } from '../../../prelude/array';
|
import { unique, concat, difference } from '../../../prelude/array';
|
||||||
|
import { extractPollFromQuestion } from './question';
|
||||||
|
|
||||||
const log = debug('misskey:activitypub');
|
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 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) {
|
if (actor.lastFetchedAt == null || Date.now() - actor.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24) {
|
||||||
updatePerson(note.attributedTo);
|
updatePerson(note.attributedTo);
|
||||||
@ -137,6 +141,8 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
|
|||||||
apMentions,
|
apMentions,
|
||||||
apHashtags,
|
apHashtags,
|
||||||
apEmojis,
|
apEmojis,
|
||||||
|
questionUri,
|
||||||
|
poll,
|
||||||
uri: note.id
|
uri: note.id
|
||||||
}, silent);
|
}, 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;
|
let text = note.text;
|
||||||
|
|
||||||
const questions = [];
|
let question: string;
|
||||||
if (note.poll != null) {
|
if (note.poll != null) {
|
||||||
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\n[投票を見る](${url})`;
|
text += `\n\n[投票を見る](${url})`;
|
||||||
|
|
||||||
questions.push(await renderQuestion(user as ILocalUser, note));
|
question = `${config.url}/questions/${note._id}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let apText = text;
|
let apText = text;
|
||||||
@ -124,7 +124,6 @@ export default async function renderNote(note: INote, dive = true): Promise<any>
|
|||||||
...hashtagTags,
|
...hashtagTags,
|
||||||
...mentionTags,
|
...mentionTags,
|
||||||
...apemojis,
|
...apemojis,
|
||||||
...questions,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -135,6 +134,7 @@ export default async function renderNote(note: INote, 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,
|
||||||
|
@ -42,6 +42,7 @@ export interface INote extends IObject {
|
|||||||
type: 'Note';
|
type: 'Note';
|
||||||
_misskey_content: string;
|
_misskey_content: string;
|
||||||
_misskey_quote: string;
|
_misskey_quote: string;
|
||||||
|
_misskey_question: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPerson extends IObject {
|
export interface IPerson extends IObject {
|
||||||
|
@ -102,6 +102,7 @@ type Option = {
|
|||||||
apMentions?: IUser[];
|
apMentions?: IUser[];
|
||||||
apHashtags?: string[];
|
apHashtags?: string[];
|
||||||
apEmojis?: string[];
|
apEmojis?: string[];
|
||||||
|
questionUri?: string;
|
||||||
uri?: string;
|
uri?: string;
|
||||||
app?: IApp;
|
app?: IApp;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user