mirror of
https://github.com/sim1222/misskey.git
synced 2025-04-29 02:37:22 +09:00
cleanup code
This commit is contained in:
parent
fbc1ec67cf
commit
2b05de0204
@ -8,6 +8,11 @@ import { MenuItem } from '@/types/menu';
|
|||||||
export async function openReactionImportMenu(ev: MouseEvent, reaction: string): Promise<void> {
|
export async function openReactionImportMenu(ev: MouseEvent, reaction: string): Promise<void> {
|
||||||
if (!reaction) return;
|
if (!reaction) return;
|
||||||
|
|
||||||
|
const host = reaction.match(/(?<=@).*\.*(?=:)/g)?.[0];
|
||||||
|
const name = reaction.match(/(?<=:).*(?=@.*\.*(?=:))/g)?.[0];
|
||||||
|
const isLocal = (host === null || host === '.');
|
||||||
|
const isCustom = reaction.startsWith(':');
|
||||||
|
|
||||||
const getEmojiObject = (emojiId): Promise<Record<string, any> | null> => 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', {
|
const sinceId = await os.api('admin/emoji/list', {
|
||||||
limit: 1,
|
limit: 1,
|
||||||
@ -32,11 +37,8 @@ export async function openReactionImportMenu(ev: MouseEvent, reaction: string):
|
|||||||
resolve(id[0]);
|
resolve(id[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
const getEmojiId = async (emojiName: string): Promise<string | null> => {
|
const getEmojiId = async (): Promise<string | null> => {
|
||||||
const isLocal = (emojiName.match(/(?<=@).*\.*(?=:)/g) === null || emojiName.match(/(?<=@).*\.*(?=:)/g)[0] === '.');
|
|
||||||
if (isLocal) return null;
|
if (isLocal) return null;
|
||||||
const host = emojiName.match(/(?<=@).*\.*(?=:)/g)[0];
|
|
||||||
const name = emojiName.match(/(?<=:).*(?=@.*\.*(?=:))/g)[0];
|
|
||||||
if (!host || !name) return null;
|
if (!host || !name) return null;
|
||||||
|
|
||||||
const resList: Record<string, any>[] = await os.api('admin/emoji/list-remote', {
|
const resList: Record<string, any>[] = await os.api('admin/emoji/list-remote', {
|
||||||
@ -50,8 +52,8 @@ export async function openReactionImportMenu(ev: MouseEvent, reaction: string):
|
|||||||
return emojiId;
|
return emojiId;
|
||||||
};
|
};
|
||||||
|
|
||||||
const importEmoji = async (emojiName: string): Promise<void> => {
|
const importEmoji = async (): Promise<void> => {
|
||||||
const emojiId = await getEmojiId(emojiName);
|
const emojiId = await getEmojiId();
|
||||||
if (!await emojiId) return;
|
if (!await emojiId) return;
|
||||||
os.api('admin/emoji/copy', {
|
os.api('admin/emoji/copy', {
|
||||||
emojiId: emojiId,
|
emojiId: emojiId,
|
||||||
@ -68,13 +70,18 @@ export async function openReactionImportMenu(ev: MouseEvent, reaction: string):
|
|||||||
icon: 'fas fa-copy',
|
icon: 'fas fa-copy',
|
||||||
text: i18n.ts.copy,
|
text: i18n.ts.copy,
|
||||||
action: (): void => {
|
action: (): void => {
|
||||||
copyToClipboard(reaction.startsWith(':') ? `:${reaction.match(/(?<=:).*(?=@.*\.*(?=:))/g)[0]}:` : reaction);
|
copyToClipboard(isCustom ? `:${name}:` : reaction);
|
||||||
},
|
},
|
||||||
}];
|
}];
|
||||||
|
|
||||||
const emojiId = await getEmojiId(reaction) ? await getEmojiId(reaction) : reaction;
|
const emojiId = await getEmojiId() ? await getEmojiId() : reaction;
|
||||||
if (reaction.startsWith(':') && emojiId) {
|
|
||||||
if (!($i?.isAdmin || $i?.isModerator)) return;
|
if (
|
||||||
|
isCustom &&
|
||||||
|
emojiId &&
|
||||||
|
($i?.isAdmin || $i?.isModerator) &&
|
||||||
|
!isLocal
|
||||||
|
) {
|
||||||
menuItems.push({
|
menuItems.push({
|
||||||
type: 'button',
|
type: 'button',
|
||||||
icon: 'fas fa-download',
|
icon: 'fas fa-download',
|
||||||
@ -83,7 +90,7 @@ export async function openReactionImportMenu(ev: MouseEvent, reaction: string):
|
|||||||
const duplication: boolean = await os.api('meta').then(meta => {
|
const duplication: boolean = await os.api('meta').then(meta => {
|
||||||
const emojis = meta.emojis;
|
const emojis = meta.emojis;
|
||||||
return emojis.some((emoji) => {
|
return emojis.some((emoji) => {
|
||||||
return (emoji.name === reaction.match(/(?<=:).*(?=@.*\.*(?=:))/g)[0]);
|
return (emoji.name === name);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -93,10 +100,10 @@ export async function openReactionImportMenu(ev: MouseEvent, reaction: string):
|
|||||||
text: i18n.ts.duplicateEmoji,
|
text: i18n.ts.duplicateEmoji,
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.canceled) return;
|
if (res.canceled) return;
|
||||||
importEmoji(reaction);
|
importEmoji();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
importEmoji(reaction);
|
importEmoji();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user