Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new server emojis format. #654

Merged
merged 1 commit into from
Jun 2, 2017
Merged
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
8 changes: 7 additions & 1 deletion src/html/HtmlNodeTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import HtmlTagStrong from './tags/HtmlTagStrong';
import HtmlTagItalic from './tags/HtmlTagItalic';
import HtmlTagDiv from './tags/HtmlTagDiv';
import HtmlTagBr from './tags/HtmlTagBr';
import { getEmojiUrl } from '../utils/url';

// br', 'blockquote',

Expand Down Expand Up @@ -64,7 +65,12 @@ export default ({ auth, attribs, name, cascadingStyle, childrenNodes, onPress }:
...stylesFromClassNames(attribs.class, cascadingStyles),
];

const HtmlComponent = specialTags[name] || HtmlTagSpan;
let HtmlComponent = specialTags[name] || HtmlTagSpan;

if (attribs.class && attribs.class.startsWith('emoji emoji-')) {
HtmlComponent = HtmlTagImg;
attribs.src = getEmojiUrl(attribs.class.split('-').pop());
}

return (
<HtmlComponent
Expand Down
8 changes: 8 additions & 0 deletions src/utils/__tests__/url-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
isTopicLink,
isGroupLink,
isSpecialLink,
getEmojiUrl,
getNarrowFromLink,
getMessageIdFromLink,
fixRealmUrl,
Expand Down Expand Up @@ -156,6 +157,13 @@ describe('isSpecialLink', () => {
});
});

describe('getEmojiUrl', () => {
test('when unicode is passed, output relative link on server', () => {
const url = getEmojiUrl('1f680');
expect(url).toBe('/static/generated/emoji/images/emoji/unicode/1f680.png');
});
});

describe('getNarrowFromLink', () => {
const users = [
{ email: 'abc@example.com', id: 1 },
Expand Down
3 changes: 3 additions & 0 deletions src/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export const isStreamLink = (url: string, realm: string): boolean =>
export const isSpecialLink = (url: string, realm: string): boolean =>
isUrlInAppLink(url, realm) && url.includes('is');

export const getEmojiUrl = (unicode: string): string =>
`/static/generated/emoji/images/emoji/unicode/${unicode}.png`;

export const getNarrowFromLink = (url: string, realm: string, users: []): [] => {
const paths = url.split(realm).pop().split('/');
if (isGroupLink(url, realm)) {
Expand Down