Skip to content

Commit 76965eb

Browse files
committed
emoji types: Split ImageEmojiType into RealmEmoji and ImageEmoji
With ImageEmoji being the same as RealmEmoji except for an added reaction_type property. See discussion: zulip#5508 (comment)
1 parent 01173d0 commit 76965eb

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

src/api/modelTypes.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export type CustomProfileField = {|
8585
+display_in_profile_summary?: true,
8686
|};
8787

88-
export type ImageEmojiType = $ReadOnly<{|
88+
export type RealmEmoji = $ReadOnly<{|
8989
author?: $ReadOnly<{|
9090
email: string,
9191
full_name: string,
@@ -99,7 +99,16 @@ export type ImageEmojiType = $ReadOnly<{|
9999
|}>;
100100

101101
export type RealmEmojiById = $ReadOnly<{|
102-
[id: string]: ImageEmojiType,
102+
[id: string]: RealmEmoji,
103+
|}>;
104+
105+
export type ImageEmoji = {|
106+
...RealmEmoji,
107+
+reaction_type: ReactionType, // eslint-disable-line no-use-before-define
108+
|};
109+
110+
export type ImageEmojiById = $ReadOnly<{|
111+
[id: string]: ImageEmoji,
103112
|}>;
104113

105114
/**

src/emoji/__tests__/emojiSelectors-test.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ describe('getActiveImageEmojiById', () => {
3333

3434
const expectedResult = {
3535
1: {
36+
reaction_type: 'realm_emoji',
3637
deactivated: false,
3738
source_url: 'https://example.com/static/user_upload/smile.png',
3839
},
3940
2: {
41+
reaction_type: 'realm_emoji',
4042
deactivated: false,
4143
source_url: 'https://example.com/static/user_upload/laugh.png',
4244
},
4345
zulip: {
46+
reaction_type: 'zulip_extra_emoji',
4447
deactivated: false,
4548
name: 'zulip',
4649
code: 'zulip',
@@ -69,9 +72,16 @@ describe('getAllImageEmojiById', () => {
6972
};
7073

7174
const expectedResult = {
72-
'1': { source_url: 'https://example.com/static/user_upload/smile.png' },
73-
'2': { source_url: 'https://example.com/static/user_upload/laugh.png' },
75+
'1': {
76+
reaction_type: 'realm_emoji',
77+
source_url: 'https://example.com/static/user_upload/smile.png',
78+
},
79+
'2': {
80+
reaction_type: 'realm_emoji',
81+
source_url: 'https://example.com/static/user_upload/laugh.png',
82+
},
7483
zulip: {
84+
reaction_type: 'zulip_extra_emoji',
7585
deactivated: false,
7686
name: 'zulip',
7787
code: 'zulip',
@@ -105,16 +115,19 @@ describe('getAllImageEmojiByCode', () => {
105115

106116
const expectedResult = {
107117
1: {
118+
reaction_type: 'realm_emoji',
108119
code: '1',
109120
name: 'smile',
110121
source_url: 'https://example.com/static/user_upload/smile.png',
111122
},
112123
2: {
124+
reaction_type: 'realm_emoji',
113125
code: '2',
114126
name: 'laugh',
115127
source_url: 'https://example.com/static/user_upload/laugh.png',
116128
},
117129
zulip: {
130+
reaction_type: 'zulip_extra_emoji',
118131
deactivated: false,
119132
name: 'zulip',
120133
code: 'zulip',

src/emoji/emojiSelectors.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
11
/* @flow strict-local */
22
import { createSelector } from 'reselect';
3-
import type { Selector, RealmEmojiById, ImageEmojiType, EmojiForShared } from '../types';
3+
import type { Selector, ImageEmoji, ImageEmojiById, EmojiForShared } from '../types';
44
import { getRawRealmEmoji } from '../directSelectors';
55
import { getIdentity } from '../account/accountsSelectors';
66
import zulipExtraEmojiMap from './zulipExtraEmojiMap';
77
import { objectFromEntries } from '../jsBackport';
8+
import type { ReadWrite } from '../generics';
9+
import { objectEntries } from '../flowPonyfill';
810

9-
export const getAllImageEmojiById: Selector<RealmEmojiById> = createSelector(
11+
export const getAllImageEmojiById: Selector<ImageEmojiById> = createSelector(
1012
getIdentity,
1113
getRawRealmEmoji,
1214
(identity, realmEmoji) => {
13-
const result: {| [string]: ImageEmojiType |} = {};
14-
[realmEmoji, zulipExtraEmojiMap].forEach(emojis => {
15-
Object.keys(emojis).forEach(id => {
16-
result[id] = {
17-
...emojis[id],
18-
source_url: new URL(emojis[id].source_url, identity.realm).toString(),
19-
};
20-
});
15+
const result: ReadWrite<ImageEmojiById> = {};
16+
objectEntries(realmEmoji).forEach(([id, emoji]) => {
17+
result[id] = {
18+
...emoji,
19+
reaction_type: 'realm_emoji',
20+
source_url: new URL(emoji.source_url, identity.realm).toString(),
21+
};
22+
});
23+
objectEntries(zulipExtraEmojiMap).forEach(([id, emoji]) => {
24+
result[id] = {
25+
...emoji,
26+
source_url: new URL(emoji.source_url, identity.realm).toString(),
27+
};
2128
});
2229
return result;
2330
},
2431
);
2532

26-
export const getActiveImageEmojiById: Selector<RealmEmojiById> = createSelector(
33+
export const getActiveImageEmojiById: Selector<ImageEmojiById> = createSelector(
2734
getAllImageEmojiById,
2835
emojis => {
29-
const result: {| [string]: ImageEmojiType |} = {};
36+
const result: ReadWrite<ImageEmojiById> = {};
3037
Object.keys(emojis).forEach(id => {
3138
if (!emojis[id].deactivated) {
3239
result[id] = emojis[id];
@@ -37,7 +44,7 @@ export const getActiveImageEmojiById: Selector<RealmEmojiById> = createSelector(
3744
);
3845

3946
export const getAllImageEmojiByCode: Selector<{|
40-
[string]: ImageEmojiType,
47+
[string]: ImageEmoji,
4148
|}> = createSelector(getAllImageEmojiById, emojis =>
4249
objectFromEntries(Object.keys(emojis).map(id => [emojis[id].code, emojis[id]])),
4350
);

src/emoji/zulipExtraEmojiMap.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/* @flow strict-local */
2-
import type { ImageEmojiType } from '../types';
2+
import type { ImageEmoji } from '../types';
33

44
/**
55
* Make this to ressemble with realm emoji
66
* so that both emoji type can be handled in similiar way
77
* thus id has no meaning here
88
*/
9-
const zulipExtraEmojiMap: {| [id: string]: ImageEmojiType |} = {
9+
const zulipExtraEmojiMap: {| [id: string]: ImageEmoji |} = {
1010
zulip: {
11+
reaction_type: 'zulip_extra_emoji',
1112
deactivated: false,
1213
code: 'zulip',
1314
name: 'zulip',

src/webview/backgroundData.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
Debug,
77
FlagsState,
88
GlobalSettingsState,
9-
ImageEmojiType,
9+
ImageEmoji,
1010
MuteState,
1111
MutedUsersState,
1212
PerAccountState,
@@ -50,7 +50,7 @@ import type { ServerEmojiData } from '../api/modelTypes';
5050
*/
5151
export type BackgroundData = $ReadOnly<{|
5252
alertWords: AlertWordsState,
53-
allImageEmojiById: $ReadOnly<{| [id: string]: ImageEmojiType |}>,
53+
allImageEmojiById: $ReadOnly<{| [id: string]: ImageEmoji |}>,
5454
auth: Auth,
5555
debug: Debug,
5656
flags: FlagsState,

0 commit comments

Comments
 (0)