mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-29 05:38:30 +01:00
wip
This commit is contained in:
parent
226e0c4714
commit
d347f0a087
5 changed files with 18 additions and 15 deletions
|
@ -22,8 +22,10 @@ export class EmojiEntityService {
|
||||||
@bindThis
|
@bindThis
|
||||||
public async pack(
|
public async pack(
|
||||||
src: Emoji['id'] | Emoji,
|
src: Emoji['id'] | Emoji,
|
||||||
opts: { omitHost?: boolean; omitId?: boolean; withUrl?: boolean; } = {},
|
opts: { omitHost?: boolean; omitId?: boolean; withUrl?: boolean; } = { omitHost: true, omitId: true, withUrl: true },
|
||||||
): Promise<Packed<'Emoji'>> {
|
): Promise<Packed<'Emoji'>> {
|
||||||
|
opts = { omitHost: true, omitId: true, withUrl: true, ...opts }
|
||||||
|
|
||||||
const emoji = typeof src === 'object' ? src : await this.emojisRepository.findOneByOrFail({ id: src });
|
const emoji = typeof src === 'object' ? src : await this.emojisRepository.findOneByOrFail({ id: src });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -101,7 +101,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
.take(ps.limit)
|
.take(ps.limit)
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
return this.emojiEntityService.packMany(emojis);
|
return this.emojiEntityService.packMany(emojis, { omitHost: false, omitId: false, withUrl: false });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
emojis = await q.take(ps.limit).getMany();
|
emojis = await q.take(ps.limit).getMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.emojiEntityService.packMany(emojis);
|
return this.emojiEntityService.packMany(emojis, { omitHost: false, omitId: false, withUrl: false });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<span v-if="isCustom && errored">:{{ customEmojiName }}:</span>
|
<span v-if="isCustom && errored">:{{ customEmojiName }}:</span>
|
||||||
<img v-else-if="isCustom" :class="[$style.root, $style.custom, { [$style.normal]: normal, [$style.noStyle]: noStyle }]" :src="url" :alt="alt" :title="alt" decoding="async" @error="errored = true"/>
|
<img v-else-if="isCustom" :class="[$style.root, $style.custom, { [$style.normal]: normal, [$style.noStyle]: noStyle }]" :src="url" :alt="alt" :title="alt" decoding="async" @error="errored = true" @load="errored = false"/>
|
||||||
<img v-else-if="char && !useOsNativeEmojis" :class="$style.root" :src="url" :alt="alt" decoding="async" @pointerenter="computeTitle"/>
|
<img v-else-if="char && !useOsNativeEmojis" :class="$style.root" :src="url" :alt="alt" decoding="async" @pointerenter="computeTitle"/>
|
||||||
<span v-else-if="char && useOsNativeEmojis" :alt="alt" @pointerenter="computeTitle">{{ char }}</span>
|
<span v-else-if="char && useOsNativeEmojis" :alt="alt" @pointerenter="computeTitle">{{ char }}</span>
|
||||||
<span v-else>{{ emoji }}</span>
|
<span v-else>{{ emoji }}</span>
|
||||||
|
@ -25,29 +25,30 @@ const props = defineProps<{
|
||||||
const char2path = defaultStore.state.emojiStyle === 'twemoji' ? char2twemojiFilePath : char2fluentEmojiFilePath;
|
const char2path = defaultStore.state.emojiStyle === 'twemoji' ? char2twemojiFilePath : char2fluentEmojiFilePath;
|
||||||
|
|
||||||
const isCustom = computed(() => props.emoji.startsWith(':'));
|
const isCustom = computed(() => props.emoji.startsWith(':'));
|
||||||
const customEmojiName = props.emoji.substr(1, props.emoji.length - 2).replace('@.', '');
|
const customEmojiName = computed(() => props.emoji.substr(1, props.emoji.length - 2).replace('@.', ''));
|
||||||
const char = computed(() => isCustom.value ? undefined : props.emoji);
|
const char = computed(() => isCustom.value ? undefined : props.emoji);
|
||||||
const useOsNativeEmojis = computed(() => defaultStore.state.emojiStyle === 'native' && !props.isReaction);
|
const useOsNativeEmojis = computed(() => defaultStore.state.emojiStyle === 'native' && !props.isReaction);
|
||||||
const url = computed(() => {
|
const url = computed(() => {
|
||||||
if (char.value) {
|
if (char.value) {
|
||||||
return char2path(char.value);
|
return char2path(char.value);
|
||||||
} else if (props.host == null && !customEmojiName.includes('@')) {
|
} else if (props.host == null && !customEmojiName.value.includes('@')) {
|
||||||
const found = customEmojis.value.find(x => x.name === customEmojiName);
|
const found = customEmojis.value.find(x => x.name === customEmojiName.value);
|
||||||
|
console.log(found)
|
||||||
return found ? found.url : null;
|
return found ? found.url : null;
|
||||||
} else {
|
} else {
|
||||||
const rawUrl = props.host ? `/emoji/${customEmojiName}@${props.host}.webp` : `/emoji/${customEmojiName}.webp`;
|
const rawUrl = props.host ? `/emoji/${customEmojiName.value}@${props.host}.webp` : `/emoji/${customEmojiName.value}.webp`;
|
||||||
return defaultStore.state.disableShowingAnimatedImages
|
return defaultStore.state.disableShowingAnimatedImages
|
||||||
? getStaticImageUrl(rawUrl)
|
? getStaticImageUrl(rawUrl)
|
||||||
: rawUrl;
|
: rawUrl;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const alt = computed(() => isCustom.value ? `:${customEmojiName}:` : char.value);
|
const alt = computed(() => isCustom.value ? `:${customEmojiName.value}:` : char.value);
|
||||||
let errored = $ref(isCustom.value && url.value == null);
|
let errored = $ref(isCustom.value && url.value == null);
|
||||||
|
|
||||||
// Searching from an array with 2000 items for every emoji felt like too energy-consuming, so I decided to do it lazily on pointerenter
|
// Searching from an array with 2000 items for every emoji felt like too energy-consuming, so I decided to do it lazily on pointerenter
|
||||||
function computeTitle(event: PointerEvent): void {
|
function computeTitle(event: PointerEvent): void {
|
||||||
const title = isCustom.value
|
const title = isCustom.value
|
||||||
? `:${customEmojiName}:`
|
? `:${customEmojiName.value}:`
|
||||||
: (getEmojiName(char.value as string) ?? char.value as string);
|
: (getEmojiName(char.value as string) ?? char.value as string);
|
||||||
(event.target as HTMLElement).title = title;
|
(event.target as HTMLElement).title = title;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { apiGet } from './os';
|
import { apiGet } from './os';
|
||||||
import { miLocalStorage } from './local-storage';
|
import { miLocalStorage } from './local-storage';
|
||||||
import { shallowRef, computed, markRaw } from 'vue';
|
import { shallowRef, computed, markRaw, watch } from 'vue';
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
import { stream } from '@/stream';
|
import { stream } from '@/stream';
|
||||||
|
|
||||||
|
@ -14,12 +14,12 @@ export const customEmojiCategories = computed<string[]>(() => {
|
||||||
return markRaw(Array.from(categories));
|
return markRaw(Array.from(categories));
|
||||||
});
|
});
|
||||||
|
|
||||||
fetchCustomEmojis();
|
watch(customEmojis, (newVal) => {
|
||||||
|
console.log('new', newVal)
|
||||||
|
});
|
||||||
|
|
||||||
stream.on('emojiAdded', emojiData => {
|
stream.on('emojiAdded', emojiData => {
|
||||||
setTimeout(() => {
|
customEmojis.value = [ emojiData.emoji, ...customEmojis.value ];
|
||||||
customEmojis.value = [ emojiData.emoji, ...customEmojis.value ]
|
|
||||||
}, 100);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
stream.on('emojiUpdated', emojiData => {
|
stream.on('emojiUpdated', emojiData => {
|
||||||
|
|
Loading…
Reference in a new issue