Skip to content

Commit fccde69

Browse files
authored
Merge pull request #1960 from GetStream/develop
Next release
2 parents cf80c90 + 6917dcd commit fccde69

File tree

12 files changed

+172
-161
lines changed

12 files changed

+172
-161
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
id: multiple channel lists
3+
sidebar_position: 12
4+
title: Multiple Channel Lists
5+
---
6+
7+
This example will focus on the specific use case where there are two `ChannelList` components in the same application.
8+
9+
The event listeners of both lists, let's say A and B, will pick up all `new.message` events for every channel, regardless of which list the `message` is sent in. If a message is sent in list B, the event listener in list A will also pick up the new `message` and bump the impacted `channel` to the top of the list. This is not the desired result for multiple lists, but there is a correct way to handle the routing of these messages.
10+
11+
## channelRenderFilterFn prop
12+
13+
The reason that a channel will automatically be bumped to the top of a list even though it's not part of the list is due to the default behavior. The ChannelList components will retrieve a channel from `client.activeChannels` if the channel doesn't already exist.
14+
15+
By using the `channelRenderFilterFn` prop we can apply custom filtering logic to the list of channels that are rendered. Since we have access to the entire channel object, we can filter on type, custom fields, or others.
16+
17+
```tsx
18+
const customChannelFilterFunction = (channels: Channel[]) => {
19+
return channels.filter(/** your custom filter logic */);
20+
};
21+
22+
<ChannelList channelRenderFilterFn={customChannelFilterFunction} filters={filters} />;
23+
```

examples/ExpoMessaging/yarn.lock

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4584,6 +4584,13 @@ lines-and-columns@^1.1.6:
45844584
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
45854585
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==
45864586

4587+
linkify-it@^4.0.1:
4588+
version "4.0.1"
4589+
resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-4.0.1.tgz#01f1d5e508190d06669982ba31a7d9f56a5751ec"
4590+
integrity sha512-C7bfi1UZmoj8+PQx22XyeXCuBlokoyWQL5pWSP+EI6nzRylyThouddufc2c1NDIcP9k5agmN9fLpA7VNJfIiqw==
4591+
dependencies:
4592+
uc.micro "^1.0.1"
4593+
45874594
loader-utils@^2.0.0:
45884595
version "2.0.4"
45894596
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.4.tgz#8b5cb38b5c34a9a018ee1fc0e6a066d1dfcc528c"
@@ -6665,10 +6672,10 @@ [email protected]:
66656672
version "0.0.0"
66666673
uid ""
66676674

6668-
6669-
version "5.9.0"
6670-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.0.tgz#a226a1f9d629d1f3e212df1f2a46312c544bc0bb"
6671-
integrity sha512-goG9dyDpVopspGt3gq31ILkwEzdolo0+CdhcpVeGmOB2CZ0tF9X78uByrj4/7VsqpCkC0hi4uMSEsERM3DZdbg==
6675+
6676+
version "5.9.1"
6677+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.1.tgz#c496feb6905e391505adca37c2eef25712a6e6d7"
6678+
integrity sha512-3zWEaoOHNpGAHy7qEI1PFqdx3dq3oHSpEs+PBrHYuUi8Xj7NisKWYkXkK3sa0BSn0hwcduSMZmNGOO9oo9lj2g==
66726679
dependencies:
66736680
"@babel/runtime" "^7.12.5"
66746681
"@gorhom/bottom-sheet" "4.4.5"
@@ -7049,6 +7056,11 @@ ua-parser-js@^0.7.30:
70497056
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.32.tgz#cd8c639cdca949e30fa68c44b7813ef13e36d211"
70507057
integrity sha512-f9BESNVhzlhEFf2CHMSj40NWOjYPl1YKYbrvIr/hFTDEmLq7SRbWvm7FcdcpCYT95zrOhC7gZSxjdnnTpBcwVw==
70517058

7059+
uc.micro@^1.0.1:
7060+
version "1.0.6"
7061+
resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac"
7062+
integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==
7063+
70527064
uglify-es@^3.1.9:
70537065
version "3.3.9"
70547066
resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.9.tgz#0c1c4f0700bed8dbc124cdb304d2592ca203e677"

