feat: このユーザーのノートを検索, クエリに基づく検索の初期値 & ノート検索のUI改善 (#14128)

* refactor(frontend): noteSearchAvailableをaccountsに移動

* feat: searchページでのクエリの受取りとtypeによる表示タブの変更

* user検索でsearchの親から受け取った値を基に入力値を初期化

* feat(frontend): ノート検索で親(search)からの情報を基にユーザー情報を取得

* feat(frontend): ユーザーのノートを検索するページに遷移するボタン

* feat(frontend): ノート検索にホスト名指定のオプション追加
also 🎨

* style: ただ照会部分を囲っただけ(可読性確保のために)

* refactor: remove unneed import
defineProps and withDefaults are compiler micro when using `<script setup>`
FYI: https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits:~:text=defineProps%20and%20defineEmits%20are%20compiler%20macros%20only%20usable%20inside%20%3Cscript%20setup%3E.%20They%20do%20not%20need%20to%20be%20imported%2C%20and%20are%20compiled%20away%20when%20%3Cscript%20setup%3E%20is%20processed.

* Update CHANGELOG

* Fix: ノート検索の初期値が常にホスト指定になってしまう

* notesSearchAvailableをaccountに持たせるのをやめる

* SDPX-Licence-Identifier

* Fix: Vitest fails due to instance.policies being undefined

* Add Storybook for search

* Fix(storybook): ノート検索が利用できないと出てしまう問題

* storybookでユーザー選択ができないのを修正

* feat: ノート検索で自分を選択可能に
& 🎨

* feat(background): api/metaで検索可能なノートのスコープを参照できるように

* globalのノートが検索不可能な場合、検索オプションを表示しないように

* Update CHANGELOG.md

* config.meilisearch.scopeがstring[]を取ることがあるので修正

* meilisearchを利用かつscopeがlocalの場合、リモートユーザーのメニューで「このユーザーのノートを検索」を出さないように

* hostが空文字の時の挙動を修正

* ローカルのみしかノートがインデックスされていない場合、リモートユーザーも選択できなくした
This commit is contained in:
taichan 2024-07-30 15:51:08 +09:00 committed by GitHub
parent 7e9c38d6fb
commit bff813042e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 327 additions and 37 deletions

View File

@ -15,6 +15,9 @@
- Fix: デフォルトテーマに無効なテーマコードを入力するとUIが使用できなくなる問題を修正
### Client
- Feat: ユーザーページから「このユーザーのノートを検索」できるように (#14128)
- Feat: 検索ページはクエリを受け付けるようになりました (#14128)
- Enhance: 検索ページのUI改善 (#14128)
- Enhance: 内蔵APIドキュメントのデザイン・パフォーマンスを改善
- Enhance: 非ログイン時に他サーバーに遷移するアクションを追加
- Enhance: 非ログイン時のハイライトTLのデザインを改善
@ -61,6 +64,7 @@
- Enhance: エンドポイント`i/webhook/update`の必須項目を`webhookId`のみに
- Enhance: エンドポイント`admin/ad/update`の必須項目を`id`のみに
- Enhance: `default.yml`内の`url`, `db.db`, `db.user`, `db.pass`を環境変数から読み込めるように
- Enhance: エンドポイント`api/meta`にプロパティ`noteSearchableScope`が増え、`string`値`local`または`global`を返却します
- Fix: チャート生成時にinstance.suspensionStateに置き換えられたinstance.isSuspendedが参照されてしまう問題を修正
- Fix: ユーザーのフィードページのMFMをHTMLに展開するように (#14006)
- Fix: アンテナ・クリップ・リスト・ウェブフックがロールポリシーの上限より一つ多く作れてしまうのを修正 (#14036)

12
locales/index.d.ts vendored
View File

@ -256,6 +256,10 @@ export interface Locale extends ILocale {
*
*/
"searchUser": string;
/**
*
*/
"searchThisUsersNotes": string;
/**
*
*/
@ -796,6 +800,10 @@ export interface Locale extends ILocale {
*
*/
"host": string;
/**
*
*/
"selectSelf": string;
/**
*
*/
@ -4492,6 +4500,10 @@ export interface Locale extends ILocale {
*
*/
"specifyUser": string;
/**
*
*/
"specifyHost": string;
/**
*
*/

View File

@ -60,6 +60,7 @@ copyFileId: "ファイルIDをコピー"
copyFolderId: "フォルダーIDをコピー"
copyProfileUrl: "プロフィールURLをコピー"
searchUser: "ユーザーを検索"
searchThisUsersNotes: "ユーザーのノートを検索"
reply: "返信"
loadMore: "もっと見る"
showMore: "もっと見る"
@ -195,6 +196,7 @@ followConfirm: "{name}をフォローしますか?"
proxyAccount: "プロキシアカウント"
proxyAccountDescription: "プロキシアカウントは、特定の条件下でユーザーのリモートフォローを代行するアカウントです。例えば、ユーザーがリモートユーザーをリストに入れたとき、リストに入れられたユーザーを誰もフォローしていないとアクティビティがサーバーに配達されないため、代わりにプロキシアカウントがフォローするようにします。"
host: "ホスト"
selectSelf: "自分を選択"
selectUser: "ユーザーを選択"
recipient: "宛先"
annotation: "注釈"
@ -1119,6 +1121,7 @@ preventAiLearning: "生成AIによる学習を拒否"
preventAiLearningDescription: "外部の文章生成AIや画像生成AIに対して、投稿したートや画像などのコンテンツを学習の対象にしないように要求します。これはnoaiフラグをHTMLレスポンスに含めることによって実現されますが、この要求に従うかはそのAI次第であるため、学習を完全に防止するものではありません。"
options: "オプション"
specifyUser: "ユーザー指定"
specifyHost: "ホスト指定"
failedToPreviewUrl: "プレビューできません"
update: "更新"
rolesThatCanBeUsedThisEmojiAsReaction: "リアクションとして使えるロール"

View File

@ -128,6 +128,7 @@ export class MetaEntityService {
mediaProxy: this.config.mediaProxy,
enableUrlPreview: instance.urlPreviewEnabled,
noteSearchableScope: this.config.meilisearch == null || this.config.meilisearch.scope === 'local' ? 'local' : 'global',
};
return packed;

View File

@ -247,6 +247,12 @@ export const packedMetaLiteSchema = {
optional: false, nullable: false,
ref: 'RolePolicies',
},
noteSearchableScope: {
type: 'string',
enum: ['local', 'global'],
optional: false, nullable: false,
default: 'local',
},
},
} as const;

View File

@ -154,7 +154,7 @@ export function federationInstance(): entities.FederationInstance {
};
}
export function userDetailed(id = 'someuserid', username = 'miskist', host = 'misskey-hub.net', name = 'Misskey User'): entities.UserDetailed {
export function userDetailed(id = 'someuserid', username = 'miskist', host:entities.UserDetailed['host'] = 'misskey-hub.net', name:entities.UserDetailed['name'] = 'Misskey User'): entities.UserDetailed {
return {
id,
username,

View File

@ -405,6 +405,7 @@ function toStories(component: string): Promise<string> {
glob('src/components/MkUserSetupDialog.*.vue'),
glob('src/components/MkInstanceCardMini.vue'),
glob('src/components/MkInviteCode.vue'),
glob('src/pages/search.vue'),
glob('src/pages/user/home.vue'),
]);
const components = globs.flat();

View File

@ -29,6 +29,9 @@ export default defineComponent({
// Fragment
if (options.length === 1 && options[0].props == null) options = options[0].children as VNode[];
// vnodev-if=false(trueoptiontype)
options = options.filter(vnode => !(typeof vnode.type === 'symbol' && vnode.type.description === 'v-cmt' && vnode.children === 'v-if'));
return () => h('div', {
class: 'novjtcto',
}, [
@ -40,6 +43,7 @@ export default defineComponent({
}, options.map(option => h(MkRadio, {
key: option.key as string,
value: option.props?.value,
disabled: option.props?.disabled,
modelValue: value.value,
'onUpdate:modelValue': _v => value.value = _v,
}, () => option.children)),

View File

@ -9,26 +9,35 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkInput v-model="searchQuery" :large="true" :autofocus="true" type="search" @enter="search">
<template #prefix><i class="ti ti-search"></i></template>
</MkInput>
<MkFolder>
<template #label>{{ i18n.ts.options }}</template>
<MkFoldableSection :expanded="true">
<template #header>{{ i18n.ts.options }}</template>
<div class="_gaps_m">
<MkSwitch v-model="isLocalOnly">{{ i18n.ts.localOnly }}</MkSwitch>
<MkRadios v-model="hostSelect">
<template #label>{{ i18n.ts.host }}</template>
<option value="all" default>{{ i18n.ts.all }}</option>
<option value="local">{{ i18n.ts.local }}</option>
<option v-if="noteSearchableScope === 'global'" value="specified">{{ i18n.ts.specifyHost }}</option>
</MkRadios>
<MkInput v-if="noteSearchableScope === 'global'" v-model="hostInput" :disabled="hostSelect !== 'specified'" :large="true" type="search">
<template #prefix><i class="ti ti-server"></i></template>
</MkInput>
<MkFolder :defaultOpen="true">
<template #label>{{ i18n.ts.specifyUser }}</template>
<template v-if="user" #suffix>@{{ user.username }}</template>
<template v-if="user" #suffix>@{{ user.username }}{{ user.host ? `@${user.host}` : "" }}</template>
<div style="text-align: center;" class="_gaps">
<div v-if="user">@{{ user.username }}</div>
<div>
<MkButton v-if="user == null" primary rounded inline @click="selectUser">{{ i18n.ts.selectUser }}</MkButton>
<MkButton v-else danger rounded inline @click="user = null">{{ i18n.ts.remove }}</MkButton>
<div class="_gaps">
<div :class="$style.userItem">
<MkUserCardMini v-if="user" :class="$style.userCard" :user="user" :withChart="false"/>
<MkButton v-if="user == null && $i != null" transparent :class="$style.addMeButton" @click="selectSelf"><div :class="$style.addUserButtonInner"><span><i class="ti ti-plus"></i><i class="ti ti-user"></i></span><span>{{ i18n.ts.selectSelf }}</span></div></MkButton>
<MkButton v-if="user == null" transparent :class="$style.addUserButton" @click="selectUser"><div :class="$style.addUserButtonInner"><i class="ti ti-plus"></i><span>{{ i18n.ts.selectUser }}</span></div></MkButton>
<button class="_button" :class="$style.remove" :disabled="user == null" @click="removeUser"><i class="ti ti-x"></i></button>
</div>
</div>
</MkFolder>
</div>
</MkFolder>
</MkFoldableSection>
<div>
<MkButton large primary gradate rounded style="margin: 0 auto;" @click="search">{{ i18n.ts.search }}</MkButton>
</div>
@ -42,31 +51,90 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { computed, ref, toRef, watch } from 'vue';
import type { UserDetailed } from 'misskey-js/entities.js';
import type { Paging } from '@/components/MkPagination.vue';
import MkNotes from '@/components/MkNotes.vue';
import MkInput from '@/components/MkInput.vue';
import MkButton from '@/components/MkButton.vue';
import MkSwitch from '@/components/MkSwitch.vue';
import { i18n } from '@/i18n.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import MkFoldableSection from '@/components/MkFoldableSection.vue';
import MkFolder from '@/components/MkFolder.vue';
import { useRouter } from '@/router/supplier.js';
import MkUserCardMini from '@/components/MkUserCardMini.vue';
import MkRadios from '@/components/MkRadios.vue';
import { $i } from '@/account.js';
import { instance } from '@/instance.js';
const props = withDefaults(defineProps<{
query?: string;
userId?: string;
username?: string;
host?: string | null;
}>(), {
query: '',
userId: undefined,
username: undefined,
host: '',
});
const router = useRouter();
const key = ref(0);
const searchQuery = ref('');
const searchOrigin = ref('combined');
const notePagination = ref();
const user = ref<any>(null);
const isLocalOnly = ref(false);
const searchQuery = ref(toRef(props, 'query').value);
const notePagination = ref<Paging>();
const user = ref<UserDetailed | null>(null);
const hostInput = ref(toRef(props, 'host').value);
function selectUser() {
os.selectUser({ includeSelf: true }).then(_user => {
const noteSearchableScope = instance.noteSearchableScope ?? 'local';
const hostSelect = ref<'all' | 'local' | 'specified'>('all');
const setHostSelectWithInput = (after:string|undefined|null, before:string|undefined|null) => {
if (before === after) return;
if (after === '') hostSelect.value = 'all';
else hostSelect.value = 'specified';
};
setHostSelectWithInput(hostInput.value, undefined);
watch(hostInput, setHostSelectWithInput);
const searchHost = computed(() => {
if (hostSelect.value === 'local') return '.';
if (hostSelect.value === 'specified') return hostInput.value;
return null;
});
if (props.userId != null) {
misskeyApi('users/show', { userId: props.userId }).then(_user => {
user.value = _user;
});
} else if (props.username != null) {
misskeyApi('users/show', {
username: props.username,
...(props.host != null && props.host !== '') ? { host: props.host } : {},
}).then(_user => {
user.value = _user;
});
}
function selectUser() {
os.selectUser({ includeSelf: true, localOnly: instance.noteSearchableScope === 'local' }).then(_user => {
user.value = _user;
hostInput.value = _user.host ?? '';
});
}
function selectSelf() {
user.value = $i as UserDetailed | null;
hostInput.value = null;
}
function removeUser() {
user.value = null;
hostInput.value = '';
}
async function search() {
@ -74,6 +142,7 @@ async function search() {
if (query == null || query === '') return;
//#region AP lookup
if (query.startsWith('https://')) {
const promise = misskeyApi('ap/show', {
uri: query,
@ -91,6 +160,7 @@ async function search() {
return;
}
//#endregion
notePagination.value = {
endpoint: 'notes/search',
@ -98,11 +168,49 @@ async function search() {
params: {
query: searchQuery.value,
userId: user.value ? user.value.id : null,
...(searchHost.value ? { host: searchHost.value } : {}),
},
};
if (isLocalOnly.value) notePagination.value.params.host = '.';
key.value++;
}
</script>
<style lang="scss" module>
.userItem {
display: flex;
justify-content: center;
}
.addMeButton {
border: 2px dashed var(--fgTransparent);
padding: 12px;
margin-right: 16px;
}
.addUserButton {
border: 2px dashed var(--fgTransparent);
padding: 12px;
flex-grow: 1;
}
.addUserButtonInner {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
min-height: 38px;
}
.userCard {
flex-grow: 1;
}
.remove {
width: 32px;
height: 32px;
align-self: center;
& > i:before {
color: #ff2a2a;
}
&:disabled {
opacity: 0;
}
}
</style>

View File

@ -0,0 +1,88 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { StoryObj } from '@storybook/vue3';
import { HttpResponse, http } from 'msw';
import search_ from './search.vue';
import { userDetailed } from '@/../.storybook/fakes.js';
import { commonHandlers } from '@/../.storybook/mocks.js';
const localUser = userDetailed('someuserid', 'miskist', null, 'Local Misskey User');
export const Default = {
render(args) {
return {
components: {
search_,
},
setup() {
return {
args,
};
},
computed: {
props() {
return {
...this.args,
};
},
},
template: '<search_ v-bind="props" />',
};
},
args: {
ignoreNotesSearchAvailable: true,
},
parameters: {
layout: 'fullscreen',
msw: {
handlers: [
...commonHandlers,
http.post('/api/users/show', () => {
return HttpResponse.json(userDetailed());
}),
http.post('/api/users/search', () => {
return HttpResponse.json([userDetailed(), localUser]);
}),
],
},
},
} satisfies StoryObj<typeof search_>;
export const NoteSearchDisabled = {
...Default,
args: {},
} satisfies StoryObj<typeof search_>;
export const WithUsernameLocal = {
...Default,
args: {
...Default.args,
username: localUser.username,
host: localUser.host,
},
parameters: {
layout: 'fullscreen',
msw: {
handlers: [
...commonHandlers,
http.post('/api/users/show', () => {
return HttpResponse.json(localUser);
}),
http.post('/api/users/search', () => {
return HttpResponse.json([userDetailed(), localUser]);
}),
],
},
},
} satisfies StoryObj<typeof search_>;
export const WithUserType = {
...Default,
args: {
type: 'user',
},
} satisfies StoryObj<typeof search_>;

View File

@ -25,7 +25,9 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { ref, toRef } from 'vue';
import type { Endpoints } from 'misskey-js';
import type { Paging } from '@/components/MkPagination.vue';
import MkUserList from '@/components/MkUserList.vue';
import MkInput from '@/components/MkInput.vue';
import MkRadios from '@/components/MkRadios.vue';
@ -36,18 +38,27 @@ import MkFoldableSection from '@/components/MkFoldableSection.vue';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { useRouter } from '@/router/supplier.js';
const props = withDefaults(defineProps<{
query?: string,
origin?: Endpoints['users/search']['req']['origin'],
}>(), {
query: '',
origin: 'combined',
});
const router = useRouter();
const key = ref('');
const searchQuery = ref('');
const searchOrigin = ref('combined');
const userPagination = ref();
const searchQuery = ref(toRef(props, 'query').value);
const searchOrigin = ref(toRef(props, 'origin').value);
const userPagination = ref<Paging>();
async function search() {
const query = searchQuery.value.toString().trim();
if (query == null || query === '') return;
//#region AP lookup
if (query.startsWith('https://')) {
const promise = misskeyApi('ap/show', {
uri: query,
@ -65,6 +76,7 @@ async function search() {
return;
}
//#endregion
userPagination.value = {
endpoint: 'users/search',

View File

@ -9,8 +9,8 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkHorizontalSwipe v-model:tab="tab" :tabs="headerTabs">
<MkSpacer v-if="tab === 'note'" key="note" :contentMax="800">
<div v-if="notesSearchAvailable">
<XNote/>
<div v-if="notesSearchAvailable || ignoreNotesSearchAvailable">
<XNote v-bind="props"/>
</div>
<div v-else>
<MkInfo warn>{{ i18n.ts.notesSearchNotAvailable }}</MkInfo>
@ -18,27 +18,43 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkSpacer>
<MkSpacer v-else-if="tab === 'user'" key="user" :contentMax="800">
<XUser/>
<XUser v-bind="props"/>
</MkSpacer>
</MkHorizontalSwipe>
</MkStickyContainer>
</template>
<script lang="ts" setup>
import { computed, defineAsyncComponent, ref } from 'vue';
import { computed, defineAsyncComponent, ref, toRef } from 'vue';
import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { $i } from '@/account.js';
import { instance } from '@/instance.js';
import { notesSearchAvailable } from '@/scripts/check-permissions.js';
import MkInfo from '@/components/MkInfo.vue';
import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue';
const props = withDefaults(defineProps<{
query?: string,
userId?: string,
username?: string,
host?: string | null,
type?: 'note' | 'user',
origin?: 'combined' | 'local' | 'remote',
// For storybook only
ignoreNotesSearchAvailable?: boolean,
}>(), {
query: '',
userId: undefined,
username: undefined,
host: undefined,
type: 'note',
origin: 'combined',
ignoreNotesSearchAvailable: false,
});
const XNote = defineAsyncComponent(() => import('./search.note.vue'));
const XUser = defineAsyncComponent(() => import('./search.user.vue'));
const tab = ref('note');
const notesSearchAvailable = (($i == null && instance.policies.canSearchNotes) || ($i != null && $i.policies.canSearchNotes));
const tab = ref(toRef(props, 'type').value);
const headerActions = computed(() => []);

View File

@ -232,6 +232,9 @@ const routes: RouteDef[] = [{
component: page(() => import('@/pages/search.vue')),
query: {
q: 'query',
userId: 'userId',
username: 'username',
host: 'host',
channel: 'channel',
type: 'type',
origin: 'origin',

View File

@ -0,0 +1,19 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { instance } from '@/instance.js';
import { $i } from '@/account.js';
export const notesSearchAvailable = (
// FIXME: instance.policies would be null in Vitest
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
($i == null && instance.policies != null && instance.policies.canSearchNotes) ||
($i != null && $i.policies.canSearchNotes) ||
false
) as boolean;
export const canSearchNonLocalNotes = (
instance.noteSearchableScope === 'global'
);

View File

@ -13,6 +13,7 @@ import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { defaultStore, userActions } from '@/store.js';
import { $i, iAmModerator } from '@/account.js';
import { notesSearchAvailable, canSearchNonLocalNotes } from '@/scripts/check-permissions.js';
import { IRouter } from '@/nirax.js';
import { antennasCache, rolesCache, userListsCache } from '@/cache.js';
import { mainRouter } from '@/router/main.js';
@ -160,7 +161,14 @@ export function getUserMenu(user: Misskey.entities.UserDetailed, router: IRouter
action: () => {
copyToClipboard(`@${user.username}@${user.host ?? host}`);
},
}, ...(iAmModerator ? [{
}, ...( notesSearchAvailable && (user.host == null || canSearchNonLocalNotes) ? [{
icon: 'ti ti-search',
text: i18n.ts.searchThisUsersNotes,
action: () => {
router.push(`/search?username=${encodeURIComponent(user.username)}${user.host != null ? '&host=' + encodeURIComponent(user.host) : ''}`);
},
}] : [])
, ...(iAmModerator ? [{
icon: 'ti ti-user-exclamation',
text: i18n.ts.moderation,
action: () => {

View File

@ -4939,6 +4939,11 @@ export type components = {
serverRules: string[];
themeColor: string | null;
policies: components['schemas']['RolePolicies'];
/**
* @default local
* @enum {string}
*/
noteSearchableScope: 'local' | 'global';
};
MetaDetailedOnly: {
features?: {