Sengi-Windows-MacOS-Linux/src/app/tools/emoji.tools.ts

41 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-04-14 05:04:19 +02:00
import { Emoji } from '../services/models/mastodon.interfaces';
import * as EmojiOne from 'emojione';
export class EmojiConverter {
applyEmojis(emojis: Emoji[], text: string, type: EmojiTypeEnum, url: string): string {
2019-04-18 05:25:54 +02:00
//const instanceUrl = 'https://' + url.split('https://')[1].split('/')[0];
2019-04-14 05:04:19 +02:00
let className = 'emoji-small';
if (type === EmojiTypeEnum.medium) {
className = 'emoji-medium';
}
emojis.forEach(emoji => {
text = text.replace(`:${emoji.shortcode}:`, `<img class="${className}" src="${emoji.url}" title=":${emoji.shortcode}:" alt=":${emoji.shortcode}:" />`);
});
text = EmojiOne.toImage(text);
while (text.includes('class="emojione"')) {
2019-04-18 05:25:54 +02:00
text = text.replace('class="emojione"', `class="emojione ${className}"`);
2019-04-14 05:04:19 +02:00
}
//FIXME: clean up this mess...
2019-04-18 05:25:54 +02:00
// while (text.includes('https://cdn.jsdelivr.net/emojione/assets/4.5/png/32/')) {
// text = text.replace('https://cdn.jsdelivr.net/emojione/assets/4.5/png/32/', instanceUrl + '/emoji/');
// text = text.replace('.png', '.svg');
// }
2019-04-14 05:04:19 +02:00
while (text.includes('https://cdn.jsdelivr.net/emojione/assets/4.5/png/32/')) {
2019-04-18 05:25:54 +02:00
text = text.replace('https://cdn.jsdelivr.net/emojione/assets/4.5/png/32/', 'assets/emoji/');
2019-04-14 05:04:19 +02:00
text = text.replace('.png', '.svg');
}
return text;
}
}
export enum EmojiTypeEnum {
small,
medium
}