Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit c71dc6b

Browse files
authored
Upgrade emojibase-bindings and remove local handling of emoticon variations (#127)
* Updgrade emojibase-bindings and remove local handling of emoticon variations * bump bindings to fix issue of mission emojis with version == 0 * update lockfile * test emoji variation in RTE
1 parent 3a59556 commit c71dc6b

File tree

6 files changed

+34
-19
lines changed

6 files changed

+34
-19
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"dependencies": {
7474
"@babel/runtime": "^7.12.5",
7575
"@matrix-org/analytics-events": "^0.26.0",
76-
"@matrix-org/emojibase-bindings": "^1.1.2",
76+
"@matrix-org/emojibase-bindings": "^1.3.3",
7777
"@vector-im/matrix-wysiwyg": "2.37.13",
7878
"@matrix-org/react-sdk-module-api": "^2.4.0",
7979
"@matrix-org/spec": "^1.7.0",

src/components/views/rooms/BasicMessageComposer.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
201201
// so xd will not match if the string was "mixd 123456"
202202
// and we are lookinh at xd 123456 part of the string
203203
if (emoticonMatch && (n >= 0 || emoticonMatch.index !== 0)) {
204-
const query = emoticonMatch[1].replace("-", "");
205-
// try both exact match and lower-case, this means that xd won't match xD but :P will match :p
206-
const data = EMOTICON_TO_EMOJI.get(query) || EMOTICON_TO_EMOJI.get(query.toLowerCase());
204+
const query = emoticonMatch[1];
205+
// variations of plaintext emoitcons(E.g. :P vs :p vs :-P) are handled upstream by the emojibase-bindings library
206+
const data = EMOTICON_TO_EMOJI.get(query);
207207

208208
if (data) {
209209
const { partCreator } = model;

src/components/views/rooms/wysiwyg_composer/hooks/useSuggestion.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ function shouldIncrementEndIndex(text: string, index: number): boolean {
388388
*/
389389
export function getMappedSuggestion(text: string, isAutoReplaceEmojiEnabled?: boolean): MappedSuggestion | null {
390390
if (isAutoReplaceEmojiEnabled) {
391-
const emoji = EMOTICON_TO_EMOJI.get(text.toLocaleLowerCase());
391+
// variations of plaintext emoitcons(E.g. :P vs :p vs :-P) are handled upstream by the emojibase-bindings/emojibase libraries.
392+
// See rules for variations here https://github.com/milesj/emojibase/blob/master/packages/core/src/generateEmoticonPermutations.ts#L3-L32
393+
const emoji = EMOTICON_TO_EMOJI.get(text);
392394
if (emoji?.unicode) {
393395
return { keyChar: "", text: emoji.unicode, type: "custom" };
394396
}

test/components/views/rooms/BasicMessageComposer-test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe("BasicMessageComposer", () => {
6363
{ before: ":-D", after: "😄" },
6464
{ before: ":D", after: "😄" },
6565
{ before: ":3", after: "😽" },
66+
{ before: "=-]", after: "🙂" },
6667
];
6768
const input = screen.getByRole("textbox");
6869

test/components/views/rooms/wysiwyg_composer/components/WysiwygComposer-test.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,18 @@ describe("WysiwygComposer", () => {
435435
inputType: "insertText",
436436
});
437437

438+
await waitFor(() => expect(onChange).toHaveBeenNthCalledWith(3, expect.stringContaining("😛")));
439+
});
440+
it("typing a space to trigger an emoji varitation replacement", async () => {
441+
fireEvent.input(screen.getByRole("textbox"), {
442+
data: ":-P",
443+
inputType: "insertText",
444+
});
445+
fireEvent.input(screen.getByRole("textbox"), {
446+
data: " ",
447+
inputType: "insertText",
448+
});
449+
438450
await waitFor(() => expect(onChange).toHaveBeenNthCalledWith(3, expect.stringContaining("😛")));
439451
});
440452
});

yarn.lock

+14-14
Original file line numberDiff line numberDiff line change
@@ -1898,13 +1898,13 @@
18981898
resolved "https://registry.yarnpkg.com/@matrix-org/analytics-events/-/analytics-events-0.26.0.tgz#7c8f8f924d8313c87951a0e941640ef8ff78f3d6"
18991899
integrity sha512-cjKZBejajUG8wPhVygMkBTwTLdEn74luUP6g6RjCUqPR3RYIl3NVi58Zil8CWfRTILb4wVLCPpAvehgXJn1HnQ==
19001900

1901-
"@matrix-org/emojibase-bindings@^1.1.2":
1902-
version "1.1.3"
1903-
resolved "https://registry.yarnpkg.com/@matrix-org/emojibase-bindings/-/emojibase-bindings-1.1.3.tgz#d35f0367d586d83261564662b6bb67fda8845d68"
1904-
integrity sha512-ljr0kPerx8yUc4JVJz7japebb1ZbtGH4V4cvlO2LYgTg+warjagDwkJ5x+ZUVuTU6MH8x0LrUxmkqVgmSoQyWA==
1901+
"@matrix-org/emojibase-bindings@^1.3.3":
1902+
version "1.3.3"
1903+
resolved "https://registry.yarnpkg.com/@matrix-org/emojibase-bindings/-/emojibase-bindings-1.3.3.tgz#cee82a739c0866bf3100b03755647ace1f3ba6ef"
1904+
integrity sha512-GwuZdmF+wZT34RKehQYjTzdgba1ju2W3FM4jPJfwqh0jUxVXZLb+6b6dV3lna6/7EDzgGvOMwTwCAolILDwS0g==
19051905
dependencies:
1906-
emojibase "^15.0.0"
1907-
emojibase-data "^15.0.0"
1906+
emojibase "^15.3.1"
1907+
emojibase-data "^15.3.1"
19081908

19091909
"@matrix-org/matrix-sdk-crypto-wasm@^7.0.0":
19101910
version "7.0.0"
@@ -4431,20 +4431,20 @@ emoji-regex@^9.2.2:
44314431
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.2.2.tgz#840c8803b0d8047f4ff0cf963176b32d4ef3ed72"
44324432
integrity sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==
44334433

4434-
emojibase-data@^15.0.0:
4435-
version "15.2.0"
4436-
resolved "https://registry.yarnpkg.com/emojibase-data/-/emojibase-data-15.2.0.tgz#475a786c091a101ef4bcf57227771c6260ee39b2"
4437-
integrity sha512-hDiw4ugxnI4pcVQO+73NlKx6aZP/A+BAPfDgK/3A83RVbHZa0Ut6GHpd5r5XUV9G7BZhKejlIRuxhXialpbt6Q==
4434+
emojibase-data@^15.3.1:
4435+
version "15.3.2"
4436+
resolved "https://registry.yarnpkg.com/emojibase-data/-/emojibase-data-15.3.2.tgz#2742246bfe14f16a7829b42ca156dec09934cf85"
4437+
integrity sha512-TpDyTDDTdqWIJixV5sTA6OQ0P0JfIIeK2tFRR3q56G9LK65ylAZ7z3KyBXokpvTTJ+mLUXQXbLNyVkjvnTLE+A==
44384438

44394439
44404440
version "15.3.2"
44414441
resolved "https://registry.yarnpkg.com/emojibase-regex/-/emojibase-regex-15.3.2.tgz#5175231715b86d4b437754527288844a6c29318f"
44424442
integrity sha512-ue6BVeb2qu33l97MkxcOoyMJlg6Tug3eTv2z1at+M9TjvlWKvdmAPvZIDG1JbT2RH3FSyJNLucO5K5H/yxT03w==
44434443

4444-
emojibase@^15.0.0:
4445-
version "15.2.0"
4446-
resolved "https://registry.yarnpkg.com/emojibase/-/emojibase-15.2.0.tgz#0a175d4218f4a1600f2ada6b3a3184cef1b3ec7b"
4447-
integrity sha512-gB6rIVtyJPersQvAo4nOGYPeILMhlcfZdiwCWVeRAtkJ7sm0tExZETGyLhrTQcHvZQhDEYI1vlCeqUhn5gZkQA==
4444+
emojibase@^15.3.1:
4445+
version "15.3.1"
4446+
resolved "https://registry.yarnpkg.com/emojibase/-/emojibase-15.3.1.tgz#7f6ff5482486f23e59a457de64e974bd35f3c9a3"
4447+
integrity sha512-GNsjHnG2J3Ktg684Fs/vZR/6XpOSkZPMAv85EHrr6br2RN2cJNwdS4am/3YSK3y+/gOv2kmoK3GGdahXdMxg2g==
44484448

44494449
emojis-list@^3.0.0:
44504450
version "3.0.0"

0 commit comments

Comments
 (0)