Skip to content

Commit 5df205a

Browse files
author
Tom Hutman
committed
Merge branch 'master' into fix-mentions-text-replace
2 parents 4250e56 + 65aff45 commit 5df205a

File tree

13 files changed

+102
-12
lines changed

13 files changed

+102
-12
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
"eslint-plugin-react-hooks": "^4.2.0",
120120
"eslint-plugin-sort-destructure-keys": "1.3.5",
121121
"eslint-plugin-typescript-sort-keys": "1.5.0",
122+
"file-loader": "^6.2.0",
122123
"htmlparser2": "^5.0.1",
123124
"husky": "^4.3.0",
124125
"jest": "^26.6.3",

src/assets/EmojiOneColor.woff2

3.19 MB
Binary file not shown.
752 KB
Binary file not shown.

src/components/AutoCompleteTextarea/List.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useCallback, useContext, useEffect, useState } from 'react';
22

33
import { TranslationContext } from '../../context/TranslationContext';
4+
import { escapeRegExp } from '../../utils';
45

56
import Item from './Item';
67
import { KEY_CODES } from './listener';
@@ -125,7 +126,7 @@ const List = (props) => {
125126
const restructureItem = (item) => {
126127
const matched = item.name || item.id;
127128

128-
const editedPropValue = propValue.slice(1);
129+
const editedPropValue = escapeRegExp(propValue.slice(1));
129130
const parts = matched.split(new RegExp(`(${editedPropValue})`, 'gi'));
130131

131132
const itemNameParts = { match: editedPropValue, parts };

src/components/Channel/Channel.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,15 @@ const ChannelInner = <
244244
onMentionsHover,
245245
} = props;
246246

247-
const { client, mutes, theme } = useChatContext<At, Ch, Co, Ev, Me, Re, Us>();
247+
const { client, mutes, theme, useImageFlagEmojisOnWindows } = useChatContext<
248+
At,
249+
Ch,
250+
Co,
251+
Ev,
252+
Me,
253+
Re,
254+
Us
255+
>();
248256
const { t } = useTranslationContext();
249257

250258
const [notifications, setNotifications] = useState<ChannelNotifications>([]);
@@ -804,7 +812,13 @@ const ChannelInner = <
804812
}
805813

806814
return (
807-
<div className={`str-chat str-chat-channel ${theme}`}>
815+
<div
816+
className={`str-chat str-chat-channel ${theme}${
817+
useImageFlagEmojisOnWindows && navigator.platform.match(/Win/)
818+
? ' str-chat--windows-flags'
819+
: ''
820+
}`}
821+
>
808822
<ChannelProvider<At, Ch, Co, Ev, Me, Re, Us> value={channelContextValue}>
809823
<div className='str-chat__container'>{children}</div>
810824
</ChannelProvider>

src/components/ChannelList/ChannelList.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ const UnMemoizedChannelList = <
291291
navOpen = false,
292292
setActiveChannel,
293293
theme,
294+
useImageFlagEmojisOnWindows,
294295
} = useChatContext<At, Ch, Co, Ev, Me, Re, Us>();
295296

296297
const channelListRef = useRef<HTMLDivElement>(null);
@@ -441,6 +442,10 @@ const UnMemoizedChannelList = <
441442
<div
442443
className={`str-chat str-chat-channel-list ${theme} ${
443444
navOpen ? 'str-chat-channel-list--open' : ''
445+
} ${
446+
useImageFlagEmojisOnWindows && navigator.platform.match(/Win/)
447+
? 'str-chat--windows-flags'
448+
: ''
444449
}`}
445450
ref={channelListRef}
446451
>

src/components/Chat/Chat.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ export type ChatProps<
8383
* - `livestream dark`
8484
*/
8585
theme?: Theme;
86+
/**
87+
* Windows 10 does not support country flag emojis out of the box.
88+
* It chooses to render these emojis as characters instead.
89+
* Stream chat can override this by loading a custom web font that will
90+
* render images (PNGs or SVGs depending on the platform) instead.
91+
* Set this prop to true if you want to use these custom emojis for Windows users.
92+
*/
93+
useImageFlagEmojisOnWindows?: boolean;
8694
};
8795

