2018-04-02 13:50:40 +03:00
|
|
|
import parseAcct from '../../../acct/parse';
|
|
|
|
import User from '../../../models/user';
|
|
|
|
import config from '../../../config';
|
2018-04-05 21:10:25 +03:00
|
|
|
import follow from '../../../services/following/create';
|
2018-04-02 13:50:40 +03:00
|
|
|
|
2018-04-04 17:59:38 +03:00
|
|
|
export default async (actor, activity): Promise<void> => {
|
2018-04-02 13:50:40 +03:00
|
|
|
const prefix = config.url + '/@';
|
|
|
|
const id = activity.object.id || activity.object;
|
|
|
|
|
|
|
|
if (!id.startsWith(prefix)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { username, host } = parseAcct(id.slice(prefix.length));
|
|
|
|
if (host !== null) {
|
|
|
|
throw new Error();
|
|
|
|
}
|
|
|
|
|
|
|
|
const followee = await User.findOne({ username, host });
|
|
|
|
if (followee === null) {
|
|
|
|
throw new Error();
|
|
|
|
}
|
|
|
|
|
2018-04-04 17:59:38 +03:00
|
|
|
await follow(actor, followee, activity);
|
2018-04-02 13:50:40 +03:00
|
|
|
};
|