From 56eb896a03068b32469be4ce4dd0dceb8c4a2b4f Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 15 Mar 2019 00:23:24 +0900 Subject: [PATCH] Accept Article object (#4499) --- src/models/note.ts | 5 +++++ src/remote/activitypub/kernel/announce/index.ts | 4 +--- src/remote/activitypub/kernel/create/index.ts | 4 +--- src/remote/activitypub/kernel/delete/index.ts | 4 +--- src/remote/activitypub/models/note.ts | 3 ++- src/server/api/endpoints/ap/show.ts | 2 +- src/services/note/create.ts | 2 ++ 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/models/note.ts b/src/models/note.ts index 466d1837c..369a00916 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -41,6 +41,7 @@ export type INote = { replyId: mongo.ObjectID; renoteId: mongo.ObjectID; poll: IPoll; + name?: string; text: string; tags: string[]; tagsLower: string[]; @@ -391,6 +392,10 @@ export const pack = async ( } //#endregion + if (_note.name) { + _note.text = `【${_note.name}】\n${_note.text}`; + } + if (_note.user.isCat && _note.text) { _note.text = (_note.text // ja-JP diff --git a/src/remote/activitypub/kernel/announce/index.ts b/src/remote/activitypub/kernel/announce/index.ts index 3b2eeb7aa..5f738da6c 100644 --- a/src/remote/activitypub/kernel/announce/index.ts +++ b/src/remote/activitypub/kernel/announce/index.ts @@ -24,10 +24,8 @@ export default async (actor: IRemoteUser, activity: IAnnounce): Promise => switch (object.type) { case 'Note': - announceNote(resolver, actor, activity, object as INote); - break; - case 'Question': + case 'Article': announceNote(resolver, actor, activity, object as INote); break; diff --git a/src/remote/activitypub/kernel/create/index.ts b/src/remote/activitypub/kernel/create/index.ts index 2afdc0137..6e314d0b8 100644 --- a/src/remote/activitypub/kernel/create/index.ts +++ b/src/remote/activitypub/kernel/create/index.ts @@ -29,10 +29,8 @@ export default async (actor: IRemoteUser, activity: ICreate): Promise => { break; case 'Note': - createNote(resolver, actor, object); - break; - case 'Question': + case 'Article': createNote(resolver, actor, object); break; diff --git a/src/remote/activitypub/kernel/delete/index.ts b/src/remote/activitypub/kernel/delete/index.ts index 864c9f5f7..c9c385b1f 100644 --- a/src/remote/activitypub/kernel/delete/index.ts +++ b/src/remote/activitypub/kernel/delete/index.ts @@ -21,10 +21,8 @@ export default async (actor: IRemoteUser, activity: IDelete): Promise => { switch (object.type) { case 'Note': - deleteNote(actor, uri); - break; - case 'Question': + case 'Article': deleteNote(actor, uri); break; diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index c8939279e..625162152 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -57,7 +57,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false const object: any = await resolver.resolve(value); - if (!object || !['Note', 'Question'].includes(object.type)) { + if (!object || !['Note', 'Question', 'Article'].includes(object.type)) { logger.error(`invalid note: ${value}`, { resolver: { history: resolver.getHistory() @@ -199,6 +199,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false files, reply, renote: quote, + name: note.name, cw, text, viaMobile: false, diff --git a/src/server/api/endpoints/ap/show.ts b/src/server/api/endpoints/ap/show.ts index 861c8bce2..7f4afa1f6 100644 --- a/src/server/api/endpoints/ap/show.ts +++ b/src/server/api/endpoints/ap/show.ts @@ -103,7 +103,7 @@ async function fetchAny(uri: string) { }; } - if (['Note', 'Question'].includes(object.type)) { + if (['Note', 'Question', 'Article'].includes(object.type)) { const note = await createNote(object.id); return { type: 'Note', diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 88598e1db..5f69329a4 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -91,6 +91,7 @@ class NotificationManager { type Option = { createdAt?: Date; + name?: string; text?: string; reply?: INote; renote?: INote; @@ -437,6 +438,7 @@ async function insertNote(user: IUser, data: Option, tags: string[], emojis: str fileIds: data.files ? data.files.map(file => file._id) : [], replyId: data.reply ? data.reply._id : null, renoteId: data.renote ? data.renote._id : null, + name: data.name, text: data.text, poll: data.poll, cw: data.cw == null ? null : data.cw,