diff --git a/src/remote/activitypub/renderer/announce.ts b/src/remote/activitypub/renderer/announce.ts index 6d5a67b5c3..f6276ade04 100644 --- a/src/remote/activitypub/renderer/announce.ts +++ b/src/remote/activitypub/renderer/announce.ts @@ -6,6 +6,7 @@ export default (object: any, note: INote) => { return { id: `${config.url}/notes/${note._id}`, + actor: `${config.url}/users/${note.userId}`, type: 'Announce', published: note.createdAt.toISOString(), to: ['https://www.w3.org/ns/activitystreams#Public'], diff --git a/src/remote/activitypub/renderer/create.ts b/src/remote/activitypub/renderer/create.ts index b8bf98a655..1ee1418fce 100644 --- a/src/remote/activitypub/renderer/create.ts +++ b/src/remote/activitypub/renderer/create.ts @@ -1,4 +1,17 @@ -export default (object: any) => ({ - type: 'Create', - object -}); +import config from '../../../config'; +import { INote } from '../../../models/note'; + +export default (object: any, note: INote) => { + const activity = { + id: `${config.url}/notes/${note._id}/activity`, + actor: `${config.url}/users/${note.userId}`, + type: 'Create', + published: note.createdAt.toISOString(), + object + } as any; + + if (object.to) activity.to = object.to; + if (object.cc) activity.cc = object.cc; + + return activity; +}; diff --git a/src/remote/activitypub/renderer/delete.ts b/src/remote/activitypub/renderer/delete.ts index f468a22e24..2a4e70e25e 100644 --- a/src/remote/activitypub/renderer/delete.ts +++ b/src/remote/activitypub/renderer/delete.ts @@ -1,4 +1,8 @@ -export default (object: any) => ({ +import config from '../../../config'; +import { ILocalUser } from "../../../models/user"; + +export default (object: any, user: ILocalUser) => ({ type: 'Delete', + actor: `${config.url}/users/${user._id}`, object }); diff --git a/src/remote/activitypub/renderer/index.ts b/src/remote/activitypub/renderer/index.ts index ee7f496162..55b2801cad 100644 --- a/src/remote/activitypub/renderer/index.ts +++ b/src/remote/activitypub/renderer/index.ts @@ -1,7 +1,16 @@ -export default (x: any) => Object.assign({ - '@context': [ - 'https://www.w3.org/ns/activitystreams', - 'https://w3id.org/security/v1', - { Hashtag: 'as:Hashtag' } - ] -}, x); +import config from '../../../config'; +import * as uuid from 'uuid'; + +export default (x: any) => { + if (x !== null && typeof x === 'object' && x.id == null) { + x.id = `${config.url}/${uuid.v4()}`; + } + + return Object.assign({ + '@context': [ + 'https://www.w3.org/ns/activitystreams', + 'https://w3id.org/security/v1', + { Hashtag: 'as:Hashtag' } + ] + }, x); +}; diff --git a/src/remote/activitypub/renderer/undo.ts b/src/remote/activitypub/renderer/undo.ts index 4498409a57..bf90a3f281 100644 --- a/src/remote/activitypub/renderer/undo.ts +++ b/src/remote/activitypub/renderer/undo.ts @@ -1,4 +1,8 @@ -export default (object: any) => ({ +import config from '../../../config'; +import { ILocalUser, IUser } from "../../../models/user"; + +export default (object: any, user: ILocalUser | IUser) => ({ type: 'Undo', + actor: `${config.url}/users/${user._id}`, object }); diff --git a/src/remote/activitypub/request.ts b/src/remote/activitypub/request.ts index 585c1c0ce8..6238d3acb1 100644 --- a/src/remote/activitypub/request.ts +++ b/src/remote/activitypub/request.ts @@ -19,6 +19,9 @@ export default (user: ILocalUser, url: string, object: any) => new Promise((reso port, method: 'POST', path: pathname + search, + headers: { + 'Content-Type': 'application/activity+json' + } }, res => { log(`${url} --> ${res.statusCode}`); @@ -32,7 +35,7 @@ export default (user: ILocalUser, url: string, object: any) => new Promise((reso sign(req, { authorizationHeaderName: 'Signature', key: user.keypair, - keyId: `acct:${user.username}@${config.host}` + keyId: `${config.url}/users/${user._id}/publickey` }); // Signature: Signature ... => Signature: ... diff --git a/src/server/activitypub.ts b/src/server/activitypub.ts index d04ffd38f9..1007790ca6 100644 --- a/src/server/activitypub.ts +++ b/src/server/activitypub.ts @@ -25,7 +25,7 @@ function inbox(ctx: Router.IRouterContext) { ctx.req.headers.authorization = 'Signature ' + ctx.req.headers.signature; try { - signature = httpSignature.parseRequest(ctx.req); + signature = httpSignature.parseRequest(ctx.req, { 'headers': [] }); } catch (e) { ctx.status = 401; return; diff --git a/src/services/following/delete.ts b/src/services/following/delete.ts index 8a9f739bd4..7c285e9eac 100644 --- a/src/services/following/delete.ts +++ b/src/services/following/delete.ts @@ -56,7 +56,7 @@ export default async function(follower: IUser, followee: IUser) { } if (isLocalUser(follower) && isRemoteUser(followee)) { - const content = pack(renderUndo(renderFollow(follower, followee))); + const content = pack(renderUndo(renderFollow(follower, followee), follower)); deliver(follower, content, followee.inbox); } } diff --git a/src/services/following/requests/cancel.ts b/src/services/following/requests/cancel.ts index 26e4544d5c..9655a95f04 100644 --- a/src/services/following/requests/cancel.ts +++ b/src/services/following/requests/cancel.ts @@ -8,7 +8,7 @@ import { publishUserStream } from '../../../stream'; export default async function(followee: IUser, follower: IUser) { if (isRemoteUser(followee)) { - const content = pack(renderUndo(renderFollow(follower, followee))); + const content = pack(renderUndo(renderFollow(follower, followee), follower)); deliver(follower as ILocalUser, content, followee.inbox); } diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 268bfa5bbe..63e3557828 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -240,7 +240,7 @@ export default async (user: IUser, data: Option, silent = false) => new Promise< async function renderActivity(data: Option, note: INote) { const content = data.renote && data.text == null ? renderAnnounce(data.renote.uri ? data.renote.uri : `${config.url}/notes/${data.renote._id}`, note) - : renderCreate(await renderNote(note, false)); + : renderCreate(await renderNote(note, false), note); return packAp(content); } diff --git a/src/services/note/delete.ts b/src/services/note/delete.ts index d444b13a8b..d0e2b12b41 100644 --- a/src/services/note/delete.ts +++ b/src/services/note/delete.ts @@ -32,7 +32,7 @@ export default async function(user: IUser, note: INote) { //#region ローカルの投稿なら削除アクティビティを配送 if (isLocalUser(user)) { - const content = pack(renderDelete(await renderNote(note))); + const content = pack(renderDelete(await renderNote(note), user)); const followings = await Following.find({ followeeId: user._id,