diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-10-13 20:11:00 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-10-13 20:11:00 +0900 |
| commit | 65e5cfa68eee619843192f3bf2a3e901a0910101 (patch) | |
| tree | 6ed53b64d96371a5543208b5815718492aebe753 /src/services/following/create.ts | |
| parent | Merge branch 'develop' of https://github.com/syuilo/misskey into develop (diff) | |
| download | misskey-65e5cfa68eee619843192f3bf2a3e901a0910101.tar.gz misskey-65e5cfa68eee619843192f3bf2a3e901a0910101.tar.bz2 misskey-65e5cfa68eee619843192f3bf2a3e901a0910101.zip | |
Resolve #2853
Diffstat (limited to 'src/services/following/create.ts')
| -rw-r--r-- | src/services/following/create.ts | 115 |
1 files changed, 60 insertions, 55 deletions
diff --git a/src/services/following/create.ts b/src/services/following/create.ts index 637e3e8093..01b6b4aed9 100644 --- a/src/services/following/create.ts +++ b/src/services/following/create.ts @@ -11,70 +11,75 @@ import { deliver } from '../../queue'; import createFollowRequest from './requests/create'; export default async function(follower: IUser, followee: IUser) { - if (followee.isLocked || isLocalUser(follower) && isRemoteUser(followee)) { + // フォロー対象が鍵アカウントである or + // フォロワーがBotであり、フォロー対象がBotからのフォローに慎重である or + // フォロワーがローカルユーザーであり、フォロー対象がリモートユーザーである + // 上記のいずれかに当てはまる場合はすぐフォローせずにフォローリクエストを発行しておく + if (followee.isLocked || (followee.carefulBot && follower.isBot) || (isLocalUser(follower) && isRemoteUser(followee))) { await createFollowRequest(follower, followee); - } else { - const following = await Following.insert({ - createdAt: new Date(), - followerId: follower._id, - followeeId: followee._id, + return; + } - // 非正規化 - _follower: { - host: follower.host, - inbox: isRemoteUser(follower) ? follower.inbox : undefined, - sharedInbox: isRemoteUser(follower) ? follower.sharedInbox : undefined - }, - _followee: { - host: followee.host, - inbox: isRemoteUser(followee) ? followee.inbox : undefined, - sharedInbox: isRemoteUser(followee) ? followee.sharedInbox : undefined - } - }); + const following = await Following.insert({ + createdAt: new Date(), + followerId: follower._id, + followeeId: followee._id, - //#region Increment following count - User.update({ _id: follower._id }, { - $inc: { - followingCount: 1 - } - }); + // 非正規化 + _follower: { + host: follower.host, + inbox: isRemoteUser(follower) ? follower.inbox : undefined, + sharedInbox: isRemoteUser(follower) ? follower.sharedInbox : undefined + }, + _followee: { + host: followee.host, + inbox: isRemoteUser(followee) ? followee.inbox : undefined, + sharedInbox: isRemoteUser(followee) ? followee.sharedInbox : undefined + } + }); - FollowingLog.insert({ - createdAt: following.createdAt, - userId: follower._id, - count: follower.followingCount + 1 - }); - //#endregion + //#region Increment following count + User.update({ _id: follower._id }, { + $inc: { + followingCount: 1 + } + }); - //#region Increment followers count - User.update({ _id: followee._id }, { - $inc: { - followersCount: 1 - } - }); - FollowedLog.insert({ - createdAt: following.createdAt, - userId: followee._id, - count: followee.followersCount + 1 - }); - //#endregion + FollowingLog.insert({ + createdAt: following.createdAt, + userId: follower._id, + count: follower.followingCount + 1 + }); + //#endregion - // Publish follow event - if (isLocalUser(follower)) { - packUser(followee, follower).then(packed => publishMainStream(follower._id, 'follow', packed)); + //#region Increment followers count + User.update({ _id: followee._id }, { + $inc: { + followersCount: 1 } + }); + FollowedLog.insert({ + createdAt: following.createdAt, + userId: followee._id, + count: followee.followersCount + 1 + }); + //#endregion + + // Publish follow event + if (isLocalUser(follower)) { + packUser(followee, follower).then(packed => publishMainStream(follower._id, 'follow', packed)); + } - // Publish followed event - if (isLocalUser(followee)) { - packUser(follower, followee).then(packed => publishMainStream(followee._id, 'followed', packed)), + // Publish followed event + if (isLocalUser(followee)) { + packUser(follower, followee).then(packed => publishMainStream(followee._id, 'followed', packed)), - // 通知を作成 - notify(followee._id, follower._id, 'follow'); - } + // 通知を作成 + notify(followee._id, follower._id, 'follow'); + } - if (isRemoteUser(follower) && isLocalUser(followee)) { - const content = pack(renderAccept(renderFollow(follower, followee))); - deliver(followee, content, follower.inbox); - } + if (isRemoteUser(follower) && isLocalUser(followee)) { + const content = pack(renderAccept(renderFollow(follower, followee))); + deliver(followee, content, follower.inbox); } } |