Skip to content

Commit

Permalink
絵文字インポート時に編集ダイアログを出す (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
kozakura913 authored Jul 28, 2024
1 parent f4b7e2b commit 03e5589
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_yojo.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ Cherrypick 4.9.0
- Fix: 引用とCWを併用した場合にタイムラインと詳細で表示が異なる不具合を修正 [#231](https://github.com/yojo-art/cherrypick/issues/231)
- Feat: サイコロウィジェット
(Cherry-picked from https://github.com/1673beta/cherrypick/pull/73)
- Enhance: 絵文字のインポート時にリモートから取得した値で埋めた編集ダイアログを表示する
- Fix: メディアタイムラインの可視性を変更できない問題を修正 [#54](https://github.com/yojo-art/cherrypick/issues/54)

### Server
-

Expand Down
11 changes: 8 additions & 3 deletions packages/frontend/src/components/global/MkCustomEmoji.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>

<script lang="ts" setup>
import { computed, onMounted, onUnmounted, inject, ref } from 'vue';
import { computed, onMounted, onUnmounted, inject, ref, defineAsyncComponent } from 'vue';
import { getProxiedImageUrl, getStaticImageUrl } from '@/scripts/media-proxy.js';
import { defaultStore } from '@/store.js';
import { customEmojis, customEmojisMap } from '@/custom-emojis.js';
Expand All @@ -40,6 +40,7 @@ import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { i18n } from '@/i18n.js';
import MkCustomEmojiDetailedDialog from '@/components/MkCustomEmojiDetailedDialog.vue';
import { $i } from '@/account.js';
import { importEmojiMeta } from '@/scripts/import-emoji.js';

const props = defineProps<{
name: string;
Expand Down Expand Up @@ -106,11 +107,15 @@ function onClick(ev: MouseEvent) {
}] : []), ...(props.host && $i && ($i.isAdmin || $i.policies.canManageCustomEmojis) ? [{
text: i18n.ts.import,
icon: 'ti ti-plus',
action: () => {
os.apiWithDialog('admin/emoji/steal', {
action: async() => {
let emoji = await os.apiWithDialog('admin/emoji/steal', {
name: customEmojiName.value,
host: props.host,
});
emoji = await importEmojiMeta(emoji, props.host);
os.popup(defineAsyncComponent(() => import('@/pages/emoji-edit-dialog.vue')), {
emoji: emoji,
});
},
}] : []), ...(props.menuReaction && react ? [{
text: i18n.ts.doReaction,
Expand Down
7 changes: 5 additions & 2 deletions packages/frontend/src/pages/custom-emojis-manager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { importEmojiMeta } from '@/scripts/import-emoji.js';

const emojisPaginationComponent = shallowRef<InstanceType<typeof MkPagination>>();

Expand Down Expand Up @@ -156,10 +157,12 @@ const edit = (emoji) => {
}, 'closed');
};

const importEmoji = (emoji) => {
os.apiWithDialog('admin/emoji/copy', {
const importEmoji = async(emoji) => {
let res = await os.apiWithDialog('admin/emoji/copy', {
emojiId: emoji.id,
});
res = await importEmojiMeta(res, emoji.host);
edit(res);
};

const remoteMenu = (emoji, ev: MouseEvent) => {
Expand Down
24 changes: 24 additions & 0 deletions packages/frontend/src/scripts/import-emoji.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export async function importEmojiMeta(emoji, host:string) {
emoji.category = '取得失敗';
try {
const json = await(await fetch('https://' + host + '/api/emoji?name=' + emoji.name)).json();
emoji.category = '';
const from_json = (key: string) => {
try {
if (json[key]) {
emoji[key] = json[key];
}
} catch {
//一部失敗したら転送せず空欄のままにしておく
}
};
from_json('license');
from_json('aliases');
from_json('category');
from_json('isSensitive');
} catch (err) {
console.log(err);
//リモートから取得に失敗
}
return emoji;
}

0 comments on commit 03e5589

Please sign in to comment.