examples/SampleApp/yarn.lock

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5322,6 +5322,13 @@ lines-and-columns@^1.1.6:
53225322
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
53235323
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==
53245324

5325+
linkify-it@^4.0.1:
5326+
version "4.0.1"
5327+
resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-4.0.1.tgz#01f1d5e508190d06669982ba31a7d9f56a5751ec"
5328+
integrity sha512-C7bfi1UZmoj8+PQx22XyeXCuBlokoyWQL5pWSP+EI6nzRylyThouddufc2c1NDIcP9k5agmN9fLpA7VNJfIiqw==
5329+
dependencies:
5330+
uc.micro "^1.0.1"
5331+
53255332
loader-utils@^2.0.0:
53265333
version "2.0.4"
53275334
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.4.tgz#8b5cb38b5c34a9a018ee1fc0e6a066d1dfcc528c"
@@ -7598,10 +7605,10 @@ [email protected]:
75987605
resolved "https://registry.yarnpkg.com/stream-buffers/-/stream-buffers-2.2.0.tgz#91d5f5130d1cef96dcfa7f726945188741d09ee4"
75997606
integrity sha512-uyQK/mx5QjHun80FLJTfaWE7JtwfRMKBLkMne6udYOmvH0CawotVa7TfgYHzAnpphn4+TweIx1QKMnRIbipmUg==
76007607

7601-
7602-
version "5.9.0"
7603-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.0.tgz#a226a1f9d629d1f3e212df1f2a46312c544bc0bb"
7604-
integrity sha512-goG9dyDpVopspGt3gq31ILkwEzdolo0+CdhcpVeGmOB2CZ0tF9X78uByrj4/7VsqpCkC0hi4uMSEsERM3DZdbg==
7608+
7609+
version "5.9.1"
7610+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.1.tgz#c496feb6905e391505adca37c2eef25712a6e6d7"
7611+
integrity sha512-3zWEaoOHNpGAHy7qEI1PFqdx3dq3oHSpEs+PBrHYuUi8Xj7NisKWYkXkK3sa0BSn0hwcduSMZmNGOO9oo9lj2g==
76057612
dependencies:
76067613
"@babel/runtime" "^7.12.5"
76077614
"@gorhom/bottom-sheet" "4.4.5"
@@ -8020,6 +8027,11 @@ [email protected]:
80208027
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
80218028
integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==
80228029

8030+
uc.micro@^1.0.1:
8031+
version "1.0.6"
8032+
resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac"
8033+
integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==
8034+
80238035
uglify-es@^3.1.9:
80248036
version "3.3.9"
80258037
resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.9.tgz#0c1c4f0700bed8dbc124cdb304d2592ca203e677"

examples/TypeScriptMessaging/yarn.lock

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4999,6 +4999,13 @@ lines-and-columns@^1.1.6:
49994999
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
50005000
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==
50015001

5002+
linkify-it@^4.0.1:
5003+
version "4.0.1"
5004+
resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-4.0.1.tgz#01f1d5e508190d06669982ba31a7d9f56a5751ec"
5005+
integrity sha512-C7bfi1UZmoj8+PQx22XyeXCuBlokoyWQL5pWSP+EI6nzRylyThouddufc2c1NDIcP9k5agmN9fLpA7VNJfIiqw==
5006+
dependencies:
5007+
uc.micro "^1.0.1"
5008+
50025009
loader-utils@^2.0.0:
50035010
version "2.0.4"
50045011
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.4.tgz#8b5cb38b5c34a9a018ee1fc0e6a066d1dfcc528c"
@@ -7161,10 +7168,10 @@ statuses@~1.5.0:
71617168
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"
71627169
integrity sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==
71637170

7164-
7165-
version "5.9.0"
7166-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.0.tgz#a226a1f9d629d1f3e212df1f2a46312c544bc0bb"
7167-
integrity sha512-goG9dyDpVopspGt3gq31ILkwEzdolo0+CdhcpVeGmOB2CZ0tF9X78uByrj4/7VsqpCkC0hi4uMSEsERM3DZdbg==
7171+
7172+
version "5.9.1"
7173+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.1.tgz#c496feb6905e391505adca37c2eef25712a6e6d7"
7174+
integrity sha512-3zWEaoOHNpGAHy7qEI1PFqdx3dq3oHSpEs+PBrHYuUi8Xj7NisKWYkXkK3sa0BSn0hwcduSMZmNGOO9oo9lj2g==
71687175
dependencies:
71697176
"@babel/runtime" "^7.12.5"
71707177
"@gorhom/bottom-sheet" "4.4.5"
@@ -7580,6 +7587,11 @@ [email protected]:
75807587
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
75817588
integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==
75827589

