diff --git a/src/models/user.ts b/src/models/user.ts index 4186241a59..0e06512dae 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -62,6 +62,11 @@ type IUserBase = { */ isLocked: boolean; + /** + * このアカウントに届いているフォローリクエストの数 + */ + pendingReceivedFollowRequestsCount: number; + host: string; }; diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts index 5ca54d013c..103cd3ac36 100644 --- a/src/server/api/endpoints/i/update.ts +++ b/src/server/api/endpoints/i/update.ts @@ -5,6 +5,7 @@ import $ from 'cafy'; import ID from '../../../../cafy-id'; import User, { isValidName, isValidDescription, isValidLocation, isValidBirthday, pack } from '../../../../models/user'; import event from '../../../../publishers/stream'; import DriveFile from '../../../../models/drive-file'; +import acceptAllFollowRequests from '../../../../services/user/accept-all-follow-requests'; /** * Update myself diff --git a/src/services/following/create.ts b/src/services/following/create.ts index 03a8f399e8..39cecfddfb 100644 --- a/src/services/following/create.ts +++ b/src/services/following/create.ts @@ -28,6 +28,12 @@ export default async function(follower: IUser, followee: IUser) { } }); + User.update({ _id: followee._id }, { + $inc: { + pendingReceivedFollowRequestsCount: 1 + } + }); + // Publish reciveRequest event if (isLocalUser(followee)) { packUser(follower, followee).then(packed => event(followee._id, 'reciveRequest', packed)), diff --git a/src/services/user/accept-all-follow-requests.ts b/src/services/user/accept-all-follow-requests.ts index fbb221e772..397a0d7ec2 100644 --- a/src/services/user/accept-all-follow-requests.ts +++ b/src/services/user/accept-all-follow-requests.ts @@ -15,4 +15,10 @@ export default async function(user: IUser) { const follower = await User.findOne({ _id: request.followerId }); accept(user, follower); }); + + User.update({ _id: user._id }, { + $set: { + pendingReceivedFollowRequestsCount: 0 + } + }); } diff --git a/src/services/user/reject-follow-request.ts b/src/services/user/reject-follow-request.ts index 32965a1556..c6388f53e1 100644 --- a/src/services/user/reject-follow-request.ts +++ b/src/services/user/reject-follow-request.ts @@ -11,8 +11,14 @@ export default async function(followee: IUser, follower: IUser) { deliver(followee as ILocalUser, content, follower.inbox); } - FollowRequest.remove({ + await FollowRequest.remove({ followeeId: followee._id, followerId: follower._id }); + + User.update({ _id: followee._id }, { + $inc: { + pendingReceivedFollowRequestsCount: -1 + } + }); }