This commit is contained in:
syuilo
2018-06-01 00:42:37 +09:00
parent 51255bb446
commit 35115607bc
9 changed files with 110 additions and 3 deletions

View File

@ -25,7 +25,7 @@ export default async (actor: IRemoteUser, activity: IAccept): Promise<void> => {
switch (object.type) {
case 'Follow':
acceptFollow(resolver, actor, activity, object);
acceptFollow(actor, object);
break;
default:

View File

@ -6,6 +6,8 @@ import follow from './follow';
import undo from './undo';
import like from './like';
import announce from './announce';
import accept from './accept';
import reject from './reject';
const self = async (actor: IRemoteUser, activity: Object): Promise<void> => {
switch (activity.type) {
@ -22,7 +24,11 @@ const self = async (actor: IRemoteUser, activity: Object): Promise<void> => {
break;
case 'Accept':
// noop
await accept(actor, activity);
break;
case 'Reject':
await reject(actor, activity);
break;
case 'Announce':

View File

@ -0,0 +1,27 @@
import * as mongo from 'mongodb';
import User, { IRemoteUser } from '../../../../models/user';
import config from '../../../../config';
import reject from '../../../../services/user/reject-follow-request';
import { IFollow } from '../../type';
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
if (!id.startsWith(config.url + '/')) {
return null;
}
const follower = await User.findOne({
_id: new mongo.ObjectID(id.split('/').pop())
});
if (follower === null) {
throw new Error('follower not found');
}
if (follower.host != null) {
throw new Error('フォローリクエストしたユーザーはローカルユーザーではありません');
}
await reject(actor, follower);
};

View File

@ -0,0 +1,35 @@
import * as debug from 'debug';
import Resolver from '../../resolver';
import { IRemoteUser } from '../../../../models/user';
import rejectFollow from './follow';
import { IReject } from '../../type';
const log = debug('misskey:activitypub');
export default async (actor: IRemoteUser, activity: IReject): Promise<void> => {
const uri = activity.id || activity;
log(`Reject: ${uri}`);
const resolver = new Resolver();
let object;
try {
object = await resolver.resolve(activity.object);
} catch (e) {
log(`Resolution failed: ${e}`);
throw e;
}
switch (object.type) {
case 'Follow':
rejectFollow(actor, object);
break;
default:
console.warn(`Unknown reject type: ${object.type}`);
break;
}
};

View File

@ -0,0 +1,4 @@
export default object => ({
type: 'Reject',
object
});

View File

@ -83,6 +83,10 @@ export interface IAccept extends IActivity {
type: 'Accept';
}
export interface IReject extends IActivity {
type: 'Reject';
}
export interface ILike extends IActivity {
type: 'Like';
_misskey_reaction: string;
@ -100,5 +104,6 @@ export type Object =
IUndo |
IFollow |
IAccept |
IReject |
ILike |
IAnnounce;