2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
<template>
|
2024-01-21 10:30:05 +01:00
|
|
|
<MkWindow
|
|
|
|
ref="windowEl"
|
|
|
|
:initialWidth="400"
|
|
|
|
:initialHeight="500"
|
|
|
|
:canResize="false"
|
|
|
|
@close="windowEl.close()"
|
2020-10-17 13:12:00 +02:00
|
|
|
@closed="$emit('closed')"
|
|
|
|
>
|
2023-05-18 11:45:49 +02:00
|
|
|
<template v-if="emoji" #header>:{{ emoji.name }}:</template>
|
|
|
|
<template v-else #header>New emoji</template>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<MkSpacer :marginMin="20" :marginMax="28">
|
|
|
|
<div class="_gaps_m">
|
|
|
|
<div v-if="imgUrl != null" :class="$style.imgs">
|
|
|
|
<div style="background: #000;" :class="$style.imgContainer">
|
|
|
|
<img :src="imgUrl" :class="$style.img"/>
|
|
|
|
</div>
|
|
|
|
<div style="background: #222;" :class="$style.imgContainer">
|
|
|
|
<img :src="imgUrl" :class="$style.img"/>
|
|
|
|
</div>
|
|
|
|
<div style="background: #ddd;" :class="$style.imgContainer">
|
|
|
|
<img :src="imgUrl" :class="$style.img"/>
|
|
|
|
</div>
|
|
|
|
<div style="background: #fff;" :class="$style.imgContainer">
|
|
|
|
<img :src="imgUrl" :class="$style.img"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<MkButton rounded style="margin: 0 auto;" @click="changeImage">{{ i18n.ts.selectFile }}</MkButton>
|
2023-10-25 14:20:36 +02:00
|
|
|
<MkInput v-model="name" pattern="[a-z0-9_]" autocapitalize="off">
|
2023-05-18 11:45:49 +02:00
|
|
|
<template #label>{{ i18n.ts.name }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<MkInput v-model="category" :datalist="customEmojiCategories">
|
|
|
|
<template #label>{{ i18n.ts.category }}</template>
|
|
|
|
</MkInput>
|
2023-10-25 14:20:36 +02:00
|
|
|
<MkInput v-model="aliases" autocapitalize="off">
|
2023-05-18 11:45:49 +02:00
|
|
|
<template #label>{{ i18n.ts.tags }}</template>
|
2024-01-03 00:07:04 +01:00
|
|
|
<template #caption>
|
|
|
|
{{ i18n.ts.theKeywordWhenSearchingForCustomEmoji }}<br/>
|
|
|
|
{{ i18n.ts.setMultipleBySeparatingWithSpace }}
|
|
|
|
</template>
|
2023-05-18 11:45:49 +02:00
|
|
|
</MkInput>
|
2024-01-17 06:29:24 +01:00
|
|
|
<MkInput v-model="license" :mfmAutocomplete="true">
|
2023-05-18 11:45:49 +02:00
|
|
|
<template #label>{{ i18n.ts.license }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<MkFolder>
|
|
|
|
<template #label>{{ i18n.ts.rolesThatCanBeUsedThisEmojiAsReaction }}</template>
|
2023-05-18 13:17:32 +02:00
|
|
|
<template #suffix>{{ rolesThatCanBeUsedThisEmojiAsReaction.length === 0 ? i18n.ts.all : rolesThatCanBeUsedThisEmojiAsReaction.length }}</template>
|
2023-05-18 11:45:49 +02:00
|
|
|
|
2023-05-18 13:17:32 +02:00
|
|
|
<div class="_gaps">
|
2023-09-30 21:53:52 +02:00
|
|
|
<MkButton rounded @click="addRole"><i class="ph-plus ph-bold ph-lg"></i> {{ i18n.ts.add }}</MkButton>
|
2023-05-18 11:45:49 +02:00
|
|
|
|
|
|
|
<div v-for="role in rolesThatCanBeUsedThisEmojiAsReaction" :key="role.id" :class="$style.roleItem">
|
2023-05-18 13:17:32 +02:00
|
|
|
<MkRolePreview :class="$style.role" :role="role" :forModeration="true" :detailed="false" style="pointer-events: none;"/>
|
2023-09-30 21:53:52 +02:00
|
|
|
<button v-if="role.target === 'manual'" class="_button" :class="$style.roleUnassign" @click="removeRole(role, $event)"><i class="ph-x ph-bold ph-lg"></i></button>
|
|
|
|
<button v-else class="_button" :class="$style.roleUnassign" disabled><i class="ph-prohibit ph-bold ph-lg"></i></button>
|
2023-05-18 11:45:49 +02:00
|
|
|
</div>
|
2023-05-18 13:17:32 +02:00
|
|
|
|
|
|
|
<MkInfo>{{ i18n.ts.rolesThatCanBeUsedThisEmojiAsReactionEmptyDescription }}</MkInfo>
|
|
|
|
<MkInfo warn>{{ i18n.ts.rolesThatCanBeUsedThisEmojiAsReactionPublicRoleWarn }}</MkInfo>
|
2023-05-18 11:45:49 +02:00
|
|
|
</div>
|
|
|
|
</MkFolder>
|
|
|
|
<MkSwitch v-model="isSensitive">isSensitive</MkSwitch>
|
|
|
|
<MkSwitch v-model="localOnly">{{ i18n.ts.localOnly }}</MkSwitch>
|
2023-09-30 21:53:52 +02:00
|
|
|
<MkButton v-if="emoji" danger @click="del()"><i class="ph-trash ph-bold ph-lg"></i> {{ i18n.ts.delete }}</MkButton>
|
2023-05-18 11:45:49 +02:00
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
<div :class="$style.footer">
|
2023-09-30 21:53:52 +02:00
|
|
|
<MkButton primary rounded style="margin: 0 auto;" @click="done"><i class="ph-check ph-bold ph-lg"></i> {{ props.emoji ? i18n.ts.update : i18n.ts.create }}</MkButton>
|
2021-04-21 05:06:02 +02:00
|
|
|
</div>
|
2023-05-18 11:45:49 +02:00
|
|
|
</div>
|
2024-01-21 10:30:05 +01:00
|
|
|
</MkWindow>
|
2020-10-17 13:12:00 +02:00
|
|
|
</template>
|
|
|
|
|
2022-05-15 15:20:01 +02:00
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { computed, watch, ref } from 'vue';
|
2023-09-04 06:33:38 +02:00
|
|
|
import * as Misskey from 'misskey-js';
|
2024-01-21 10:30:05 +01:00
|
|
|
import MkWindow from '@/components/MkWindow.vue';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-01-07 07:09:46 +01:00
|
|
|
import MkInput from '@/components/MkInput.vue';
|
2023-05-18 11:45:49 +02:00
|
|
|
import MkInfo from '@/components/MkInfo.vue';
|
|
|
|
import MkFolder from '@/components/MkFolder.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import * as os from '@/os.js';
|
2024-01-04 10:32:46 +01:00
|
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { customEmojiCategories } from '@/custom-emojis.js';
|
2023-05-18 11:45:49 +02:00
|
|
|
import MkSwitch from '@/components/MkSwitch.vue';
|
2023-12-21 03:36:45 +01:00
|
|
|
import { selectFile } from '@/scripts/select-file.js';
|
2023-05-18 11:45:49 +02:00
|
|
|
import MkRolePreview from '@/components/MkRolePreview.vue';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-15 15:20:01 +02:00
|
|
|
const props = defineProps<{
|
2023-05-18 11:45:49 +02:00
|
|
|
emoji?: any,
|
2022-05-15 15:20:01 +02:00
|
|
|
}>();
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2024-01-21 10:30:05 +01:00
|
|
|
const windowEl = ref<InstanceType<typeof MkWindow> | null>(null);
|
2023-12-07 06:42:09 +01:00
|
|
|
const name = ref<string>(props.emoji ? props.emoji.name : '');
|
|
|
|
const category = ref<string>(props.emoji ? props.emoji.category : '');
|
|
|
|
const aliases = ref<string>(props.emoji ? props.emoji.aliases.join(' ') : '');
|
|
|
|
const license = ref<string>(props.emoji ? (props.emoji.license ?? '') : '');
|
|
|
|
const isSensitive = ref(props.emoji ? props.emoji.isSensitive : false);
|
|
|
|
const localOnly = ref(props.emoji ? props.emoji.localOnly : false);
|
|
|
|
const roleIdsThatCanBeUsedThisEmojiAsReaction = ref(props.emoji ? props.emoji.roleIdsThatCanBeUsedThisEmojiAsReaction : []);
|
2023-12-26 06:19:35 +01:00
|
|
|
const rolesThatCanBeUsedThisEmojiAsReaction = ref<Misskey.entities.Role[]>([]);
|
2023-12-07 06:42:09 +01:00
|
|
|
const file = ref<Misskey.entities.DriveFile>();
|
|
|
|
|
|
|
|
watch(roleIdsThatCanBeUsedThisEmojiAsReaction, async () => {
|
2024-01-04 10:32:46 +01:00
|
|
|
rolesThatCanBeUsedThisEmojiAsReaction.value = (await Promise.all(roleIdsThatCanBeUsedThisEmojiAsReaction.value.map((id) => misskeyApi('admin/roles/show', { roleId: id }).catch(() => null)))).filter(x => x != null);
|
2023-05-18 11:45:49 +02:00
|
|
|
}, { immediate: true });
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const imgUrl = computed(() => file.value ? file.value.url : props.emoji ? `/emoji/${props.emoji.name}.webp` : null);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-15 15:20:01 +02:00
|
|
|
const emit = defineEmits<{
|
2023-05-18 11:45:49 +02:00
|
|
|
(ev: 'done', v: { deleted?: boolean; updated?: any; created?: any }): void,
|
2022-05-15 15:20:01 +02:00
|
|
|
(ev: 'closed'): void
|
|
|
|
}>();
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-05-18 11:45:49 +02:00
|
|
|
async function changeImage(ev) {
|
2023-12-07 06:42:09 +01:00
|
|
|
file.value = await selectFile(ev.currentTarget ?? ev.target, null);
|
|
|
|
const candidate = file.value.name.replace(/\.(.+)$/, '');
|
2023-07-20 10:29:21 +02:00
|
|
|
if (candidate.match(/^[a-z0-9_]+$/)) {
|
2023-12-07 06:42:09 +01:00
|
|
|
name.value = candidate;
|
2023-07-20 10:29:21 +02:00
|
|
|
}
|
2022-05-15 15:20:01 +02:00
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-05-18 11:45:49 +02:00
|
|
|
async function addRole() {
|
2024-01-04 10:32:46 +01:00
|
|
|
const roles = await misskeyApi('admin/roles/list');
|
2023-12-07 06:42:09 +01:00
|
|
|
const currentRoleIds = rolesThatCanBeUsedThisEmojiAsReaction.value.map(x => x.id);
|
2023-05-18 11:45:49 +02:00
|
|
|
|
|
|
|
const { canceled, result: role } = await os.select({
|
2023-05-19 02:14:54 +02:00
|
|
|
items: roles.filter(r => r.isPublic).filter(r => !currentRoleIds.includes(r.id)).map(r => ({ text: r.name, value: r })),
|
2023-05-18 11:45:49 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
rolesThatCanBeUsedThisEmojiAsReaction.value.push(role);
|
2023-05-18 11:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function removeRole(role, ev) {
|
2023-12-07 06:42:09 +01:00
|
|
|
rolesThatCanBeUsedThisEmojiAsReaction.value = rolesThatCanBeUsedThisEmojiAsReaction.value.filter(x => x.id !== role.id);
|
2023-05-18 11:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function done() {
|
|
|
|
const params = {
|
2023-12-07 06:42:09 +01:00
|
|
|
name: name.value,
|
|
|
|
category: category.value === '' ? null : category.value,
|
|
|
|
aliases: aliases.value.split(' ').filter(x => x !== ''),
|
|
|
|
license: license.value === '' ? null : license.value,
|
|
|
|
isSensitive: isSensitive.value,
|
|
|
|
localOnly: localOnly.value,
|
|
|
|
roleIdsThatCanBeUsedThisEmojiAsReaction: rolesThatCanBeUsedThisEmojiAsReaction.value.map(x => x.id),
|
2023-05-18 11:45:49 +02:00
|
|
|
};
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
if (file.value) {
|
|
|
|
params.fileId = file.value.id;
|
2023-05-18 11:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (props.emoji) {
|
|
|
|
await os.apiWithDialog('admin/emoji/update', {
|
2022-05-15 15:20:01 +02:00
|
|
|
id: props.emoji.id,
|
2023-05-18 11:45:49 +02:00
|
|
|
...params,
|
|
|
|
});
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-05-18 11:45:49 +02:00
|
|
|
emit('done', {
|
|
|
|
updated: {
|
|
|
|
id: props.emoji.id,
|
|
|
|
...params,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-01-21 10:30:05 +01:00
|
|
|
windowEl.value.close();
|
2023-05-18 11:45:49 +02:00
|
|
|
} else {
|
|
|
|
const created = await os.apiWithDialog('admin/emoji/add', params);
|
|
|
|
|
|
|
|
emit('done', {
|
|
|
|
created: created,
|
|
|
|
});
|
|
|
|
|
2024-01-21 10:30:05 +01:00
|
|
|
windowEl.value.close();
|
2023-05-18 11:45:49 +02:00
|
|
|
}
|
2022-05-15 15:20:01 +02:00
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-15 15:20:01 +02:00
|
|
|
async function del() {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
2024-01-20 00:11:59 +01:00
|
|
|
text: i18n.tsx.removeAreYouSure({ x: name.value }),
|
2022-05-15 15:20:01 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApi('admin/emoji/delete', {
|
2022-07-20 15:24:26 +02:00
|
|
|
id: props.emoji.id,
|
2022-05-15 15:20:01 +02:00
|
|
|
}).then(() => {
|
|
|
|
emit('done', {
|
2022-07-20 15:24:26 +02:00
|
|
|
deleted: true,
|
2022-05-15 15:20:01 +02:00
|
|
|
});
|
2024-01-21 10:30:05 +01:00
|
|
|
windowEl.value.close();
|
2022-05-15 15:20:01 +02:00
|
|
|
});
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
</script>
|
|
|
|
|
2023-05-14 03:21:56 +02:00
|
|
|
<style lang="scss" module>
|
2023-05-18 11:45:49 +02:00
|
|
|
.imgs {
|
|
|
|
display: flex;
|
|
|
|
gap: 8px;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.imgContainer {
|
|
|
|
padding: 8px;
|
2023-10-31 19:44:34 +01:00
|
|
|
border-radius: var(--radius-sm);
|
2023-05-18 11:45:49 +02:00
|
|
|
}
|
|
|
|
|
2023-05-14 03:21:56 +02:00
|
|
|
.img {
|
|
|
|
display: block;
|
|
|
|
height: 64px;
|
2023-05-18 11:45:49 +02:00
|
|
|
width: 64px;
|
|
|
|
object-fit: contain;
|
|
|
|
}
|
|
|
|
|
|
|
|
.roleItem {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
|
|
|
|
.role {
|
|
|
|
flex: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
.roleUnassign {
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
margin-left: 8px;
|
|
|
|
align-self: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.footer {
|
|
|
|
position: sticky;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
padding: 12px;
|
|
|
|
border-top: solid 0.5px var(--divider);
|
|
|
|
-webkit-backdrop-filter: var(--blur, blur(15px));
|
|
|
|
backdrop-filter: var(--blur, blur(15px));
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
</style>
|