stream-chat-react-native-core 5.1.1-beta.1 → 5.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/lib/commonjs/components/ChannelList/ChannelListMessenger.js +32 -15
  2. package/lib/commonjs/components/ChannelList/ChannelListMessenger.js.map +1 -1
  3. package/lib/commonjs/components/Chat/Chat.js +17 -5
  4. package/lib/commonjs/components/Chat/Chat.js.map +1 -1
  5. package/lib/commonjs/components/MessageList/MessageList.js +39 -26
  6. package/lib/commonjs/components/MessageList/MessageList.js.map +1 -1
  7. package/lib/commonjs/contexts/debugContext/DebugContext.js +63 -0
  8. package/lib/commonjs/contexts/debugContext/DebugContext.js.map +1 -0
  9. package/lib/commonjs/contexts/index.js +13 -0
  10. package/lib/commonjs/contexts/index.js.map +1 -1
  11. package/lib/commonjs/version.json +1 -1
  12. package/lib/module/components/ChannelList/ChannelListMessenger.js +32 -15
  13. package/lib/module/components/ChannelList/ChannelListMessenger.js.map +1 -1
  14. package/lib/module/components/Chat/Chat.js +17 -5
  15. package/lib/module/components/Chat/Chat.js.map +1 -1
  16. package/lib/module/components/MessageList/MessageList.js +39 -26
  17. package/lib/module/components/MessageList/MessageList.js.map +1 -1
  18. package/lib/module/contexts/debugContext/DebugContext.js +63 -0
  19. package/lib/module/contexts/debugContext/DebugContext.js.map +1 -0
  20. package/lib/module/contexts/index.js +13 -0
  21. package/lib/module/contexts/index.js.map +1 -1
  22. package/lib/module/version.json +1 -1
  23. package/lib/typescript/contexts/debugContext/DebugContext.d.ts +27 -0
  24. package/lib/typescript/contexts/index.d.ts +1 -0
  25. package/package.json +2 -2
  26. package/src/components/ChannelList/ChannelListMessenger.tsx +17 -0
  27. package/src/components/Chat/Chat.tsx +13 -0
  28. package/src/components/MessageList/MessageList.tsx +15 -0
  29. package/src/contexts/debugContext/DebugContext.tsx +77 -0
  30. package/src/contexts/index.ts +1 -0
  31. package/src/version.json +1 -1
@@ -30,6 +30,7 @@ import {
30
30
  useChannelContext,
31
31
  } from '../../contexts/channelContext/ChannelContext';
32
32
  import { ChatContextValue, useChatContext } from '../../contexts/chatContext/ChatContext';
33
+ import { useDebugContext } from '../../contexts/debugContext/DebugContext';
33
34
  import {
34
35
  ImageGalleryContextValue,
35
36
  useImageGalleryContext,
@@ -936,6 +937,20 @@ const MessageListWithContext = <
936
937
  setFlatListRef(ref);
937
938
  }
938
939
  };
940
+
941
+ const debugRef = useDebugContext();
942
+
943
+ const isDebugModeEnabled = __DEV__ && debugRef && debugRef.current;
944
+
945
+ if (isDebugModeEnabled) {
946
+ if (debugRef.current.setEventType) debugRef.current.setEventType('send');
947
+ if (debugRef.current.setSendEventParams)
948
+ debugRef.current.setSendEventParams({
949
+ action: thread ? 'ThreadList' : 'Messages',
950
+ data: messageList,
951
+ });
952
+ }
953
+
939
954
  const renderListEmptyComponent = () => (
940
955
  <View style={[styles.flex, styles.invert]} testID='empty-state'>
941
956
  <EmptyStateIndicator listType='message' />
@@ -0,0 +1,77 @@
1
+ import React, { PropsWithChildren, useContext, useRef } from 'react';
2
+
3
+ import type { Channel, ChannelState, StreamChat } from 'stream-chat';
4
+
5
+ import type { MessageType } from '../../components/MessageList/hooks/useMessageList';
6
+ import type { DefaultStreamChatGenerics } from '../../types/types';
7
+
8
+ import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
9
+
10
+ export type DebugDataType<
11
+ StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
12
+ > =
13
+ | StreamChat<StreamChatGenerics>['user']
14
+ | {
15
+ data: Channel<StreamChatGenerics>['data'];
16
+ members: ChannelState<StreamChatGenerics>['members'];
17
+ }[]
18
+ | MessageType<StreamChatGenerics>[];
19
+
20
+ export type DebugContextValue<
21
+ StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
22
+ > = {
23
+ eventType?: string;
24
+ sendEventParams?: {
25
+ action: string;
26
+ data: DebugDataType<StreamChatGenerics>;
27
+ };
28
+ setEventType?: (data: string) => void;
29
+ setSendEventParams?: (data: { action: string; data: DebugDataType<StreamChatGenerics> }) => void;
30
+ };
31
+
32
+ export const DebugContext = React.createContext(
33
+ DEFAULT_BASE_CONTEXT_VALUE as React.MutableRefObject<DebugContextValue>,
34
+ );
35
+
36
+ export const DebugContextProvider = <
37
+ StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
38
+ >({
39
+ children,
40
+ useFlipper,
41
+ }: PropsWithChildren<{
42
+ useFlipper: () => {
43
+ updateData: (ref: React.RefObject<DebugContextValue<StreamChatGenerics>>) => void;
44
+ };
45
+ }>) => {
46
+ const debugRef = useRef<DebugContextValue<StreamChatGenerics>>({
47
+ eventType: undefined,
48
+ sendEventParams: undefined,
49
+ });
50
+
51
+ const { updateData } = useFlipper();
52
+
53
+ const ref = useRef<DebugContextValue<StreamChatGenerics>>({
54
+ setEventType: (data: string) => {
55
+ debugRef.current.eventType = data;
56
+ updateData(debugRef);
57
+ },
58
+ setSendEventParams: (data: { action: string; data: DebugDataType<StreamChatGenerics> }) => {
59
+ debugRef.current.sendEventParams = data;
60
+ updateData(debugRef);
61
+ },
62
+ });
63
+
64
+ return (
65
+ <DebugContext.Provider value={ref as unknown as React.MutableRefObject<DebugContextValue>}>
66
+ {children}
67
+ </DebugContext.Provider>
68
+ );
69
+ };
70
+
71
+ export const useDebugContext = () => {
72
+ const contextValue = useContext(
73
+ DebugContext,
74
+ ) as unknown as React.MutableRefObject<DebugContextValue>;
75
+
76
+ return contextValue;
77
+ };
@@ -2,6 +2,7 @@ export * from './attachmentPickerContext/AttachmentPickerContext';
2
2
  export * from './channelContext/ChannelContext';
3
3
  export * from './channelsContext/ChannelsContext';
4
4
  export * from './chatContext/ChatContext';
5
+ export * from './debugContext/DebugContext';
5
6
  export * from './imageGalleryContext/ImageGalleryContext';
6
7
  export * from './keyboardContext/KeyboardContext';
7
8
  export * from './messageContext/MessageContext';
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.1.1-beta.1"
2
+ "version": "5.2.0-beta.1"
3
3
  }