Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/meteor/app/emoji/client/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ export const getEmojisBySearchTerm = (
continue;
}

const { emojiPackage, shortnames = [], name } = emojiObject;
const { emojiPackage, shortnames = [], name, legacy } = emojiObject;

if (legacy) {
continue;
}

let tone = '';
current = current.replace(/:/g, '');

Expand Down
2 changes: 2 additions & 0 deletions apps/meteor/app/emoji/lib/rocketchat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type EmojiPackages = {
extension?: string;
etag?: string;
unicode?: string;
legacy?: boolean;
}
| {
name?: undefined;
Expand All @@ -43,6 +44,7 @@ export type EmojiPackages = {
aliases?: undefined;
shortnames?: undefined;
etag?: string;
legacy?: boolean;
};
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ const ComposerPopupProvider = ({ children, room }: ComposerPopupProviderProps) =
})
.filter(
({ _id }) =>
filterRegex.test(_id) && (exactFinalTone.test(_id.substring(key.length)) || seeColor.test(key) || !colorBlind.test(_id)),
!collection[_id]?.legacy &&
filterRegex.test(_id) &&
(exactFinalTone.test(_id.substring(key.length)) || seeColor.test(key) || !colorBlind.test(_id)),
)
.sort(emojiSort(recents))
.slice(0, 10);
Expand Down Expand Up @@ -307,7 +309,9 @@ const ComposerPopupProvider = ({ children, room }: ComposerPopupProviderProps) =
})
.filter(
({ _id }) =>
filterRegex.test(_id) && (exactFinalTone.test(_id.substring(key.length)) || seeColor.test(key) || !colorBlind.test(_id)),
!collection[_id]?.legacy &&
filterRegex.test(_id) &&
(exactFinalTone.test(_id.substring(key.length)) || seeColor.test(key) || !colorBlind.test(_id)),
)
.sort(emojiSort(recents))
.slice(0, 10);
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/client/views/root/hooks/useNativeEmoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const useNativeEmoji = () => {
category: '',
emojiPackage: 'native',
unicode,
legacy: true,
};
}

Expand Down
39 changes: 39 additions & 0 deletions apps/meteor/tests/unit/app/emoji/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { describe, it, beforeEach, before } from 'mocha';
import { getEmojisBySearchTerm, updateRecent, removeFromRecent, replaceEmojiInRecent } from '../../../../app/emoji/client/helpers';
import { emoji } from '../../../../app/emoji/client/lib';
import { getEmojiConfig } from '../../../../app/emoji-native/lib/getEmojiConfig';
import { legacyEmojioneMap } from '../../../../app/emoji-native/lib/legacyEmojioneMap';

const registerNativeEmojis = () => {
const config = getEmojiConfig(emoji);
Expand All @@ -27,6 +28,27 @@ const registerNativeEmojis = () => {
});
}
}

//Add legacy emojis to mimic how client currently works.
for (const [shortcode, unicode] of Object.entries(legacyEmojioneMap)) {
const key = `:${shortcode}:`;

if (emoji.list[key]) {
continue; // already registered by emojibase
}

emoji.list[key] = {
uc_base: '',
uc_output: '',
uc_match: '',
uc_greedy: '',
shortnames: [],
category: '',
legacy: true,
emojiPackage: 'native',
unicode,
};
}
};

describe('Emoji Client Helpers', () => {
Expand Down Expand Up @@ -66,6 +88,23 @@ describe('Emoji Client Helpers', () => {
expect(names('+1').some((name) => /_tone[1-5]/.test(name))).to.be.false;
});

it('excludes legacy-only names from the results', () => {
expect(names('dog2')).to.be.empty;
});

it('excludes legacy-only names from partial matches', () => {
expect(names('dog')).to.not.include('dog2');
});

it('keeps the emojibase name for the same emoji searchable', () => {
expect(names('dog')).to.include('dog');
expect(names('dog')).to.include('dog_face');
});

it('still renders a legacy shortcode entered manually', () => {
expect(emoji.packages.native.render(':dog2:')).to.include(legacyEmojioneMap.dog2);
});

it('applies the selected skin tone when searching by an alias', () => {
const result = getEmojisBySearchTerm('thumbsup', 2, [], () => undefined).find(({ image }) => image?.includes('馃憤'));

Expand Down
Loading