misskey/src/remote/activitypub/kernel/follow.ts

28 lines
816 B
TypeScript
Raw Normal View History

2018-04-18 07:09:55 +02:00
import * as mongo from 'mongodb';
2018-04-07 09:14:35 +02:00
import User, { IRemoteUser } from '../../../models/user';
2018-04-02 12:50:40 +02:00
import config from '../../../config';
2018-04-05 20:10:25 +02:00
import follow from '../../../services/following/create';
2018-04-07 09:14:35 +02:00
import { IFollow } from '../type';
2018-04-02 12:50:40 +02:00
2018-04-07 09:14:35 +02:00
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
2018-04-07 22:07:17 +02:00
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
2018-04-02 12:50:40 +02:00
2018-04-08 08:15:22 +02:00
if (!id.startsWith(config.url + '/')) {
2018-04-02 12:50:40 +02:00
return null;
}
2018-04-18 07:09:55 +02:00
const followee = await User.findOne({
_id: new mongo.ObjectID(id.split('/').pop())
});
2018-04-02 12:50:40 +02:00
if (followee === null) {
2018-04-08 08:15:22 +02:00
throw new Error('followee not found');
}
if (followee.host != null) {
throw new Error('フォローしようとしているユーザーはローカルユーザーではありません');
2018-04-02 12:50:40 +02:00
}
await follow(actor, followee, activity.id);
2018-04-02 12:50:40 +02:00
};