Skip to content

Commit

Permalink
Support new server emojis format.
Browse files Browse the repository at this point in the history
Fixes: #603
  • Loading branch information
Sam1301 authored and borisyankov committed Jun 2, 2017
1 parent 5b291b1 commit f9e1cf9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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

0 comments on commit f9e1cf9

Please sign in to comment.