mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-26 22:29:28 +09:00
Accept remote follow
This commit is contained in:
parent
32c008d008
commit
cc3704c3e9
@ -4,11 +4,13 @@ import Following from '../../../models/following';
|
|||||||
import User from '../../../models/user';
|
import User from '../../../models/user';
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
import queue from '../../../queue';
|
import queue from '../../../queue';
|
||||||
|
import context from '../renderer/context';
|
||||||
|
import renderAccept from '../renderer/accept';
|
||||||
|
import request from '../../request';
|
||||||
|
|
||||||
export default async (actor, activity) => {
|
export default async (actor, activity) => {
|
||||||
const prefix = config.url + '/@';
|
const prefix = config.url + '/@';
|
||||||
const id = activity.object.id || activity.object;
|
const id = activity.object.id || activity.object;
|
||||||
let following;
|
|
||||||
|
|
||||||
if (!id.startsWith(prefix)) {
|
if (!id.startsWith(prefix)) {
|
||||||
return null;
|
return null;
|
||||||
@ -24,28 +26,33 @@ export default async (actor, activity) => {
|
|||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const accept = renderAccept(activity);
|
||||||
following = await Following.insert({
|
accept['@context'] = context;
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
request(followee, actor.account.inbox, accept),
|
||||||
|
|
||||||
|
Following.insert({
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
followerId: actor._id,
|
followerId: actor._id,
|
||||||
followeeId: followee._id
|
followeeId: followee._id
|
||||||
});
|
}).then(following => new Promise((resolve, reject) => {
|
||||||
} catch (exception) {
|
|
||||||
// duplicate key error
|
|
||||||
if (exception instanceof MongoError && exception.code === 11000) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw exception;
|
|
||||||
}
|
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
queue.create('http', { type: 'follow', following: following._id }).save(error => {
|
queue.create('http', { type: 'follow', following: following._id }).save(error => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
} else {
|
} else {
|
||||||
resolve(null);
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}), error => {
|
||||||
|
// duplicate key error
|
||||||
|
if (error instanceof MongoError && error.code === 11000) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
4
src/remote/activitypub/renderer/accept.ts
Normal file
4
src/remote/activitypub/renderer/accept.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export default object => ({
|
||||||
|
type: 'Accept',
|
||||||
|
object
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user