Removed external CDN

This commit is contained in:
Airyz 2023-01-13 18:04:15 +10:30
parent 7041aaa62b
commit 7aa74035c3
3 changed files with 17 additions and 26 deletions

View file

@ -30,7 +30,7 @@ import PhotoIC from '../../../../public/res/ic/outlined/photo.svg';
import BulbIC from '../../../../public/res/ic/outlined/bulb.svg'; import BulbIC from '../../../../public/res/ic/outlined/bulb.svg';
import PeaceIC from '../../../../public/res/ic/outlined/peace.svg'; import PeaceIC from '../../../../public/res/ic/outlined/peace.svg';
import FlagIC from '../../../../public/res/ic/outlined/flag.svg'; import FlagIC from '../../../../public/res/ic/outlined/flag.svg';
import { getTwemojiCDN } from '../../../util/twemojify'; import { getTwemojiBaseUrl } from '../../../util/twemojify';
const ROW_EMOJIS_COUNT = 7; const ROW_EMOJIS_COUNT = 7;
@ -38,7 +38,7 @@ const EmojiGroup = React.memo(({ name, groupEmojis }) => {
function getEmojiBoard() { function getEmojiBoard() {
const emojiBoard = []; const emojiBoard = [];
const totalEmojis = groupEmojis.length; const totalEmojis = groupEmojis.length;
var cdn = getTwemojiCDN()
for (let r = 0; r < totalEmojis; r += ROW_EMOJIS_COUNT) { for (let r = 0; r < totalEmojis; r += ROW_EMOJIS_COUNT) {
const emojiRow = []; const emojiRow = [];
for (let c = r; c < r + ROW_EMOJIS_COUNT; c += 1) { for (let c = r; c < r + ROW_EMOJIS_COUNT; c += 1) {
@ -59,7 +59,7 @@ const EmojiGroup = React.memo(({ name, groupEmojis }) => {
hexcode: emoji.hexcode, hexcode: emoji.hexcode,
loading: 'lazy', loading: 'lazy',
}), }),
base: cdn, base: getTwemojiBaseUrl(),
}, },
)) ))
// This is a custom emoji, and should be render as an mxc // This is a custom emoji, and should be render as an mxc
@ -252,8 +252,6 @@ function EmojiBoard({ onSelect, searchRef }) {
$emojiContent.children[tabIndex].scrollIntoView(); $emojiContent.children[tabIndex].scrollIntoView();
} }
var cdn = getTwemojiCDN()
return ( return (
<div id="emoji-board" className="emoji-board"> <div id="emoji-board" className="emoji-board">
<ScrollView invisible> <ScrollView invisible>
@ -337,7 +335,7 @@ function EmojiBoard({ onSelect, searchRef }) {
</ScrollView> </ScrollView>
</div> </div>
<div ref={emojiInfo} className="emoji-board__content__info"> <div ref={emojiInfo} className="emoji-board__content__info">
<div>{ parse(twemoji.parse('🙂', {base: cdn})) }</div> <div>{ parse(twemoji.parse('🙂', {base: getTwemojiBaseUrl()})) }</div>
<Text>:slight_smile:</Text> <Text>:slight_smile:</Text>
</div> </div>
</div> </div>

View file

@ -5,7 +5,7 @@ import './RoomViewCmdBar.scss';
import parse from 'html-react-parser'; import parse from 'html-react-parser';
import twemoji from 'twemoji'; import twemoji from 'twemoji';
import { getTwemojiCDN, twemojify } from '../../../util/twemojify'; import { getTwemojiBaseUrl, twemojify } from '../../../util/twemojify';
import initMatrix from '../../../client/initMatrix'; import initMatrix from '../../../client/initMatrix';
import { getEmojiForCompletion } from '../emoji-board/custom-emoji'; import { getEmojiForCompletion } from '../emoji-board/custom-emoji';
@ -60,7 +60,7 @@ function renderSuggestions({ prefix, option, suggestions }, fireCmd) {
unicode: emoji.unicode, unicode: emoji.unicode,
shortcodes: emoji.shortcodes?.toString(), shortcodes: emoji.shortcodes?.toString(),
}), }),
base: getTwemojiCDN() base: getTwemojiBaseUrl()
}, },
)); ));
} }

View file

@ -8,19 +8,9 @@ import { sanitizeText } from './sanitize';
const Math = lazy(() => import('../app/atoms/math/Math')); const Math = lazy(() => import('../app/atoms/math/Math'));
const CDN_LOCAL = '/public/twemoji/assets/' const TWEMOJI_BASE_URL = '/public/twemoji/assets/'
const CDN_EXTERNAL = 'https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/';
var use_local = false; export const getTwemojiBaseUrl = () => TWEMOJI_BASE_URL;
export const getTwemojiCDN = () => {
if(window.__TAURI__ || use_local){
return CDN_LOCAL
}
else{
return CDN_EXTERNAL
}
};
const mathOptions = { const mathOptions = {
replace: (node) => { replace: (node) => {
@ -57,13 +47,16 @@ export function twemojify(text, opts, linkify = false, sanitize = true, maths =
content = sanitizeText(content); content = sanitizeText(content);
} }
if(opts){ let options = opts;
opts.base = getTwemojiCDN()
} else { if(!options){
opts = { base: getTwemojiCDN() } options = { base: getTwemojiBaseUrl() }
}
else if(!options.base){
options.base = getTwemojiBaseUrl()
} }
content = twemoji.parse(content, opts); content = twemoji.parse(content, options);
if (linkify) { if (linkify) {
content = linkifyHtml(content, { content = linkifyHtml(content, {