Skip to content

Commit 09647d7

Browse files
committed
Merge branch 'master' into thread-typing-events
2 parents e011ded + a1e7c8a commit 09647d7

File tree

14 files changed

+136
-28
lines changed

14 files changed

+136
-28
lines changed

examples/SampleApp/android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ android {
139139
targetSdkVersion rootProject.ext.targetSdkVersion
140140
multiDexEnabled true
141141
vectorDrawables.useSupportLibrary = true
142-
versionCode 21
143-
versionName "0.0.21"
142+
versionCode 22
143+
versionName "0.0.22"
144144
}
145145
splits {
146146
abi {

examples/SampleApp/ios/SampleApp-tvOS/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.0.21</string>
18+
<string>0.0.22</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>21</string>
22+
<string>22</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true />
2525
<key>NSAppTransportSecurity</key>

examples/SampleApp/ios/SampleApp-tvOSTests/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
<key>CFBundlePackageType</key>
1616
<string>BNDL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.0.21</string>
18+
<string>0.0.22</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>21</string>
22+
<string>22</string>
2323
</dict>
2424
</plist>

examples/SampleApp/ios/SampleApp.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@
672672
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
673673
CLANG_ENABLE_MODULES = YES;
674674
CODE_SIGN_IDENTITY = "iPhone Distribution";
675-
CURRENT_PROJECT_VERSION = 21;
675+
CURRENT_PROJECT_VERSION = 22;
676676
DEVELOPMENT_TEAM = EHV7XZLAHA;
677677
ENABLE_BITCODE = NO;
678678
INFOPLIST_FILE = SampleApp/Info.plist;
@@ -699,7 +699,7 @@
699699
CLANG_ENABLE_MODULES = YES;
700700
CODE_SIGN_IDENTITY = "iPhone Distribution";
701701
CODE_SIGN_STYLE = Manual;
702-
CURRENT_PROJECT_VERSION = 21;
702+
CURRENT_PROJECT_VERSION = 22;
703703
DEVELOPMENT_TEAM = EHV7XZLAHA;
704704
INFOPLIST_FILE = SampleApp/Info.plist;
705705
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";

examples/SampleApp/ios/SampleApp/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>0.0.21</string>
20+
<string>0.0.22</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>
24-
<string>21</string>
24+
<string>22</string>
2525
<key>LSRequiresIPhoneOS</key>
2626
<true />
2727
<key>NSAppTransportSecurity</key>

examples/SampleApp/ios/SampleAppTests/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
<key>CFBundlePackageType</key>
1616
<string>BNDL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.0.21</string>
18+
<string>0.0.22</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>21</string>
22+
<string>22</string>
2323
</dict>
2424
</plist>

examples/SampleApp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "SampleApp",
3-
"version": "0.0.21",
3+
"version": "0.0.22",
44
"private": true,
55
"scripts": {
66
"android": "npx react-native run-android",

src/components/ChannelList/ChannelList.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import { useChannelDeleted } from './hooks/listeners/useChannelDeleted';
1313
import { useChannelHidden } from './hooks/listeners/useChannelHidden';
1414
import { useChannelTruncated } from './hooks/listeners/useChannelTruncated';
1515
import { useChannelUpdated } from './hooks/listeners/useChannelUpdated';
16+
import { useChannelVisible } from './hooks/listeners/useChannelVisible';
1617
import { useConnectionRecovered } from './hooks/listeners/useConnectionRecovered';
1718
import { useNewMessage } from './hooks/listeners/useNewMessage';
1819
import { useNewMessageNotification } from './hooks/listeners/useNewMessageNotification';
19-
import { useCreateChannelsContext } from './hooks/useCreateChannelsContext';
20-
import { usePaginatedChannels } from './hooks/usePaginatedChannels';
2120
import { useRemovedFromChannelNotification } from './hooks/listeners/useRemovedFromChannelNotification';
2221
import { useUserPresence } from './hooks/listeners/useUserPresence';
22+
import { useCreateChannelsContext } from './hooks/useCreateChannelsContext';
23+
import { usePaginatedChannels } from './hooks/usePaginatedChannels';
2324
import { Skeleton as SkeletonDefault } from './Skeleton';
2425

2526
import { ChannelPreviewMessenger } from '../ChannelPreview/ChannelPreviewMessenger';
@@ -174,6 +175,20 @@ export type ChannelListProps<
174175
>,
175176
event: Event<At, Ch, Co, Ev, Me, Re, Us>,
176177
) => void;
178+
/**
179+
* Function that overrides default behavior when a channel gets visible. In absence of this prop, the channel will be added to the list.
180+
*
181+
* @param setChannels Setter for internal state property - `channels`. It's created from useState() hook.
182+
* @param event An [Event object](https://getstream.io/chat/docs/event_object) corresponding to `channel.visible` event
183+
*
184+
* @overrideType Function
185+
* */
186+
onChannelVisible?: (
187+
setChannels: React.Dispatch<
188+
React.SetStateAction<Channel<At, Ch, Co, Ev, Me, Re, Us>[]>
189+
>,
190+
event: Event<At, Ch, Co, Ev, Me, Re, Us>,
191+
) => void;
177192
/**
178193
* Override the default listener/handler for event `notification.message_new`
179194
* This event is received on channel, which is not being watched.
@@ -256,6 +271,7 @@ export const ChannelList = <
256271
onAddedToChannel,
257272
onChannelDeleted,
258273
onChannelHidden,
274+
onChannelVisible,
259275
onChannelTruncated,
260276
onChannelUpdated,
261277
onMessageNew,
@@ -320,6 +336,11 @@ export const ChannelList = <
320336
setChannels,
321337
});
322338

339+
useChannelVisible({
340+
onChannelVisible,
341+
setChannels,
342+
});
343+
323344
useConnectionRecovered<At, Ch, Co, Ev, Me, Re, Us>({
324345
refreshList,
325346
setForceUpdate,
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { useEffect } from 'react';
2+
import uniqBy from 'lodash/uniqBy';
3+
4+
import { useChatContext } from '../../../../contexts/chatContext/ChatContext';
5+
import { getChannel } from '../../utils';
6+
7+
import type { Channel, Event } from 'stream-chat';
8+
9+
import type {
10+
DefaultAttachmentType,
11+
DefaultChannelType,
12+
DefaultCommandType,
13+
DefaultEventType,
14+
DefaultMessageType,
15+
DefaultReactionType,
16+
DefaultUserType,
17+
UnknownType,
18+
} from '../../../../types/types';
19+
20+
type Parameters<
21+
At extends UnknownType = DefaultAttachmentType,
22+
Ch extends UnknownType = DefaultChannelType,
23+
Co extends string = DefaultCommandType,
24+
Ev extends UnknownType = DefaultEventType,
25+
Me extends UnknownType = DefaultMessageType,
26+
Re extends UnknownType = DefaultReactionType,
27+
Us extends UnknownType = DefaultUserType
28+
> = {
29+
setChannels: React.Dispatch<
30+
React.SetStateAction<Channel<At, Ch, Co, Ev, Me, Re, Us>[]>
31+
>;
32+
onChannelVisible?: (
33+
setChannels: React.Dispatch<
34+
React.SetStateAction<Channel<At, Ch, Co, Ev, Me, Re, Us>[]>
35+
>,
36+
event: Event<At, Ch, Co, Ev, Me, Re, Us>,
37+
) => void;
38+
};
39+
40+
export const useChannelVisible = <
41+
At extends UnknownType = DefaultAttachmentType,
42+
Ch extends UnknownType = DefaultChannelType,
43+
Co extends string = DefaultCommandType,
44+
Ev extends UnknownType = DefaultEventType,
45+
Me extends UnknownType = DefaultMessageType,
46+
Re extends UnknownType = DefaultReactionType,
47+
Us extends UnknownType = DefaultUserType
48+
>({
49+
onChannelVisible,
50+
setChannels,
51+
}: Parameters<At, Ch, Co, Ev, Me, Re, Us>) => {
52+
const { client } = useChatContext<At, Ch, Co, Ev, Me, Re, Us>();
53+
54+
useEffect(() => {
55+
const handleEvent = async (event: Event<At, Ch, Co, Ev, Me, Re, Us>) => {
56+
if (typeof onChannelVisible === 'function') {
57+
onChannelVisible(setChannels, event);
58+
} else {
59+
if (event.channel_id && event.channel_type) {
60+
const channel = await getChannel<At, Ch, Co, Ev, Me, Re, Us>({
61+
client,
62+
id: event.channel_id,
63+
type: event.channel_type,
64+
});
65+
setChannels((channels) => uniqBy([channel, ...channels], 'cid'));
66+
}
67+
}
68+
};
69+
70+
client.on('channel.visible', handleEvent);
71+
return () => client.off('channel.visible', handleEvent);
72+
}, []);
73+
};

src/components/ChannelList/hooks/usePaginatedChannels.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const usePaginatedChannels = <
136136
const reloadList = () => queryChannels('reload');
137137

138138
/**
139-
* Equality check using stringified filters ensure that we don't make un-necessary queryChannels api calls
139+
* Equality check using stringified filters/sort ensure that we don't make un-necessary queryChannels api calls
140140
* for the scenario:
141141
*
142142
* <ChannelList
@@ -151,10 +151,11 @@ export const usePaginatedChannels = <
151151
* in return will trigger useEffect. To avoid this, we can add a value check.
152152
*/
153153
const filterStr = useMemo(() => JSON.stringify(filters), [filters]);
154+
const sortStr = useMemo(() => JSON.stringify(sort), [sort]);
154155

155156
useEffect(() => {
156157
reloadList();
157-
}, [filterStr]);
158+
}, [filterStr, sortStr]);
158159

159160
return {
160161
channels,

0 commit comments

Comments
 (0)