mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-30 14:01:02 +00:00 
			
		
		
		
	chore: simplify storing and sending custom emoji's
- Using a map to store the CustomEmojis is unncessary, the values can be derived by the key easily. We still need to know if a certain name is custom emoji, so store the custom emojis in a `Set`. - Instead of constructing a map in `window.config`, construct a `Set` and reconstruct the value in `emoji.js`. This has the main benefit of reducing the amount of text being sent for each request, which is quite noticable if a Forgejo instance has many (>1000) custom emojis. - Remove the default value of `CustomEmojisMap`, it will be constructed anyway.
This commit is contained in:
		
					parent
					
						
							
								f1cfd152e2
							
						
					
				
			
			
				commit
				
					
						da635229bf
					
				
			
		
					 6 changed files with 10 additions and 13 deletions
				
			
		|  | @ -2,7 +2,7 @@ import emojis from '../../../assets/emoji.json'; | |||
| 
 | ||||
| const {assetUrlPrefix, customEmojis} = window.config; | ||||
| 
 | ||||
| const tempMap = {...customEmojis}; | ||||
| const tempMap = Object.assign(...Array.from(customEmojis, (v) => ({[v]: `:${v}:`}))); | ||||
| for (const {emoji, aliases} of emojis) { | ||||
|   for (const alias of aliases || []) { | ||||
|     tempMap[alias] = emoji; | ||||
|  | @ -23,7 +23,7 @@ for (const key of emojiKeys) { | |||
| // retrieve HTML for given emoji name
 | ||||
| export function emojiHTML(name) { | ||||
|   let inner; | ||||
|   if (Object.hasOwn(customEmojis, name)) { | ||||
|   if (customEmojis.has(name)) { | ||||
|     inner = `<img alt=":${name}:" src="${assetUrlPrefix}/img/emoji/${name}.png">`; | ||||
|   } else { | ||||
|     inner = emojiString(name); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue