Fix remote follow (#2606)
This commit is contained in:
		
							parent
							
								
									a0735b0e7a
								
							
						
					
					
						commit
						eaec936fa6
					
				
					 8 changed files with 18 additions and 16 deletions
				
			
		| 
						 | 
					@ -83,7 +83,7 @@ export default Vue.extend({
 | 
				
			||||||
						userId: this.user.id
 | 
											userId: this.user.id
 | 
				
			||||||
					});
 | 
										});
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					if (this.user.isLocked && this.user.hasPendingFollowRequestFromYou) {
 | 
										if (this.user.hasPendingFollowRequestFromYou) {
 | 
				
			||||||
						this.user = await (this as any).api('following/requests/cancel', {
 | 
											this.user = await (this as any).api('following/requests/cancel', {
 | 
				
			||||||
							userId: this.user.id
 | 
												userId: this.user.id
 | 
				
			||||||
						});
 | 
											});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,13 +55,15 @@ export default Vue.extend({
 | 
				
			||||||
	methods: {
 | 
						methods: {
 | 
				
			||||||
		onFollow(user) {
 | 
							onFollow(user) {
 | 
				
			||||||
			if (user.id == this.u.id) {
 | 
								if (user.id == this.u.id) {
 | 
				
			||||||
				this.user.isFollowing = user.isFollowing;
 | 
									this.u.isFollowing = user.isFollowing;
 | 
				
			||||||
 | 
									this.u.hasPendingFollowRequestFromYou = user.hasPendingFollowRequestFromYou;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		onUnfollow(user) {
 | 
							onUnfollow(user) {
 | 
				
			||||||
			if (user.id == this.u.id) {
 | 
								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
 | 
											userId: this.u.id
 | 
				
			||||||
					});
 | 
										});
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					if (this.u.isLocked && this.u.hasPendingFollowRequestFromYou) {
 | 
										if (this.u.hasPendingFollowRequestFromYou) {
 | 
				
			||||||
						this.u = await (this as any).api('following/requests/cancel', {
 | 
											this.u = await (this as any).api('following/requests/cancel', {
 | 
				
			||||||
							userId: this.u.id
 | 
												userId: this.u.id
 | 
				
			||||||
						});
 | 
											});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,12 +48,14 @@ export default Vue.extend({
 | 
				
			||||||
		onFollow(user) {
 | 
							onFollow(user) {
 | 
				
			||||||
			if (user.id == this.u.id) {
 | 
								if (user.id == this.u.id) {
 | 
				
			||||||
				this.u.isFollowing = user.isFollowing;
 | 
									this.u.isFollowing = user.isFollowing;
 | 
				
			||||||
 | 
									this.u.hasPendingFollowRequestFromYou = user.hasPendingFollowRequestFromYou;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		onUnfollow(user) {
 | 
							onUnfollow(user) {
 | 
				
			||||||
			if (user.id == this.u.id) {
 | 
								if (user.id == this.u.id) {
 | 
				
			||||||
				this.u.isFollowing = user.isFollowing;
 | 
									this.u.isFollowing = user.isFollowing;
 | 
				
			||||||
 | 
									this.u.hasPendingFollowRequestFromYou = user.hasPendingFollowRequestFromYou;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,7 +68,7 @@ export default Vue.extend({
 | 
				
			||||||
						userId: this.u.id
 | 
											userId: this.u.id
 | 
				
			||||||
					});
 | 
										});
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					if (this.u.isLocked && this.u.hasPendingFollowRequestFromYou) {
 | 
										if (this.u.hasPendingFollowRequestFromYou) {
 | 
				
			||||||
						this.u = await (this as any).api('following/requests/cancel', {
 | 
											this.u = await (this as any).api('following/requests/cancel', {
 | 
				
			||||||
							userId: this.u.id
 | 
												userId: this.u.id
 | 
				
			||||||
						});
 | 
											});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -432,10 +432,10 @@ export const pack = (
 | 
				
			||||||
				followerId: _user.id,
 | 
									followerId: _user.id,
 | 
				
			||||||
				followeeId: meId
 | 
									followeeId: meId
 | 
				
			||||||
			}),
 | 
								}),
 | 
				
			||||||
			_user.isLocked ? FollowRequest.findOne({
 | 
								FollowRequest.findOne({
 | 
				
			||||||
				followerId: meId,
 | 
									followerId: meId,
 | 
				
			||||||
				followeeId: _user.id
 | 
									followeeId: _user.id
 | 
				
			||||||
			}) : Promise.resolve(null),
 | 
								}),
 | 
				
			||||||
			FollowRequest.findOne({
 | 
								FollowRequest.findOne({
 | 
				
			||||||
				followerId: _user.id,
 | 
									followerId: _user.id,
 | 
				
			||||||
				followeeId: meId
 | 
									followeeId: meId
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@ import { deliver } from '../../queue';
 | 
				
			||||||
import createFollowRequest from './requests/create';
 | 
					import createFollowRequest from './requests/create';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default async function(follower: IUser, followee: IUser) {
 | 
					export default async function(follower: IUser, followee: IUser) {
 | 
				
			||||||
	if (followee.isLocked) {
 | 
						if (followee.isLocked || isLocalUser(follower) && isRemoteUser(followee)) {
 | 
				
			||||||
		await createFollowRequest(follower, followee);
 | 
							await createFollowRequest(follower, followee);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		const following = await Following.insert({
 | 
							const following = await Following.insert({
 | 
				
			||||||
| 
						 | 
					@ -72,11 +72,6 @@ export default async function(follower: IUser, followee: IUser) {
 | 
				
			||||||
			notify(followee._id, follower._id, 'follow');
 | 
								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)) {
 | 
							if (isRemoteUser(follower) && isLocalUser(followee)) {
 | 
				
			||||||
			const content = pack(renderAccept(renderFollow(follower, followee)));
 | 
								const content = pack(renderAccept(renderFollow(follower, followee)));
 | 
				
			||||||
			deliver(followee, content, follower.inbox);
 | 
								deliver(followee, content, follower.inbox);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -75,4 +75,6 @@ export default async function(followee: IUser, follower: IUser) {
 | 
				
			||||||
	packUser(followee, followee, {
 | 
						packUser(followee, followee, {
 | 
				
			||||||
		detail: true
 | 
							detail: true
 | 
				
			||||||
	}).then(packed => publishUserStream(followee._id, 'meUpdated', packed));
 | 
						}).then(packed => publishUserStream(followee._id, 'meUpdated', packed));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						packUser(followee, follower).then(packed => publishUserStream(follower._id, 'follow', packed));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,8 +7,6 @@ import { deliver } from '../../../queue';
 | 
				
			||||||
import FollowRequest from '../../../models/follow-request';
 | 
					import FollowRequest from '../../../models/follow-request';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default async function(follower: IUser, followee: IUser) {
 | 
					export default async function(follower: IUser, followee: IUser) {
 | 
				
			||||||
	if (!followee.isLocked) throw '対象のアカウントは鍵アカウントではありません';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	await FollowRequest.insert({
 | 
						await FollowRequest.insert({
 | 
				
			||||||
		createdAt: new Date(),
 | 
							createdAt: new Date(),
 | 
				
			||||||
		followerId: follower._id,
 | 
							followerId: follower._id,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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 FollowRequest from '../../../models/follow-request';
 | 
				
			||||||
import pack from '../../../remote/activitypub/renderer';
 | 
					import pack from '../../../remote/activitypub/renderer';
 | 
				
			||||||
import renderFollow from '../../../remote/activitypub/renderer/follow';
 | 
					import renderFollow from '../../../remote/activitypub/renderer/follow';
 | 
				
			||||||
import renderReject from '../../../remote/activitypub/renderer/reject';
 | 
					import renderReject from '../../../remote/activitypub/renderer/reject';
 | 
				
			||||||
import { deliver } from '../../../queue';
 | 
					import { deliver } from '../../../queue';
 | 
				
			||||||
 | 
					import { publishUserStream } from '../../../stream';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default async function(followee: IUser, follower: IUser) {
 | 
					export default async function(followee: IUser, follower: IUser) {
 | 
				
			||||||
	if (isRemoteUser(follower)) {
 | 
						if (isRemoteUser(follower)) {
 | 
				
			||||||
| 
						 | 
					@ -21,4 +22,6 @@ export default async function(followee: IUser, follower: IUser) {
 | 
				
			||||||
			pendingReceivedFollowRequestsCount: -1
 | 
								pendingReceivedFollowRequestsCount: -1
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						packUser(followee, follower).then(packed => publishUserStream(follower._id, 'unfollow', packed));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue