This commit is contained in:
syuilo 2018-04-13 14:39:08 +09:00
parent cdf13d30f2
commit 17f4dd69a3
7 changed files with 21 additions and 39 deletions

View file

@ -1,5 +0,0 @@
export default [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
{ Hashtag: 'as:Hashtag' }
];

View file

@ -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);

View file

@ -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

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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);
};
// 投稿がリプライかつ投稿者がローカルユーザーかつリプライ先の投稿の投稿者がリモートユーザーなら配送

View file

@ -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