7590+
uc.micro@^1.0.1:
7591+
version "1.0.6"
7592+
resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac"
7593+
integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==
7594+
75837595
uglify-es@^3.1.9:
75847596
version "3.3.9"
75857597
resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.9.tgz#0c1c4f0700bed8dbc124cdb304d2592ca203e677"

package/expo-package/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,10 +2998,10 @@ [email protected]:
29982998
resolved "https://registry.yarnpkg.com/stream-buffers/-/stream-buffers-2.2.0.tgz#91d5f5130d1cef96dcfa7f726945188741d09ee4"
29992999
integrity sha512-uyQK/mx5QjHun80FLJTfaWE7JtwfRMKBLkMne6udYOmvH0CawotVa7TfgYHzAnpphn4+TweIx1QKMnRIbipmUg==
30003000

3001-
3002-
version "5.9.0"
3003-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.0.tgz#a226a1f9d629d1f3e212df1f2a46312c544bc0bb"
3004-
integrity sha512-goG9dyDpVopspGt3gq31ILkwEzdolo0+CdhcpVeGmOB2CZ0tF9X78uByrj4/7VsqpCkC0hi4uMSEsERM3DZdbg==
3001+
3002+
version "5.9.1"
3003+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.1.tgz#c496feb6905e391505adca37c2eef25712a6e6d7"
3004+
integrity sha512-3zWEaoOHNpGAHy7qEI1PFqdx3dq3oHSpEs+PBrHYuUi8Xj7NisKWYkXkK3sa0BSn0hwcduSMZmNGOO9oo9lj2g==
30053005
dependencies:
30063006
"@babel/runtime" "^7.12.5"
30073007
"@gorhom/bottom-sheet" "4.4.5"

package/native-package/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,10 +4403,10 @@ statuses@~1.5.0:
44034403
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"
44044404
integrity sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==
44054405

4406-
4407-
version "5.9.0"
4408-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.0.tgz#a226a1f9d629d1f3e212df1f2a46312c544bc0bb"
4409-
integrity sha512-goG9dyDpVopspGt3gq31ILkwEzdolo0+CdhcpVeGmOB2CZ0tF9X78uByrj4/7VsqpCkC0hi4uMSEsERM3DZdbg==
4406+
4407+
version "5.9.1"
4408+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.1.tgz#c496feb6905e391505adca37c2eef25712a6e6d7"
4409+
integrity sha512-3zWEaoOHNpGAHy7qEI1PFqdx3dq3oHSpEs+PBrHYuUi8Xj7NisKWYkXkK3sa0BSn0hwcduSMZmNGOO9oo9lj2g==
44104410
dependencies:
44114411
"@babel/runtime" "^7.12.5"
44124412
"@gorhom/bottom-sheet" "4.4.5"

package/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"dayjs": "1.10.5",
7373
"file-loader": "6.2.0",
7474
"i18next": "20.2.4",
75+
"linkify-it": "^4.0.1",
7576
"lodash-es": "4.17.21",
7677
"metro-react-native-babel-preset": "0.66.2",
7778
"mime-types": "^2.1.34",
@@ -106,6 +107,7 @@
106107
"@types/react": "17.0.5",
107108
"@types/react-native": "0.67.3",
108109
"@types/react-test-renderer": "17.0.1",
110+
"@types/linkify-it": "3.0.2",
109111
"@types/uuid": "^8.3.4",
110112
"@typescript-eslint/eslint-plugin": "^5.7.0",
111113
"@typescript-eslint/parser": "^5.7.0",

