Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 照会まわりの修正 #13342

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-

### Server
-
- Fix: ローカルユーザーをMisskey WebのURL(`/@user`)で照会できない問題を修正


## 2024.5.0
Expand Down Expand Up @@ -68,6 +68,7 @@
- Enhance: コントロールパネルのクイックアクションから通常の照会を行えるように
- Fix: 一部のページ内リンクが正しく動作しない問題を修正
- Fix: 周年の実績が閏年を考慮しない問題を修正
- Fix: ノートの検索欄にURLを入れると勝手に照会される問題を修正
- Fix: ローカルURLのプレビューポップアップが左上に表示される
- Fix: WebGL2をサポートしないブラウザで「季節に応じた画面の演出」が有効になっているとき、Misskeyが起動できなくなる問題を修正
(Cherry-picked from https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/459)
Expand Down
4 changes: 4 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4984,6 +4984,10 @@ export interface Locale extends ILocale {
* お問い合わせ
*/
"inquiry": string;
/**
* URLを検知しました。照会しますか?
*/
"searchOrLookup": string;
"_delivery": {
/**
* 配信状態
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,7 @@ keepOriginalFilenameDescription: "この設定をオフにすると、アップ
noDescription: "説明文はありません"
alwaysConfirmFollow: "フォローの際常に確認する"
inquiry: "お問い合わせ"
searchOrLookup: "URLを検知しました。照会しますか?"

_delivery:
status: "配信状態"
Expand Down
15 changes: 15 additions & 0 deletions packages/backend/src/core/activitypub/ApDbResolverService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ export class ApDbResolverService implements OnApplicationShutdown {
const uri = new URL(getApId(value));
if (uri.origin !== this.config.url) return { local: false, uri: uri.href };

if (uri.pathname.slice(1, 2) === '@') {
const [, username, ...rest] = uri.pathname.split(separator);
return {
local: true,
type: '__ui_user__',
id: username,
rest: rest.length === 0 ? undefined : rest.join(separator),
};
}

const [, type, id, ...rest] = uri.pathname.split(separator);
return {
local: true,
Expand Down Expand Up @@ -102,6 +112,11 @@ export class ApDbResolverService implements OnApplicationShutdown {
const parsed = this.parseUri(value);

if (parsed.local) {
if (parsed.type === '__ui_user__') {
const [, username, host] = parsed.id.split('@');
return await this.usersRepository.findOneBy({ username, host, isDeleted: false }) as MiLocalUser | undefined ?? null;
}

if (parsed.type !== 'users') return null;

return await this.cacheService.userByIdCache.fetchMaybe(
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/core/activitypub/ApResolverService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ export class Resolver {
}
return this.apRendererService.addContext(this.apRendererService.renderFollow(follower as MiLocalUser | MiRemoteUser, followee as MiLocalUser | MiRemoteUser, url));
});
case '__ui_user__': {
const [, username, host] = parsed.id.split('@');
return this.usersRepository.findOneByOrFail({ username, host, isDeleted: false })
.then(user => this.apRendererService.renderPerson(user as MiLocalUser));
}
default:
throw new Error(`resolveLocal: type ${parsed.type} unhandled`);
}
Expand Down
50 changes: 33 additions & 17 deletions packages/frontend/src/pages/search.note.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,17 @@ 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 { doLookup } from '@/scripts/lookup.js';
import MkFoldableSection from '@/components/MkFoldableSection.vue';
import MkFolder from '@/components/MkFolder.vue';
import { useRouter } from '@/router/supplier.js';

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 isSearching = ref(false);

function selectUser() {
os.selectUser({ includeSelf: true }).then(_user => {
Expand All @@ -70,26 +68,43 @@ function selectUser() {
}

async function search() {
if (isSearching.value) return;
isSearching.value = true;

const query = searchQuery.value.toString().trim();

if (query == null || query === '') return;
if (query == null || query === '') {
isSearching.value = false;
return;
}

if (query.startsWith('https://')) {
const promise = misskeyApi('ap/show', {
uri: query,
if (query.startsWith('https://') || query.startsWith('http://')) {
const confirm = await os.actions({
type: 'question',
text: i18n.ts.searchOrLookup,
actions: [
{
text: i18n.ts.lookup,
primary: true,
value: 'lookup' as const,
},
{
text: i18n.ts.search,
value: 'search' as const,
},
],
});

os.promiseDialog(promise, null, null, i18n.ts.fetchingAsApObject);

const res = await promise;

if (res.type === 'User') {
router.push(`/@${res.object.username}@${res.object.host}`);
} else if (res.type === 'Note') {
router.push(`/notes/${res.object.id}`);
if (confirm.canceled) {
isSearching.value = false;
return;
}

return;
if (confirm.result === 'lookup') {
await doLookup(query);
isSearching.value = false;
return;
}
}

notePagination.value = {
Expand All @@ -104,5 +119,6 @@ async function search() {
if (isLocalOnly.value) notePagination.value.params.host = '.';

key.value++;
isSearching.value = false;
}
</script>
16 changes: 11 additions & 5 deletions packages/frontend/src/scripts/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ import { Router } from '@/nirax.js';
import { mainRouter } from '@/router/main.js';

export async function lookup(router?: Router) {
const _router = router ?? mainRouter;

const { canceled, result: temp } = await os.inputText({
title: i18n.ts.lookup,
});
const query = temp ? temp.trim() : '';

if (canceled) return;

await doLookup(temp, router);
}

export async function doLookup(url: string, router?: Router) {
const _router = router ?? mainRouter;

const query = url ? url.trim() : '';

if (query.startsWith('@') && !query.includes(' ')) {
_router.push(`/${query}`);
return;
Expand All @@ -28,7 +34,7 @@ export async function lookup(router?: Router) {
return;
}

if (query.startsWith('https://')) {
if (query.startsWith('https://') || query.startsWith('http://')) {
const promise = misskeyApi('ap/show', {
uri: query,
});
Expand All @@ -38,7 +44,7 @@ export async function lookup(router?: Router) {
const res = await promise;

if (res.type === 'User') {
_router.push(`/@${res.object.username}@${res.object.host}`);
_router.push(res.object.host ? `/@${res.object.username}@${res.object.host}` : `/@${res.object.username}`);
} else if (res.type === 'Note') {
_router.push(`/notes/${res.object.id}`);
}
Expand Down
Loading