Skip to content

Commit

Permalink
Fix emojis vs uppercase letters:
Browse files Browse the repository at this point in the history
* Fix: trying to use an emojis with an uppercase letter breaks the message field.
* Fix: isOnlyEmojis vs uppercase letters.
* Fix: renaming getEmojisByAtrribute to getEmojisByAttribute.
  • Loading branch information
JohnXLivingston authored and jcbrand committed Sep 6, 2024
1 parent 16d941a commit a0e993a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
- Improved accessibility.
- New "getOccupantActionButtons" hook, so that plugins can add actions on MUC occupants.
- MUC occupants badges: displays short labels, with full label as title.

- Fix: trying to use an emojis with an uppercase letter breaks the message field.
- Fix: renaming getEmojisByAtrribute to getEmojisByAttribute.
- New config option [stanza_timeout](https://conversejs.org/docs/html/configuration.html#show-background)

### Breaking changes:
Expand Down
12 changes: 6 additions & 6 deletions src/headless/plugins/emoji/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function getShortnameReferences (text) {
}
const references = [...text.matchAll(converse.emojis.shortnames_regex)].filter(ref => ref[0].length > 0);
return references.map(ref => {
const cp = converse.emojis.by_sn[ref[0]].cp;
const cp = converse.emojis.by_sn[ref[0].toLowerCase()].cp;
return {
cp,
'begin': ref.index,
Expand Down Expand Up @@ -146,7 +146,7 @@ export function getCodePointReferences (text) {
'cp': icon_id,
'emoji': emoji,
'end': offset + emoji.length,
'shortname': getEmojisByAtrribute('cp')[icon_id]?.sn || ''
'shortname': getEmojisByAttribute('cp')[icon_id]?.sn || ''
});
});
return references;
Expand Down Expand Up @@ -190,20 +190,20 @@ export function isOnlyEmojis (text) {
}
const emojis = words.filter(text => {
const refs = getCodePointReferences(u.shortnamesToUnicode(text));
return refs.length === 1 && (text === refs[0]['shortname'] || text === refs[0]['emoji']);
return refs.length === 1 && (text.toLowerCase() === refs[0]['shortname'] || text === refs[0]['emoji']);
});
return emojis.length === words.length;
}

/**
* @namespace u
* @method u.getEmojisByAtrribute
* @method u.getEmojisByAttribute
* @param { 'category'|'cp'|'sn' } attr
* The attribute according to which the returned map should be keyed.
* @returns { Object }
* Map of emojis with the passed in `attr` used as key and a list of emojis as values.
*/
function getEmojisByAtrribute (attr) {
function getEmojisByAttribute (attr) {
if (emojis_by_attribute[attr]) {
return emojis_by_attribute[attr];
}
Expand All @@ -223,7 +223,7 @@ Object.assign(u, {
getCodePointReferences,
getShortnameReferences,
convertASCII2Emoji,
getEmojisByAtrribute,
getEmojisByAttribute,
isOnlyEmojis,
shortnamesToUnicode,
});

0 comments on commit a0e993a

Please sign in to comment.