From e580b92c37f27c2849c6d27e22ca4c47086081bb Mon Sep 17 00:00:00 2001 From: Lhc_fl Date: Sun, 6 Oct 2024 19:12:13 +0800 Subject: [PATCH] ux: should not show follow requests tab when have no pending sent follow req --- packages/backend/src/core/entities/UserEntityService.ts | 8 ++++++++ packages/backend/src/models/json-schema/user.ts | 4 ++++ packages/backend/test/e2e/users.ts | 2 ++ packages/frontend/src/navbar.ts | 1 + packages/frontend/src/pages/follow-requests.vue | 3 ++- packages/misskey-js/src/autogen/types.ts | 1 + 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts index d3c087a15376..9c1e4abbb8ed 100644 --- a/packages/backend/src/core/entities/UserEntityService.ts +++ b/packages/backend/src/core/entities/UserEntityService.ts @@ -365,6 +365,13 @@ export class UserEntityService implements OnModuleInit { return count > 0; } + @bindThis + public async getHasPendingSentFollowRequest(userId: MiUser['id']): Promise { + return this.followRequestsRepository.existsBy({ + followerId: userId, + }); + } + @bindThis public getOnlineStatus(user: MiUser): 'unknown' | 'online' | 'active' | 'offline' { if (user.hideOnlineStatus) return 'unknown'; @@ -602,6 +609,7 @@ export class UserEntityService implements OnModuleInit { hasUnreadChannel: false, // 後方互換性のため hasUnreadNotification: notificationsInfo?.hasUnread, // 後方互換性のため hasPendingReceivedFollowRequest: this.getHasPendingReceivedFollowRequest(user.id), + hasPendingSentFollowRequest: this.getHasPendingSentFollowRequest(user.id), unreadNotificationsCount: notificationsInfo?.unreadCount, mutedWords: profile!.mutedWords, hardMutedWords: profile!.hardMutedWords, diff --git a/packages/backend/src/models/json-schema/user.ts b/packages/backend/src/models/json-schema/user.ts index 38631f907dd5..72eb64c12828 100644 --- a/packages/backend/src/models/json-schema/user.ts +++ b/packages/backend/src/models/json-schema/user.ts @@ -548,6 +548,10 @@ export const packedMeDetailedOnlySchema = { type: 'boolean', nullable: false, optional: false, }, + hasPendingSentFollowRequest: { + type: 'boolean', + nullable: false, optional: false, + }, unreadNotificationsCount: { type: 'number', nullable: false, optional: false, diff --git a/packages/backend/test/e2e/users.ts b/packages/backend/test/e2e/users.ts index 822ca14ae6c3..218c32777b83 100644 --- a/packages/backend/test/e2e/users.ts +++ b/packages/backend/test/e2e/users.ts @@ -135,6 +135,7 @@ describe('ユーザー', () => { hasUnreadNotification: user.hasUnreadNotification, unreadNotificationsCount: user.unreadNotificationsCount, hasPendingReceivedFollowRequest: user.hasPendingReceivedFollowRequest, + hasPendingSentFollowRequest: user.hasPendingSentFollowRequest, unreadAnnouncements: user.unreadAnnouncements, mutedWords: user.mutedWords, hardMutedWords: user.hardMutedWords, @@ -372,6 +373,7 @@ describe('ユーザー', () => { assert.strictEqual(response.hasUnreadNotification, false); assert.strictEqual(response.unreadNotificationsCount, 0); assert.strictEqual(response.hasPendingReceivedFollowRequest, false); + assert.strictEqual(response.hasPendingSentFollowRequest, false); assert.deepStrictEqual(response.unreadAnnouncements, []); assert.deepStrictEqual(response.mutedWords, []); assert.deepStrictEqual(response.mutedInstances, []); diff --git a/packages/frontend/src/navbar.ts b/packages/frontend/src/navbar.ts index 096d404a572f..21ff61e49e6f 100644 --- a/packages/frontend/src/navbar.ts +++ b/packages/frontend/src/navbar.ts @@ -40,6 +40,7 @@ export const navbarItemDef = reactive({ followRequests: { title: i18n.ts.followRequests, icon: 'ti ti-user-plus', + show: computed(() => $i != null && ($i.isLocked || $i.hasPendingSentFollowRequest)), indicated: computed(() => $i != null && $i.hasPendingReceivedFollowRequest), to: '/my/follow-requests', }, diff --git a/packages/frontend/src/pages/follow-requests.vue b/packages/frontend/src/pages/follow-requests.vue index 78558b11ed0c..3d03579bddf6 100644 --- a/packages/frontend/src/pages/follow-requests.vue +++ b/packages/frontend/src/pages/follow-requests.vue @@ -50,6 +50,7 @@ import { i18n } from '@/i18n.js'; import { definePageMetadata } from '@/scripts/page-metadata.js'; import { infoImageUrl } from '@/instance.js'; import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue'; +import { $i } from '@/account'; const paginationComponent = shallowRef>(); @@ -94,7 +95,7 @@ const headerTabs = computed(() => [ }, ]); -const tab = ref('list'); +const tab = ref($i?.hasPendingSentFollowRequest ? 'sent' : 'list'); definePageMetadata(() => ({ title: i18n.ts.followRequests, diff --git a/packages/misskey-js/src/autogen/types.ts b/packages/misskey-js/src/autogen/types.ts index d09952e1094e..26ecafa1449b 100644 --- a/packages/misskey-js/src/autogen/types.ts +++ b/packages/misskey-js/src/autogen/types.ts @@ -3860,6 +3860,7 @@ export type components = { hasUnreadChannel: boolean; hasUnreadNotification: boolean; hasPendingReceivedFollowRequest: boolean; + hasPendingSentFollowRequest: boolean; unreadNotificationsCount: number; mutedWords: string[][]; hardMutedWords: string[][];