yumechi-no-kuni/src/services/following/requests/cancel.ts

30 lines
983 B
TypeScript
Raw Normal View History

2018-06-02 02:01:32 -05:00
import User, { IUser, isRemoteUser, ILocalUser, pack as packUser } from "../../../models/user";
2018-06-01 10:38:31 -05:00
import FollowRequest from "../../../models/follow-request";
import pack from '../../../remote/activitypub/renderer';
import renderFollow from '../../../remote/activitypub/renderer/follow';
import renderUndo from '../../../remote/activitypub/renderer/undo';
import { deliver } from '../../../queue';
2018-06-02 02:01:32 -05:00
import event from '../../../publishers/stream';
2018-06-01 10:38:31 -05:00
export default async function(followee: IUser, follower: IUser) {
if (isRemoteUser(followee)) {
const content = pack(renderUndo(renderFollow(follower, followee)));
deliver(follower as ILocalUser, content, followee.inbox);
}
await FollowRequest.remove({
followeeId: followee._id,
followerId: follower._id
});
2018-06-02 02:01:32 -05:00
await User.update({ _id: followee._id }, {
2018-06-01 10:38:31 -05:00
$inc: {
pendingReceivedFollowRequestsCount: -1
}
});
2018-06-02 02:01:32 -05:00
packUser(followee, followee, {
detail: true
}).then(packed => event(followee._id, 'meUpdated', packed));
2018-06-01 10:38:31 -05:00
}