Custom reaction (#4517)

* Custom reaction

* increase limit of reactions/delete

* リアクションの場合は OS標準の絵文字を使用 を迂回する

* カスタムリアクションを無効にする設定

* fix

* disableCustomReaction --> enableEmojiReaction

* Avoid MFM rendering

* 🎨

* 🎨

* Auto accept

* custom emoji reaction

* Improve usability

* Extract emojiRegex

* Fix

* Clean up

* 🎨

* 🎨

* toDbReaction で reaction は必須に

あとフォールバックは like に

* Clean up

* Make required

* https://github.com/syuilo/misskey/pull/4517/commits/3eb08748feeaab9ee5c5b505c870f97d7edbeb0d#r266241728

* Refactor

* Allow null
This commit is contained in:
MeiMei 2019-03-18 00:03:57 +09:00 committed by syuilo
parent a5b12bac54
commit 2684541693
19 changed files with 278 additions and 44 deletions

1
src/misc/emoji-regex.ts Normal file

File diff suppressed because one or more lines are too long

View file

@ -13,6 +13,7 @@ const defaultMeta: any = {
originalUsersCount: 0
},
maxNoteTextLength: 1000,
enableEmojiReaction: true,
enableTwitterIntegration: false,
enableGithubIntegration: false,
enableDiscordIntegration: false,

59
src/misc/reaction-lib.ts Normal file
View file

@ -0,0 +1,59 @@
import Emoji from '../models/emoji';
import { emojiRegex } from './emoji-regex';
const basic10: Record<string, string> = {
'👍': 'like',
'❤': 'love', // ここに記述する場合は異体字セレクタを入れない
'😆': 'laugh',
'🤔': 'hmm',
'😮': 'surprise',
'🎉': 'congrats',
'💢': 'angry',
'😥': 'confused',
'😇': 'rip',
'🍮': 'pudding',
};
export async function getFallbackReaction(): Promise<string> {
return 'like';
}
export async function toDbReaction(reaction: string, enableEmoji = true): Promise<string> {
if (reaction == null) return await getFallbackReaction();
// 既存の文字列リアクションはそのまま
if (Object.values(basic10).includes(reaction)) return reaction;
if (!enableEmoji) return await getFallbackReaction();
// Unicode絵文字
const match = emojiRegex.exec(reaction);
if (match) {
// 合字を含む1つの絵文字
const unicode = match[0];
// 異体字セレクタ除去後の絵文字
const normalized = unicode.match('\u200d') ? unicode : unicode.replace(/\ufe0f/g, '');
// Unicodeプリンは寿司化不能とするため文字列化しない
if (normalized === '🍮') return normalized;
// プリン以外の既存のリアクションは文字列化する
if (basic10[normalized]) return basic10[normalized];
// それ以外はUnicodeのまま
return normalized;
}
const custom = reaction.match(/:([\w+-]+):/);
if (custom) {
const emoji = await Emoji.findOne({
host: null,
name: custom[1],
});
if (emoji) return reaction;
}
return await getFallbackReaction();
}