jormungandr-bite/src/services/following/requests/reject.ts

25 lines
807 B
TypeScript
Raw Normal View History

2018-06-17 23:28:43 -06:00
import User, { IUser, isRemoteUser, ILocalUser } from '../../../models/user';
import FollowRequest from '../../../models/follow-request';
2018-06-01 09:15:17 -06: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-05-31 09:42:37 -06:00
export default async function(followee: IUser, follower: IUser) {
if (isRemoteUser(follower)) {
const content = pack(renderReject(renderFollow(follower, followee)));
deliver(followee as ILocalUser, content, follower.inbox);
}
2018-05-31 10:12:02 -06:00
await FollowRequest.remove({
2018-05-31 09:42:37 -06:00
followeeId: followee._id,
followerId: follower._id
});
2018-05-31 10:12:02 -06:00
User.update({ _id: followee._id }, {
$inc: {
pendingReceivedFollowRequestsCount: -1
}
});
2018-05-31 09:42:37 -06:00
}