Merge branch 'sim-dev/emojiimport' into develop
This commit is contained in:
commit
f66626e6e6
@ -1,15 +1,14 @@
|
||||
import { defineAsyncComponent } from 'vue';
|
||||
import { $i } from '@/account';
|
||||
import { i18n } from '@/i18n';
|
||||
import * as os from '@/os';
|
||||
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
||||
import { defineAsyncComponent } from 'vue';
|
||||
import { entities } from 'misskey-js';
|
||||
import { MenuItem } from '@/types/menu';
|
||||
import { CustomEmoji } from 'misskey-js/built/entities';
|
||||
|
||||
export async function openReactionImportMenu(ev: MouseEvent, reaction: string) {
|
||||
export async function openReactionImportMenu(ev: MouseEvent, reaction: string): Promise<void> {
|
||||
if (!reaction) return;
|
||||
|
||||
const getEmojiObject = emojiId => new Promise<Record<string, any> | null>(async resolve => {
|
||||
const getEmojiObject = (emojiId): Promise<Record<string, any> | null> => new Promise<Record<string, any> | null>(async resolve => {
|
||||
const sinceId = await os.api('admin/emoji/list', {
|
||||
limit: 1,
|
||||
untilId: emojiId.id,
|
||||
@ -33,14 +32,12 @@ export async function openReactionImportMenu(ev: MouseEvent, reaction: string) {
|
||||
resolve(id[0]);
|
||||
});
|
||||
|
||||
const getEmojiId = async (emojiName: string) => {
|
||||
|
||||
const isLocal = (emojiName.match(/(?<=@).*\.*(?=:)/g) == null || emojiName.match(/(?<=@).*\.*(?=:)/g)[0] == '.');
|
||||
const getEmojiId = async (emojiName: string): Promise<string | null> => {
|
||||
const isLocal = (emojiName.match(/(?<=@).*\.*(?=:)/g) === null || emojiName.match(/(?<=@).*\.*(?=:)/g)[0] === '.');
|
||||
if (isLocal) return null;
|
||||
const host = emojiName.match(/(?<=@).*\.*(?=:)/g)[0];
|
||||
const name = emojiName.match(/(?<=:).*(?=@.*\.*(?=:))/g)[0];
|
||||
if (!host || !name) return;
|
||||
|
||||
if (!host || !name) return null;
|
||||
|
||||
const resList: Record<string, any>[] = await os.api('admin/emoji/list-remote', {
|
||||
host,
|
||||
@ -48,12 +45,12 @@ export async function openReactionImportMenu(ev: MouseEvent, reaction: string) {
|
||||
limit: 100,
|
||||
});
|
||||
|
||||
const emojiId = await resList.find(emoji => emoji.name == name && emoji.host == host)?.id;
|
||||
const emojiId = await resList.find(emoji => emoji.name === name && emoji.host === host)?.id;
|
||||
|
||||
return emojiId;
|
||||
}
|
||||
};
|
||||
|
||||
const importEmoji = async (emojiName: string) => {
|
||||
const importEmoji = async (emojiName: string): Promise<void> => {
|
||||
const emojiId = await getEmojiId(emojiName);
|
||||
if (!await emojiId) return;
|
||||
os.api('admin/emoji/copy', {
|
||||
@ -63,9 +60,6 @@ export async function openReactionImportMenu(ev: MouseEvent, reaction: string) {
|
||||
}));
|
||||
};
|
||||
|
||||
if (!($i?.isAdmin || $i?.isModerator)) return;
|
||||
if (!reaction) return;
|
||||
|
||||
const menuItems: MenuItem[] = [{
|
||||
type: 'label',
|
||||
text: reaction,
|
||||
@ -73,18 +67,15 @@ export async function openReactionImportMenu(ev: MouseEvent, reaction: string) {
|
||||
type: 'button',
|
||||
icon: 'fas fa-copy',
|
||||
text: i18n.ts.copy,
|
||||
action: () => {
|
||||
copyToClipboard(reaction => {
|
||||
if (reaction.startsWith(':')) {
|
||||
return `:${reaction.match(/(?<=:).*(?=@.*\.*(?=:))/g)[0]}:` || reaction;
|
||||
} else {
|
||||
return reaction;
|
||||
}
|
||||
});
|
||||
action: (): void => {
|
||||
console.log('copy');
|
||||
copyToClipboard(reaction.startsWith(':') ? `:${reaction.match(/(?<=:).*(?=@.*\.*(?=:))/g)[0]}:` : reaction);
|
||||
},
|
||||
}];
|
||||
}];
|
||||
|
||||
const emojiId = await getEmojiId(reaction) ? await getEmojiId(reaction) : reaction;
|
||||
if (reaction.startsWith(':') && emojiId) {
|
||||
if (!($i?.isAdmin || $i?.isModerator)) return;
|
||||
menuItems.push({
|
||||
type: 'button',
|
||||
icon: 'fas fa-download',
|
||||
@ -113,7 +104,5 @@ export async function openReactionImportMenu(ev: MouseEvent, reaction: string) {
|
||||
}
|
||||
|
||||
os.contextMenu(menuItems, ev);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user