diff --git a/src/remote/activitypub/renderer/context.ts b/src/remote/activitypub/renderer/context.ts deleted file mode 100644 index b56f727ae7..0000000000 --- a/src/remote/activitypub/renderer/context.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default [ - 'https://www.w3.org/ns/activitystreams', - 'https://w3id.org/security/v1', - { Hashtag: 'as:Hashtag' } -]; diff --git a/src/remote/activitypub/renderer/index.ts b/src/remote/activitypub/renderer/index.ts new file mode 100644 index 0000000000..ee7f496162 --- /dev/null +++ b/src/remote/activitypub/renderer/index.ts @@ -0,0 +1,7 @@ +export default (x: any) => Object.assign({ + '@context': [ + 'https://www.w3.org/ns/activitystreams', + 'https://w3id.org/security/v1', + { Hashtag: 'as:Hashtag' } + ] +}, x); diff --git a/src/server/activitypub.ts b/src/server/activitypub.ts index acd10b7886..2a99bccfc4 100644 --- a/src/server/activitypub.ts +++ b/src/server/activitypub.ts @@ -2,8 +2,7 @@ import * as Router from 'koa-router'; import { parseRequest } from 'http-signature'; import { createHttp } from '../queue'; -import context from '../remote/activitypub/renderer/context'; -import render from '../remote/activitypub/renderer/note'; +import pack from '../remote/activitypub/renderer'; import Note from '../models/note'; import User, { isLocalUser } from '../models/user'; import renderNote from '../remote/activitypub/renderer/note'; @@ -57,10 +56,7 @@ router.get('/notes/:note', async (ctx, next) => { return; } - const rendered = await render(note); - rendered['@context'] = context; - - ctx.body = rendered; + ctx.body = pack(await renderNote(note)); }); // outbot @@ -81,9 +77,8 @@ router.get('/users/:user/outbox', async ctx => { const renderedNotes = await Promise.all(notes.map(note => renderNote(note))); const rendered = renderOrderedCollection(`${config.url}/users/${userId}/inbox`, user.notesCount, renderedNotes); - rendered['@context'] = context; - ctx.body = rendered; + ctx.body = pack(rendered); }); // publickey @@ -98,10 +93,7 @@ router.get('/users/:user/publickey', async ctx => { } if (isLocalUser(user)) { - const rendered = renderKey(user); - rendered['@context'] = context; - - ctx.body = rendered; + ctx.body = pack(renderKey(user)); } else { ctx.status = 400; } @@ -118,10 +110,7 @@ router.get('/users/:user', async ctx => { return; } - const rendered = renderPerson(user); - rendered['@context'] = context; - - ctx.body = rendered; + ctx.body = pack(renderPerson(user)); }); // follow form diff --git a/src/services/following/create.ts b/src/services/following/create.ts index 31e3be19ed..3289e31294 100644 --- a/src/services/following/create.ts +++ b/src/services/following/create.ts @@ -4,7 +4,7 @@ import FollowingLog from '../../models/following-log'; import FollowedLog from '../../models/followed-log'; import event from '../../publishers/stream'; import notify from '../../publishers/notify'; -import context from '../../remote/activitypub/renderer/context'; +import pack from '../../remote/activitypub/renderer'; import renderFollow from '../../remote/activitypub/renderer/follow'; import renderAccept from '../../remote/activitypub/renderer/accept'; import { deliver } from '../../queue'; @@ -57,16 +57,12 @@ export default async function(follower: IUser, followee: IUser, activity?) { } if (isLocalUser(follower) && isRemoteUser(followee)) { - const content = renderFollow(follower, followee); - content['@context'] = context; - + const content = pack(renderFollow(follower, followee)); deliver(follower, content, followee.inbox).save(); } if (isRemoteUser(follower) && isLocalUser(followee)) { - const content = renderAccept(activity); - content['@context'] = context; - + const content = pack(renderAccept(activity)); deliver(followee, content, follower.inbox).save(); } } diff --git a/src/services/following/delete.ts b/src/services/following/delete.ts index d79bf64f53..8b6c56816a 100644 --- a/src/services/following/delete.ts +++ b/src/services/following/delete.ts @@ -3,7 +3,7 @@ import Following from '../../models/following'; import FollowingLog from '../../models/following-log'; import FollowedLog from '../../models/followed-log'; import event from '../../publishers/stream'; -import context from '../../remote/activitypub/renderer/context'; +import pack from '../../remote/activitypub/renderer'; import renderFollow from '../../remote/activitypub/renderer/follow'; import renderUndo from '../../remote/activitypub/renderer/undo'; import { deliver } from '../../queue'; @@ -56,9 +56,7 @@ export default async function(follower: IUser, followee: IUser, activity?) { } if (isLocalUser(follower) && isRemoteUser(followee)) { - const content = renderUndo(renderFollow(follower, followee)); - content['@context'] = context; - + const content = pack(renderUndo(renderFollow(follower, followee))); deliver(follower, content, followee.inbox).save(); } } diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 8f0b84bccd..b238cd5607 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -6,7 +6,7 @@ import { deliver } from '../../queue'; import renderNote from '../../remote/activitypub/renderer/note'; import renderCreate from '../../remote/activitypub/renderer/create'; import renderAnnounce from '../../remote/activitypub/renderer/announce'; -import context from '../../remote/activitypub/renderer/context'; +import packAp from '../../remote/activitypub/renderer'; import { IDriveFile } from '../../models/drive-file'; import notify from '../../publishers/notify'; import NoteWatching from '../../models/note-watching'; @@ -132,8 +132,7 @@ export default async (user: IUser, data: { const content = data.renote && data.text == null ? renderAnnounce(data.renote.uri ? data.renote.uri : await renderNote(data.renote)) : renderCreate(await renderNote(note)); - content['@context'] = context; - return content; + return packAp(content); }; // 投稿がリプライかつ投稿者がローカルユーザーかつリプライ先の投稿の投稿者がリモートユーザーなら配送 diff --git a/src/services/note/reaction/create.ts b/src/services/note/reaction/create.ts index 88158034f3..69a14248da 100644 --- a/src/services/note/reaction/create.ts +++ b/src/services/note/reaction/create.ts @@ -8,7 +8,7 @@ import NoteWatching from '../../../models/note-watching'; import watch from '../watch'; import renderLike from '../../../remote/activitypub/renderer/like'; import { deliver } from '../../../queue'; -import context from '../../../remote/activitypub/renderer/context'; +import pack from '../../../remote/activitypub/renderer'; export default async (user: IUser, note: INote, reaction: string) => new Promise(async (res, rej) => { // Myself @@ -85,9 +85,7 @@ export default async (user: IUser, note: INote, reaction: string) => new Promise //#region 配信 // リアクターがローカルユーザーかつリアクション対象がリモートユーザーの投稿なら配送 if (isLocalUser(user) && isRemoteUser(note._user)) { - const content = renderLike(user, note); - content['@context'] = context; - + const content = pack(renderLike(user, note)); deliver(user, content, note._user.inbox).save(); } //#endregion