Skip to content

Commit

Permalink
存在しないカスタム絵文字をテキストで表示するように
Browse files Browse the repository at this point in the history
Resolve #9516
  • Loading branch information
syuilo committed Jan 17, 2023
1 parent 0db2abd commit fe4fbaf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ You should also include the user name that made the change.
## 13.x.x (unreleased)

### Improvements
- 存在しないカスタム絵文字をテキストで表示するように

### Bugfixes
- playを削除する手段がなかったのを修正
Expand Down
9 changes: 7 additions & 2 deletions packages/backend/src/server/ServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { genIdenticon } from '@/misc/gen-identicon.js';
import { createTemp } from '@/misc/create-temp.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { LoggerService } from '@/core/LoggerService.js';
import { bindThis } from '@/decorators.js';
import { ActivityPubServerService } from './ActivityPubServerService.js';
import { NodeinfoServerService } from './NodeinfoServerService.js';
import { ApiServerService } from './api/ApiServerService.js';
Expand All @@ -22,7 +23,6 @@ import { WellKnownServerService } from './WellKnownServerService.js';
import { MediaProxyServerService } from './MediaProxyServerService.js';
import { FileServerService } from './FileServerService.js';
import { ClientServerService } from './web/ClientServerService.js';
import { bindThis } from '@/decorators.js';

@Injectable()
export class ServerService {
Expand Down Expand Up @@ -101,7 +101,12 @@ export class ServerService {
reply.header('Content-Security-Policy', 'default-src \'none\'; style-src \'unsafe-inline\'');

if (emoji == null) {
return await reply.redirect('/static-assets/emoji-unknown.png');
if ('fallback' in request.query) {
return await reply.redirect('/static-assets/emoji-unknown.png');
} else {
reply.code(404);
return;
}
}

const url = new URL('/proxy/emoji.webp', this.config.url);
Expand Down
4 changes: 3 additions & 1 deletion packages/frontend/src/components/global/MkEmoji.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<img v-if="isCustom" :class="[$style.root, $style.custom, { [$style.normal]: normal, [$style.noStyle]: noStyle }]" :src="url" :alt="alt" :title="alt" decoding="async"/>
<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="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>{{ emoji }}</span>
Expand Down Expand Up @@ -37,6 +38,7 @@ const url = computed(() => {
}
});
const alt = computed(() => isCustom.value ? `:${customEmojiName}:` : char.value);
let errored = $ref(false);
// 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 {
Expand Down

0 comments on commit fe4fbaf

Please sign in to comment.