8896
/**
@@ -121,6 +129,7 @@ export const Chat = <
121129
i18nInstance,
122130
initialNavOpen = true,
123131
theme = 'messaging light',
132+
useImageFlagEmojisOnWindows = false,
124133
} = props;
125134

126135
const {
@@ -136,7 +145,7 @@ export const Chat = <
136145
if (!translators.t) return null;
137146

138147
return (
139-
<ChatProvider<At, Ch, Co, Ev, Me, Re, Us>
148+
<ChatProvider
140149
value={{
141150
channel,
142151
client,
@@ -146,6 +155,7 @@ export const Chat = <
146155
openMobileNav,
147156
setActiveChannel,
148157
theme,
158+
useImageFlagEmojisOnWindows,
149159
}}
150160
>
151161
<TranslationProvider value={translators}>{children}</TranslationProvider>

src/components/Chat/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './Chat';
2+
export * from './hooks/useChat';

src/context/ChatContext.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@ export type ChatContextValue<
2525
Us extends DefaultUserType<Us> = DefaultUserType
2626
> = {
2727
client: StreamChat<At, Ch, Co, Ev, Me, Re, Us>;
28-
theme: Theme;
29-
channel?: Channel<At, Ch, Co, Ev, Me, Re, Us>;
30-
closeMobileNav?: () => void;
31-
mutes?: Mute<Us>[];
32-
navOpen?: boolean;
33-
openMobileNav?: () => void;
34-
setActiveChannel?: (
28+
closeMobileNav: () => void;
29+
mutes: Mute<Us>[];
30+
openMobileNav: () => void;
31+
setActiveChannel: (
3532
newChannel?: Channel<At, Ch, Co, Ev, Me, Re, Us>,
3633
watchers?: { limit?: number; offset?: number },
3734
event?: React.SyntheticEvent,
3835
) => void;
36+
theme: Theme;
37+
useImageFlagEmojisOnWindows: boolean;
38+
channel?: Channel<At, Ch, Co, Ev, Me, Re, Us>;
39+
navOpen?: boolean;
3940
};
4041

4142
export const ChatContext = React.createContext({} as ChatContextValue);

src/styles/_base.scss

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,47 @@
6767
}
6868
}
6969

70+
/* declare a font faces for our Emoji Replacement font, based on the default font used by Stream Chat React */
71+
72+
$emoji-flag-unicode-range: U+1F1E6-1F1FF;
73+
74+
/* png based woff for most browsers */
75+
@font-face {
76+
font-family: ReplaceFlagEmojiPNG;
77+
src: url("../assets/NotoColorEmoji-flags.woff2") format("woff2");
78+
/* using the unicode-range attribute to limit the reach of the Flag Emoji web font to only flags */
79+
unicode-range: $emoji-flag-unicode-range;
80+
}
81+
82+
/* svg based for firefox */
83+
@font-face {
84+
font-family: ReplaceFlagEmojiSVG;
85+
src: url("../assets/EmojiOneColor.woff2") format("woff2");
86+
unicode-range: $emoji-flag-unicode-range;
87+
}
88+
89+
.str-chat--windows-flags {
90+
.str-chat__textarea__textarea,
91+
.str-chat__message-text-inner *,
92+
.str-chat__emoji-item--entity,
93+
.emoji-mart-emoji-native * {
94+
font-family: ReplaceFlagEmojiPNG, $second-font, sans-serif;
95+
font-display: swap;
96+
}
97+
}
98+
99+
@-moz-document url-prefix() {
100+
.str-chat--windows-flags {
101+
.str-chat__textarea__textarea,
102+
.str-chat__message-text-inner *,
103+
.str-chat__emoji-item--entity,
104+
.emoji-mart-emoji-native * {
105+
font-family: ReplaceFlagEmojiSVG, $second-font, sans-serif;
106+
font-display: swap;
107+
}
108+
}
109+
}
110+
70111
.str-chat-channel-list {
71112
float: left;
72113
}

0 commit comments

Comments
 (0)