2018-09-04 11:33:16 +02:00
|
|
|
import User, { IUser, isRemoteUser, ILocalUser, pack as packUser } from '../../../models/user';
|
2018-06-18 07:28:43 +02:00
|
|
|
import FollowRequest from '../../../models/follow-request';
|
2018-06-01 17:15:17 +02:00
|
|
|
import pack from '../../../remote/activitypub/renderer';
|
|
|
|
import renderFollow from '../../../remote/activitypub/renderer/follow';
|
|
|
|
import renderReject from '../../../remote/activitypub/renderer/reject';
|
|
|
|
import { deliver } from '../../../queue';
|
2018-10-07 04:06:17 +02:00
|
|
|
import { publishMainStream } from '../../../stream';
|
2018-05-31 17:42:37 +02:00
|
|
|
|
|
|
|
export default async function(followee: IUser, follower: IUser) {
|
|
|
|
if (isRemoteUser(follower)) {
|
2018-10-15 09:51:23 +02:00
|
|
|
const request = await FollowRequest.findOne({
|
|
|
|
followeeId: followee._id,
|
|
|
|
followerId: follower._id
|
|
|
|
});
|
|
|
|
|
|
|
|
const content = pack(renderReject(renderFollow(follower, followee, request.requestId), followee as ILocalUser));
|
2018-05-31 17:42:37 +02:00
|
|
|
deliver(followee as ILocalUser, content, follower.inbox);
|
|
|
|
}
|
|
|
|
|
2018-05-31 18:12:02 +02:00
|
|
|
await FollowRequest.remove({
|
2018-05-31 17:42:37 +02:00
|
|
|
followeeId: followee._id,
|
|
|
|
followerId: follower._id
|
|
|
|
});
|
2018-05-31 18:12:02 +02:00
|
|
|
|
|
|
|
User.update({ _id: followee._id }, {
|
|
|
|
$inc: {
|
|
|
|
pendingReceivedFollowRequestsCount: -1
|
|
|
|
}
|
|
|
|
});
|
2018-09-04 11:33:16 +02:00
|
|
|
|
2018-10-30 06:34:32 +01:00
|
|
|
packUser(followee, follower, {
|
|
|
|
detail: true
|
|
|
|
}).then(packed => publishMainStream(follower._id, 'unfollow', packed));
|
2018-05-31 17:42:37 +02:00
|
|
|
}
|