From b11e4053db5b73f793029acaf2daecc3ef2ef27b Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Thu, 22 Dec 2022 16:41:06 -0500 Subject: [PATCH 1/6] server: use named export for acceptFollowRequest --- .../src/remote/activitypub/kernel/accept/follow.ts | 4 ++-- .../server/api/endpoints/following/requests/accept.ts | 2 +- .../src/services/following/requests/accept-all.ts | 4 ++-- .../backend/src/services/following/requests/accept.ts | 9 +++++++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/remote/activitypub/kernel/accept/follow.ts b/packages/backend/src/remote/activitypub/kernel/accept/follow.ts index 58249d2de..037f660c6 100644 --- a/packages/backend/src/remote/activitypub/kernel/accept/follow.ts +++ b/packages/backend/src/remote/activitypub/kernel/accept/follow.ts @@ -1,5 +1,5 @@ import { CacheableRemoteUser } from '@/models/entities/user.js'; -import accept from '@/services/following/requests/accept.js'; +import { acceptFollowRequest } from '@/services/following/requests/accept.js'; import { relayAccepted } from '@/services/relay.js'; import { IFollow } from '@/remote/activitypub/type.js'; import { DbResolver } from '@/remote/activitypub/db-resolver.js'; @@ -24,6 +24,6 @@ export default async (actor: CacheableRemoteUser, activity: IFollow): Promise { const request = await FollowRequests.findOneBy({ followeeId: followee.id, followerId: follower.id, From 2204adc6576b3bd7abe1de667ac124e4f3a745b3 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Thu, 22 Dec 2022 16:41:27 -0500 Subject: [PATCH 2/6] server: use named export for acceptAllFollowRequests --- packages/backend/src/server/api/endpoints/i/update.ts | 2 +- .../backend/src/services/following/requests/accept-all.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index 57c349803..d73f2111a 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -2,7 +2,7 @@ import RE2 from 're2'; import * as mfm from 'mfm-js'; import { notificationTypes } from 'foundkey-js'; import { publishMainStream, publishUserEvent } from '@/services/stream.js'; -import acceptAllFollowRequests from '@/services/following/requests/accept-all.js'; +import { acceptAllFollowRequests } from '@/services/following/requests/accept-all.js'; import { publishToFollowers } from '@/services/i/update.js'; import { extractCustomEmojisFromMfm } from '@/misc/extract-custom-emojis-from-mfm.js'; import { extractHashtags } from '@/misc/extract-hashtags.js'; diff --git a/packages/backend/src/services/following/requests/accept-all.ts b/packages/backend/src/services/following/requests/accept-all.ts index 58b15af01..ccc608c28 100644 --- a/packages/backend/src/services/following/requests/accept-all.ts +++ b/packages/backend/src/services/following/requests/accept-all.ts @@ -3,10 +3,10 @@ import { FollowRequests, Users } from '@/models/index.js'; import { acceptFollowRequest } from './accept.js'; /** - * 指定したユーザー宛てのフォローリクエストをすべて承認 - * @param user ユーザー + * Approve all follow requests addressed to the specified user. + * @param user The user whom to accept all follow requests to */ -export default async function(user: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }) { +export async function acceptAllFollowRequests(user: User): Promise { const requests = await FollowRequests.findBy({ followeeId: user.id, }); From 28f65bebfcea728a4c1755eb4621048cb6de08a3 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Thu, 22 Dec 2022 16:43:38 -0500 Subject: [PATCH 3/6] server: use named export for cancelFollowRequest --- packages/backend/src/remote/activitypub/kernel/undo/follow.ts | 4 ++-- .../src/server/api/endpoints/following/requests/cancel.ts | 2 +- packages/backend/src/services/following/requests/cancel.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/remote/activitypub/kernel/undo/follow.ts b/packages/backend/src/remote/activitypub/kernel/undo/follow.ts index b2607351a..d6f334e52 100644 --- a/packages/backend/src/remote/activitypub/kernel/undo/follow.ts +++ b/packages/backend/src/remote/activitypub/kernel/undo/follow.ts @@ -1,5 +1,5 @@ import unfollow from '@/services/following/delete.js'; -import cancelRequest from '@/services/following/requests/cancel.js'; +import { cancelFollowRequest } from '@/services/following/requests/cancel.js'; import { CacheableRemoteUser } from '@/models/entities/user.js'; import { FollowRequests, Followings } from '@/models/index.js'; import { IFollow } from '@/remote/activitypub/type.js'; @@ -29,7 +29,7 @@ export default async (actor: CacheableRemoteUser, activity: IFollow): Promise { if (Users.isRemoteUser(followee)) { const content = renderActivity(renderUndo(renderFollow(follower, followee), follower)); From a3354904af6c706dace83c789e29afb1170fb9f1 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Thu, 22 Dec 2022 16:45:25 -0500 Subject: [PATCH 4/6] server: use named export for createFollowRequest --- packages/backend/src/services/following/create.ts | 2 +- packages/backend/src/services/following/requests/create.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/services/following/create.ts b/packages/backend/src/services/following/create.ts index b866c8383..a4f546266 100644 --- a/packages/backend/src/services/following/create.ts +++ b/packages/backend/src/services/following/create.ts @@ -15,7 +15,7 @@ import { getActiveWebhooks } from '@/misc/webhook-cache.js'; import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc.js'; import Logger from '../logger.js'; import { createNotification } from '../create-notification.js'; -import createFollowRequest from './requests/create.js'; +import { createFollowRequest } from './requests/create.js'; const logger = new Logger('following/create'); diff --git a/packages/backend/src/services/following/requests/create.ts b/packages/backend/src/services/following/requests/create.ts index e8971ba57..bfcc2fd5e 100644 --- a/packages/backend/src/services/following/requests/create.ts +++ b/packages/backend/src/services/following/requests/create.ts @@ -7,7 +7,7 @@ import { Blockings, FollowRequests, Users } from '@/models/index.js'; import { genId } from '@/misc/gen-id.js'; import { createNotification } from '@/services/create-notification.js'; -export default async function(follower: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }, followee: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }, requestId?: string) { +export async function createFollowRequest(follower: User, followee: User, requestId?: string): Promise { if (follower.id === followee.id) return; // check blocking From 549302e9c02c6f9e1dc60828425f637b78d453d8 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Thu, 22 Dec 2022 16:54:55 -0500 Subject: [PATCH 5/6] server: add doc for createFollowRequest --- packages/backend/src/services/following/requests/create.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/backend/src/services/following/requests/create.ts b/packages/backend/src/services/following/requests/create.ts index bfcc2fd5e..81fec5fe4 100644 --- a/packages/backend/src/services/following/requests/create.ts +++ b/packages/backend/src/services/following/requests/create.ts @@ -7,6 +7,12 @@ import { Blockings, FollowRequests, Users } from '@/models/index.js'; import { genId } from '@/misc/gen-id.js'; import { createNotification } from '@/services/create-notification.js'; +/** + * Make a follow request from `follower` to `followee`. + * @param follower User making the follow request + * @param followee User to make the follow request to + * @param requestId Follow request ID + */ export async function createFollowRequest(follower: User, followee: User, requestId?: string): Promise { if (follower.id === followee.id) return; From 4db25e4b1fb0126de796effae73670bf78091ab5 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Thu, 22 Dec 2022 16:50:46 -0500 Subject: [PATCH 6/6] server: add doc for cancelFollowRequest --- packages/backend/src/services/following/requests/cancel.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/backend/src/services/following/requests/cancel.ts b/packages/backend/src/services/following/requests/cancel.ts index b3e64c4f4..999ebc64e 100644 --- a/packages/backend/src/services/following/requests/cancel.ts +++ b/packages/backend/src/services/following/requests/cancel.ts @@ -7,6 +7,11 @@ import { IdentifiableError } from '@/misc/identifiable-error.js'; import { User } from '@/models/entities/user.js'; import { Users, FollowRequests } from '@/models/index.js'; +/** + * Cancel a follow request from `follower` to `followee`. + * @param followee User that was going to be followed + * @param follower User who is making the follow request + */ export async function cancelFollowRequest(followee: User, follower: User): Promise { if (Users.isRemoteUser(followee)) { const content = renderActivity(renderUndo(renderFollow(follower, followee), follower));