diff --git a/src/client/app/common/views/pages/follow.vue b/src/client/app/common/views/pages/follow.vue index ec74b3a9b9..05c1329f6d 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 62742a8f39..1db4b0cfa4 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 360ee91d4b..ff7260edb5 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 31d09bc8f8..8f3fbbdc8f 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 bd39b8e183..dd2fa544dc 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 bf8ed99e13..5e38879a49 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 4c7c90cc08..946c22568c 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 affcd2ef5a..eda6716321 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)); }