From eaec936fa6a53d0fd1004a613ea09f482198f366 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Tue, 4 Sep 2018 18:33:16 +0900 Subject: [PATCH] Fix remote follow (#2606) --- src/client/app/common/views/pages/follow.vue | 2 +- src/client/app/desktop/views/components/follow-button.vue | 8 +++++--- src/client/app/mobile/views/components/follow-button.vue | 4 +++- src/models/user.ts | 4 ++-- src/services/following/create.ts | 7 +------ src/services/following/requests/accept.ts | 2 ++ src/services/following/requests/create.ts | 2 -- src/services/following/requests/reject.ts | 5 ++++- 8 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/client/app/common/views/pages/follow.vue b/src/client/app/common/views/pages/follow.vue index ec74b3a9b..05c1329f6 100644 --- a/src/client/app/common/views/pages/follow.vue +++ b/src/client/app/common/views/pages/follow.vue @@ -83,7 +83,7 @@ export default Vue.extend({ userId: this.user.id }); } else { - if (this.user.isLocked && this.user.hasPendingFollowRequestFromYou) { + if (this.user.hasPendingFollowRequestFromYou) { this.user = await (this as any).api('following/requests/cancel', { userId: this.user.id }); diff --git a/src/client/app/desktop/views/components/follow-button.vue b/src/client/app/desktop/views/components/follow-button.vue index 62742a8f3..1db4b0cfa 100644 --- a/src/client/app/desktop/views/components/follow-button.vue +++ b/src/client/app/desktop/views/components/follow-button.vue @@ -55,13 +55,15 @@ export default Vue.extend({ methods: { onFollow(user) { if (user.id == this.u.id) { - this.user.isFollowing = user.isFollowing; + this.u.isFollowing = user.isFollowing; + this.u.hasPendingFollowRequestFromYou = user.hasPendingFollowRequestFromYou; } }, onUnfollow(user) { if (user.id == this.u.id) { - this.user.isFollowing = user.isFollowing; + this.u.isFollowing = user.isFollowing; + this.u.hasPendingFollowRequestFromYou = user.hasPendingFollowRequestFromYou; } }, @@ -74,7 +76,7 @@ export default Vue.extend({ userId: this.u.id }); } else { - if (this.u.isLocked && this.u.hasPendingFollowRequestFromYou) { + if (this.u.hasPendingFollowRequestFromYou) { this.u = await (this as any).api('following/requests/cancel', { userId: this.u.id }); diff --git a/src/client/app/mobile/views/components/follow-button.vue b/src/client/app/mobile/views/components/follow-button.vue index 360ee91d4..ff7260edb 100644 --- a/src/client/app/mobile/views/components/follow-button.vue +++ b/src/client/app/mobile/views/components/follow-button.vue @@ -48,12 +48,14 @@ export default Vue.extend({ onFollow(user) { if (user.id == this.u.id) { this.u.isFollowing = user.isFollowing; + this.u.hasPendingFollowRequestFromYou = user.hasPendingFollowRequestFromYou; } }, onUnfollow(user) { if (user.id == this.u.id) { this.u.isFollowing = user.isFollowing; + this.u.hasPendingFollowRequestFromYou = user.hasPendingFollowRequestFromYou; } }, @@ -66,7 +68,7 @@ export default Vue.extend({ userId: this.u.id }); } else { - if (this.u.isLocked && this.u.hasPendingFollowRequestFromYou) { + if (this.u.hasPendingFollowRequestFromYou) { this.u = await (this as any).api('following/requests/cancel', { userId: this.u.id }); diff --git a/src/models/user.ts b/src/models/user.ts index 31d09bc8f..8f3fbbdc8 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -432,10 +432,10 @@ export const pack = ( followerId: _user.id, followeeId: meId }), - _user.isLocked ? FollowRequest.findOne({ + FollowRequest.findOne({ followerId: meId, followeeId: _user.id - }) : Promise.resolve(null), + }), FollowRequest.findOne({ followerId: _user.id, followeeId: meId diff --git a/src/services/following/create.ts b/src/services/following/create.ts index bd39b8e18..dd2fa544d 100644 --- a/src/services/following/create.ts +++ b/src/services/following/create.ts @@ -11,7 +11,7 @@ import { deliver } from '../../queue'; import createFollowRequest from './requests/create'; export default async function(follower: IUser, followee: IUser) { - if (followee.isLocked) { + if (followee.isLocked || isLocalUser(follower) && isRemoteUser(followee)) { await createFollowRequest(follower, followee); } else { const following = await Following.insert({ @@ -72,11 +72,6 @@ export default async function(follower: IUser, followee: IUser) { notify(followee._id, follower._id, 'follow'); } - if (isLocalUser(follower) && isRemoteUser(followee)) { - const content = pack(renderFollow(follower, followee)); - deliver(follower, content, followee.inbox); - } - if (isRemoteUser(follower) && isLocalUser(followee)) { const content = pack(renderAccept(renderFollow(follower, followee))); deliver(followee, content, follower.inbox); diff --git a/src/services/following/requests/accept.ts b/src/services/following/requests/accept.ts index bf8ed99e1..5e38879a4 100644 --- a/src/services/following/requests/accept.ts +++ b/src/services/following/requests/accept.ts @@ -75,4 +75,6 @@ export default async function(followee: IUser, follower: IUser) { packUser(followee, followee, { detail: true }).then(packed => publishUserStream(followee._id, 'meUpdated', packed)); + + packUser(followee, follower).then(packed => publishUserStream(follower._id, 'follow', packed)); } diff --git a/src/services/following/requests/create.ts b/src/services/following/requests/create.ts index 4c7c90cc0..946c22568 100644 --- a/src/services/following/requests/create.ts +++ b/src/services/following/requests/create.ts @@ -7,8 +7,6 @@ import { deliver } from '../../../queue'; import FollowRequest from '../../../models/follow-request'; export default async function(follower: IUser, followee: IUser) { - if (!followee.isLocked) throw '対象のアカウントは鍵アカウントではありません'; - await FollowRequest.insert({ createdAt: new Date(), followerId: follower._id, diff --git a/src/services/following/requests/reject.ts b/src/services/following/requests/reject.ts index affcd2ef5..eda671632 100644 --- a/src/services/following/requests/reject.ts +++ b/src/services/following/requests/reject.ts @@ -1,9 +1,10 @@ -import User, { IUser, isRemoteUser, ILocalUser } from '../../../models/user'; +import User, { IUser, isRemoteUser, ILocalUser, pack as packUser } from '../../../models/user'; import FollowRequest from '../../../models/follow-request'; import pack from '../../../remote/activitypub/renderer'; import renderFollow from '../../../remote/activitypub/renderer/follow'; import renderReject from '../../../remote/activitypub/renderer/reject'; import { deliver } from '../../../queue'; +import { publishUserStream } from '../../../stream'; export default async function(followee: IUser, follower: IUser) { if (isRemoteUser(follower)) { @@ -21,4 +22,6 @@ export default async function(followee: IUser, follower: IUser) { pendingReceivedFollowRequestsCount: -1 } }); + + packUser(followee, follower).then(packed => publishUserStream(follower._id, 'unfollow', packed)); }