package/src/components/ChannelList/ChannelList.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export type ChannelListProps<
6161
| 'numberOfSkeletons'
6262
>
6363
> & {
64+
/** Optional function to filter channels prior to rendering the list. Do not use any complex logic that would delay the loading of the ChannelList. We recommend using a pure function with array methods like filter/sort/reduce. */
65+
channelRenderFilterFn?: (
66+
channels: Array<Channel<StreamChatGenerics>>,
67+
) => Array<Channel<StreamChatGenerics>>;
6468
/**
6569
* Object containing channel query filters
6670
*
@@ -236,6 +240,7 @@ export const ChannelList = <
236240
) => {
237241
const {
238242
additionalFlatListProps = {},
243+
channelRenderFilterFn,
239244
EmptyStateIndicator = EmptyStateIndicatorDefault,
240245
FooterLoadingIndicator = ChannelListFooterLoadingIndicator,
241246
filters = DEFAULT_FILTERS,
@@ -365,7 +370,7 @@ export const ChannelList = <
365370

366371
const channelsContext = useCreateChannelsContext({
367372
additionalFlatListProps,
368-
channels,
373+
channels: channelRenderFilterFn ? channelRenderFilterFn(channels ?? []) : channels,
369374
EmptyStateIndicator,
370375
error,
371376
FooterLoadingIndicator,

package/src/components/Message/MessageSimple/utils/parseLinks.test.ts

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,116 +2,114 @@ import { parseLinksFromText } from './parseLinks';
22

33
describe('parseLinksFromText', () => {
44
it.each([
5-
['www.getstream.io', 'www.getstream.io'],
6-
['getstream.io', 'getstream.io'],
7-
['scrn://team-chat', 'team-chat'],
8-
['https://localhost', 'localhost'],
5+
['https://www.getstream.io', 'https://www.getstream.io'],
6+
['https://getstream.io', 'https://getstream.io'],
7+
['scrn://team-chat', undefined],
8+
['https://localhost', 'https://localhost'],
99
[
1010
'https://localhost/with/path?and=query&multiple=params',
11-
'localhost/with/path?and=query&multiple=params',
11+
'https://localhost/with/path?and=query&multiple=params',
12+
],
13+
[
14+
'https://localhost/with/path?and=query#fragment',
15+
'https://localhost/with/path?and=query#fragment',
1216
],
13-
['https://localhost/with/path?and=query#fragment', 'localhost/with/path?and=query#fragment'],
14-
['reactnative.stream', 'reactnative.stream'],
17+
['reactnative.stream', undefined],
1518
[
1619
'https://zh.wikipedia.org/wiki/挪威牛油危機',
17-
'zh.wikipedia.org/wiki/%E6%8C%AA%E5%A8%81%E7%89%9B%E6%B2%B9%E5%8D%B1%E6%A9%9F',
20+
'https://zh.wikipedia.org/wiki/%E6%8C%AA%E5%A8%81%E7%89%9B%E6%B2%B9%E5%8D%B1%E6%A9%9F',
1821
],
1922
[
2023
'https://getstream.io/chat/docs/react-native/?language=javascript',
21-
'getstream.io/chat/docs/react-native/?language=javascript',
24+
'https://getstream.io/chat/docs/react-native/?language=javascript',
2225
],
23-
['127.0.0.1/local_(development)_server', '127.0.0.1/local_(development)_server'],
24-
['https://a.co:8999/ab.php?p=12', 'a.co:8999/ab.php?p=12'],
26+
['127.0.0.1/local_(development)_server', undefined],
27+
['https://a.co:8999/ab.php?p=12', 'https://a.co:8999/ab.php?p=12'],
2528
[
26-
'http://help.apple.com/xcode/mac/current/#/devba7f53ad4',
27-
'help.apple.com/xcode/mac/current/#/devba7f53ad4',
29+
'https://help.apple.com/xcode/mac/current/#/devba7f53ad4',
30+
'https://help.apple.com/xcode/mac/current/#/devba7f53ad4',
2831
],
2932
])('Returns the encoded value of %p as %p', (link, expected) => {
3033
const result = parseLinksFromText(link);
31-
32-
expect(result[0].encoded).toBe(expected);
34+
expect(result[0]?.encodedUrl).toBe(expected);
3335
});
34-
3536
it('parses fqdn', () => {
3637
const input = `We have put the apim bol,
37-
temporarily so :sj: we can later put the monitors on my grasp
38-
on reality right now is
39-
https://www.contrived-example.com:8080/sub/page.php?p1=1🇳🇴&p2=2#fragment-identifier
40-
:)`;
41-
38+
temporarily so :sj: we can later put the monitors on my grasp
39+
on reality right now is
40+
https://www.contrived-example.com:8080/sub/page.php?p1=1🇳🇴&p2=2#fragment-identifier
41+
:)`;
4242
const result = parseLinksFromText(input);
43-
4443
expect(result).toEqual([
4544
{
46-
encoded:
47-
'www.contrived-example.com:8080/sub/page.php?p1=1%F0%9F%87%B3%F0%9F%87%B4&p2=2#fragment-identifier',
45+
encodedUrl:
46+
'https://www.contrived-example.com:8080/sub/page.php?p1=1%F0%9F%87%B3%F0%9F%87%B4&p2=2#fragment-identifier',
4847
raw: 'https://www.contrived-example.com:8080/sub/page.php?p1=1🇳🇴&p2=2#fragment-identifier',
49-
scheme: 'https://',
5048
},
5149
]);
5250
});
53-
5451
it.each([
5552
5653
5754
5855
5956
])('Can parse the email address %p', (email) => {
6057
const result = parseLinksFromText(email);
61-
62-
expect(result[0].encoded).toBe(email);
63-
expect(result[0].scheme).toBe('mailto:');
58+
expect(result[0].encodedUrl).toBe('mailto:' + email);
59+
expect(result[0].raw).toBe(email);
6460
});
65-
6661
it("doesn't double the mailto prefix", () => {
6762
const input = 'mailto:[email protected]';
68-
6963
const result = parseLinksFromText(input);
70-
7164
expect(result[0]).toEqual({
72-
encoded: '[email protected]',
65+
encodedUrl: input,
7366
raw: input,
74-
scheme: 'mailto:',
7567
});
7668
});
77-
7869
it('Does not falsely parse LINKs from text content', () => {
7970
const input = `#This string exists to test that we don't produce false positives
80-
81-
Existing links:
82-
[already a parsed link](https://getstream.io/blog/react-native-how-to-build-bidirectional-infinite-scroll/)
83-
[even a bogus one]( should not match )
84-
85-
## These should, however, be parsed:
86-
www.getstream.io
87-
getstream.io
88-
`;
71+
Existing links:
72+
[already a parsed link](https://getstream.io/blog/react-native-how-to-build-bidirectional-infinite-scroll/)
73+
[even a bogus one]( should not match )
74+
## These should, however, be parsed:
75+
www.getstream.io
76+
getstream.io
77+
`;
8978
const result = parseLinksFromText(input);
90-
79+
console.log({ result });
9180
expect(result).toHaveLength(2);
9281
});
93-
9482
it('Encodes incomplete emoji unicode', () => {
9583
const input = 'https://getstream.io/�';
9684
const result = parseLinksFromText(input);
97-
9885
expect(result[0]).toEqual({
99-
encoded: 'getstream.io/%EF%BF%BD',
100-
raw: 'https://getstream.io/�',
101-
scheme: 'https://',
86+
encodedUrl: 'https://getstream.io/%EF%BF%BD',
87+
raw: input,
10288
});
10389
});
104-
90+
it('doest not report invalid tlds as urls', () => {
91+
const input = `
92+
%
93+
% Not links
94+
%
95+
example.invalid
96+
example.invalid/
97+
http://.example.com
98+
http://-example.com
99+
hppt://example.com
100+
example.coma
101+
-example.coma
102+
`;
103+
const result = parseLinksFromText(input);
104+
expect(result).toHaveLength(0);
105+
});
105106
it('does not parse a decimal number as a URL', () => {
106107
const input = '123.456';
107108
const result = parseLinksFromText(input);
108-
109109
expect(result).toHaveLength(0);
110110
});
111-
112111
it.each([['@user'], ['@user.name']])('does not parse %p as a URL', (input) => {
113112
const result = parseLinksFromText(input);
114-
115113
expect(result).toHaveLength(0);
116114
});
117115
});

0 commit comments

Comments
 (0)