stream-chat-react-native-core 3.9.0-next.1 → 3.9.0-next.2

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 (62) hide show
  1. package/lib/commonjs/components/Attachment/Gallery.js +21 -9
  2. package/lib/commonjs/components/Attachment/Gallery.js.map +1 -1
  3. package/lib/commonjs/components/Channel/Channel.js +22 -12
  4. package/lib/commonjs/components/Channel/Channel.js.map +1 -1
  5. package/lib/commonjs/components/Channel/hooks/useCreateChannelContext.js +4 -0
  6. package/lib/commonjs/components/Channel/hooks/useCreateChannelContext.js.map +1 -1
  7. package/lib/commonjs/components/Channel/hooks/useCreateMessagesContext.js +4 -0
  8. package/lib/commonjs/components/Channel/hooks/useCreateMessagesContext.js.map +1 -1
  9. package/lib/commonjs/components/Message/MessageSimple/MessageSimple.js +9 -6
  10. package/lib/commonjs/components/Message/MessageSimple/MessageSimple.js.map +1 -1
  11. package/lib/commonjs/components/MessageList/MessageList.js +40 -31
  12. package/lib/commonjs/components/MessageList/MessageList.js.map +1 -1
  13. package/lib/commonjs/components/MessageList/hooks/useMessageList.js +1 -1
  14. package/lib/commonjs/components/MessageList/hooks/useMessageList.js.map +1 -1
  15. package/lib/commonjs/components/MessageList/utils/getGroupStyles.js +1 -5
  16. package/lib/commonjs/components/MessageList/utils/getGroupStyles.js.map +1 -1
  17. package/lib/commonjs/contexts/channelContext/ChannelContext.js +2 -2
  18. package/lib/commonjs/contexts/channelContext/ChannelContext.js.map +1 -1
  19. package/lib/commonjs/contexts/messagesContext/MessagesContext.js +2 -2
  20. package/lib/commonjs/contexts/messagesContext/MessagesContext.js.map +1 -1
  21. package/lib/commonjs/version.json +1 -1
  22. package/lib/module/components/Attachment/Gallery.js +21 -9
  23. package/lib/module/components/Attachment/Gallery.js.map +1 -1
  24. package/lib/module/components/Channel/Channel.js +22 -12
  25. package/lib/module/components/Channel/Channel.js.map +1 -1
  26. package/lib/module/components/Channel/hooks/useCreateChannelContext.js +4 -0
  27. package/lib/module/components/Channel/hooks/useCreateChannelContext.js.map +1 -1
  28. package/lib/module/components/Channel/hooks/useCreateMessagesContext.js +4 -0
  29. package/lib/module/components/Channel/hooks/useCreateMessagesContext.js.map +1 -1
  30. package/lib/module/components/Message/MessageSimple/MessageSimple.js +9 -6
  31. package/lib/module/components/Message/MessageSimple/MessageSimple.js.map +1 -1
  32. package/lib/module/components/MessageList/MessageList.js +40 -31
  33. package/lib/module/components/MessageList/MessageList.js.map +1 -1
  34. package/lib/module/components/MessageList/hooks/useMessageList.js +1 -1
  35. package/lib/module/components/MessageList/hooks/useMessageList.js.map +1 -1
  36. package/lib/module/components/MessageList/utils/getGroupStyles.js +1 -5
  37. package/lib/module/components/MessageList/utils/getGroupStyles.js.map +1 -1
  38. package/lib/module/contexts/channelContext/ChannelContext.js +2 -2
  39. package/lib/module/contexts/channelContext/ChannelContext.js.map +1 -1
  40. package/lib/module/contexts/messagesContext/MessagesContext.js +2 -2
  41. package/lib/module/contexts/messagesContext/MessagesContext.js.map +1 -1
  42. package/lib/module/version.json +1 -1
  43. package/lib/typescript/components/Attachment/Gallery.d.ts +1 -1
  44. package/lib/typescript/components/Channel/Channel.d.ts +2 -1
  45. package/lib/typescript/components/Channel/hooks/useCreateChannelContext.d.ts +1 -1
  46. package/lib/typescript/components/Channel/hooks/useCreateMessagesContext.d.ts +4 -2
  47. package/lib/typescript/components/Message/MessageSimple/MessageSimple.d.ts +1 -1
  48. package/lib/typescript/components/MessageList/MessageList.d.ts +1 -1
  49. package/lib/typescript/contexts/channelContext/ChannelContext.d.ts +3 -1
  50. package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts +3 -1
  51. package/package.json +1 -1
  52. package/src/components/Attachment/Gallery.tsx +20 -5
  53. package/src/components/Channel/Channel.tsx +10 -0
  54. package/src/components/Channel/hooks/useCreateChannelContext.ts +4 -0
  55. package/src/components/Channel/hooks/useCreateMessagesContext.ts +4 -0
  56. package/src/components/Message/MessageSimple/MessageSimple.tsx +9 -3
  57. package/src/components/MessageList/MessageList.tsx +52 -27
  58. package/src/components/MessageList/hooks/useMessageList.ts +1 -1
  59. package/src/components/MessageList/utils/getGroupStyles.ts +3 -8
  60. package/src/contexts/channelContext/ChannelContext.tsx +2 -0
  61. package/src/contexts/messagesContext/MessagesContext.tsx +2 -0
  62. package/src/version.json +1 -1
@@ -43,7 +43,7 @@ export type MessageSimplePropsWithContext<
43
43
  > &
44
44
  Pick<
45
45
  MessagesContextValue<At, Ch, Co, Ev, Me, Re, Us>,
46
- 'MessageAvatar' | 'MessageContent' | 'ReactionList'
46
+ 'enableMessageGroupingByUser' | 'MessageAvatar' | 'MessageContent' | 'ReactionList'
47
47
  >;
48
48
 
49
49
  const MessageSimpleWithContext = <
@@ -60,6 +60,7 @@ const MessageSimpleWithContext = <
60
60
  const {
61
61
  alignment,
62
62
  channel,
63
+ enableMessageGroupingByUser,
63
64
  groupStyles,
64
65
  hasReactions,
65
66
  message,
@@ -89,7 +90,11 @@ const MessageSimpleWithContext = <
89
90
  styles.container,
90
91
  {
91
92
  justifyContent: alignment === 'left' ? 'flex-start' : 'flex-end',
92
- marginBottom: hasMarginBottom ? (isVeryLastMessage ? 30 : 8) : 0,
93
+ marginBottom: hasMarginBottom
94
+ ? isVeryLastMessage && enableMessageGroupingByUser
95
+ ? 30
96
+ : 8
97
+ : 0,
93
98
  marginTop: showReactions ? 2 : 0,
94
99
  },
95
100
  container,
@@ -211,7 +216,7 @@ export const MessageSimple = <
211
216
  ) => {
212
217
  const { alignment, channel, groupStyles, hasReactions, message } =
213
218
  useMessageContext<At, Ch, Co, Ev, Me, Re, Us>();
214
- const { MessageAvatar, MessageContent, ReactionList } =
219
+ const { enableMessageGroupingByUser, MessageAvatar, MessageContent, ReactionList } =
215
220
  useMessagesContext<At, Ch, Co, Ev, Me, Re, Us>();
216
221
 
217
222
  return (
@@ -219,6 +224,7 @@ export const MessageSimple = <
219
224
  {...{
220
225
  alignment,
221
226
  channel,
227
+ enableMessageGroupingByUser,
222
228
  groupStyles,
223
229
  hasReactions,
224
230
  message,
@@ -131,6 +131,7 @@ type MessageListPropsWithContext<
131
131
  | 'channel'
132
132
  | 'disabled'
133
133
  | 'EmptyStateIndicator'
134
+ | 'hideStickyDateHeader'
134
135
  | 'loadChannelAtMessage'
135
136
  | 'loading'
136
137
  | 'LoadingIndicator'
@@ -158,6 +159,7 @@ type MessageListPropsWithContext<
158
159
  | 'initialScrollToFirstUnreadMessage'
159
160
  | 'InlineDateSeparator'
160
161
  | 'InlineUnreadIndicator'
162
+ | 'legacyImageViewerSwipeBehaviour'
161
163
  | 'Message'
162
164
  | 'ScrollToBottomButton'
163
165
  | 'MessageSystem'
@@ -264,10 +266,12 @@ const MessageListWithContext = <
264
266
  FlatList,
265
267
  FooterComponent = LoadingMoreIndicator,
266
268
  HeaderComponent = InlineLoadingMoreRecentIndicator,
269
+ hideStickyDateHeader,
267
270
  initialScrollToFirstUnreadMessage,
268
271
  InlineDateSeparator,
269
272
  InlineUnreadIndicator,
270
273
  inverted = true,
274
+ legacyImageViewerSwipeBehaviour,
271
275
  loadChannelAtMessage,
272
276
  loading,
273
277
  LoadingIndicator,
@@ -410,7 +414,7 @@ const MessageListWithContext = <
410
414
  */
411
415
  const onViewableItemsChanged = useRef(
412
416
  ({ viewableItems }: { viewableItems: ViewToken[] | undefined }) => {
413
- if (viewableItems) {
417
+ if (viewableItems && !hideStickyDateHeader) {
414
418
  updateStickyHeaderDateIfNeeded(viewableItems);
415
419
  }
416
420
  setInitialScrollIfNeeded();
@@ -785,44 +789,58 @@ const MessageListWithContext = <
785
789
  [messageListLengthAfterUpdate],
786
790
  );
787
791
 
788
- const messagesWithImages = messageList.filter((message) => {
789
- if (!message.deleted_at && message.attachments) {
790
- return message.attachments.some(
791
- (attachment) =>
792
- attachment.type === 'image' &&
793
- !attachment.title_link &&
794
- !attachment.og_scrape_url &&
795
- (attachment.image_url || attachment.thumb_url),
796
- );
797
- }
798
- return false;
799
- });
792
+ const messagesWithImages =
793
+ legacyImageViewerSwipeBehaviour &&
794
+ messageList.filter((message) => {
795
+ if (!message.deleted_at && message.attachments) {
796
+ return message.attachments.some(
797
+ (attachment) =>
798
+ attachment.type === 'image' &&
799
+ !attachment.title_link &&
800
+ !attachment.og_scrape_url &&
801
+ (attachment.image_url || attachment.thumb_url),
802
+ );
803
+ }
804
+ return false;
805
+ });
800
806
 
801
807
  /**
802
808
  * This is for the useEffect to run again in the case that a message
803
809
  * gets edited with more or the same number of images
804
810
  */
805
- const imageString = messagesWithImages
806
- .map((message) =>
807
- message.attachments
808
- ?.map((attachment) => attachment.image_url || attachment.thumb_url || '')
809
- .join(),
810
- )
811
- .join();
812
-
813
- const numberOfMessagesWithImages = messagesWithImages.length;
811
+ const imageString =
812
+ legacyImageViewerSwipeBehaviour &&
813
+ messagesWithImages &&
814
+ messagesWithImages
815
+ .map((message) =>
816
+ message.attachments
817
+ ?.map((attachment) => attachment.image_url || attachment.thumb_url || '')
818
+ .join(),
819
+ )
820
+ .join();
821
+
822
+ const numberOfMessagesWithImages =
823
+ legacyImageViewerSwipeBehaviour && messagesWithImages && messagesWithImages.length;
814
824
  const threadExists = !!thread;
825
+
815
826
  useEffect(() => {
816
- if ((threadList && thread) || (!threadList && !thread)) {
817
- setImages(messagesWithImages);
827
+ if (legacyImageViewerSwipeBehaviour && ((threadList && thread) || (!threadList && !thread))) {
828
+ setImages(messagesWithImages as MessageType<At, Ch, Co, Ev, Me, Re, Us>[]);
818
829
  }
819
- }, [imageString, numberOfMessagesWithImages, threadExists, threadList]);
830
+ }, [
831
+ imageString,
832
+ legacyImageViewerSwipeBehaviour,
833
+ numberOfMessagesWithImages,
834
+ threadExists,
835
+ threadList,
836
+ ]);
820
837
 
821
838
  const stickyHeaderFormatDate =
822
839
  stickyHeaderDate?.getFullYear() === new Date().getFullYear() ? 'MMM D' : 'MMM D, YYYY';
823
- const tStickyHeaderDate = stickyHeaderDate ? tDateTimeParser(stickyHeaderDate) : null;
840
+ const tStickyHeaderDate =
841
+ stickyHeaderDate && !hideStickyDateHeader ? tDateTimeParser(stickyHeaderDate) : null;
824
842
  const stickyHeaderDateToRender =
825
- tStickyHeaderDate === null
843
+ tStickyHeaderDate === null || hideStickyDateHeader
826
844
  ? null
827
845
  : isDayOrMoment(tStickyHeaderDate)
828
846
  ? tStickyHeaderDate.format(stickyHeaderFormatDate)
@@ -943,7 +961,9 @@ export const MessageList = <
943
961
  channel,
944
962
  disabled,
945
963
  EmptyStateIndicator,
964
+ enableMessageGroupingByUser,
946
965
  error,
966
+ hideStickyDateHeader,
947
967
  loadChannelAtMessage,
948
968
  loading,
949
969
  LoadingIndicator,
@@ -965,6 +985,7 @@ export const MessageList = <
965
985
  initialScrollToFirstUnreadMessage,
966
986
  InlineDateSeparator,
967
987
  InlineUnreadIndicator,
988
+ legacyImageViewerSwipeBehaviour,
968
989
  Message,
969
990
  MessageSystem,
970
991
  myMessageTheme,
@@ -987,11 +1008,14 @@ export const MessageList = <
987
1008
  disabled,
988
1009
  disableTypingIndicator,
989
1010
  EmptyStateIndicator,
1011
+ enableMessageGroupingByUser,
990
1012
  error,
991
1013
  FlatList,
1014
+ hideStickyDateHeader,
992
1015
  initialScrollToFirstUnreadMessage,
993
1016
  InlineDateSeparator,
994
1017
  InlineUnreadIndicator,
1018
+ legacyImageViewerSwipeBehaviour,
995
1019
  loadChannelAtMessage,
996
1020
  loading,
997
1021
  LoadingIndicator,
@@ -1021,6 +1045,7 @@ export const MessageList = <
1021
1045
  TypingIndicatorContainer,
1022
1046
  }}
1023
1047
  {...props}
1048
+ noGroupByUser={!enableMessageGroupingByUser || props.noGroupByUser}
1024
1049
  />
1025
1050
  );
1026
1051
  };
@@ -116,7 +116,7 @@ export const useMessageList = <
116
116
  .map((msg) => ({
117
117
  ...msg,
118
118
  dateSeparator: dateSeparators[msg.id] || undefined,
119
- groupStyles: messageGroupStyles[msg.id] || [],
119
+ groupStyles: messageGroupStyles[msg.id] || ['single'],
120
120
  readBy: msg.id ? readData[msg.id] || false : false,
121
121
  }));
122
122
 
@@ -53,6 +53,9 @@ export const getGroupStyles = <
53
53
  noGroupByUser,
54
54
  userId,
55
55
  } = params;
56
+
57
+ if (noGroupByUser) return {};
58
+
56
59
  const messageGroupStyles: { [key: string]: GroupType[] } = {};
57
60
 
58
61
  const messagesFilteredForNonUser = messages.filter(
@@ -128,14 +131,6 @@ export const getGroupStyles = <
128
131
  }
129
132
  }
130
133
 
131
- /**
132
- * If noGroupByUser set add the key for single
133
- */
134
- if (noGroupByUser) {
135
- groupStyles.splice(0, groupStyles.length);
136
- groupStyles.push('single');
137
- }
138
-
139
134
  if (message.id) {
140
135
  messageGroupStyles[message.id] = groupStyles;
141
136
  }
@@ -53,6 +53,7 @@ export type ChannelContextValue<
53
53
  * Hide inline date separators on channel
54
54
  */
55
55
  hideDateSeparators: boolean;
56
+ hideStickyDateHeader: boolean;
56
57
  /**
57
58
  * Returns true if the current user has admin privileges
58
59
  */
@@ -164,6 +165,7 @@ export type ChannelContextValue<
164
165
  */
165
166
  channel?: Channel<At, Ch, Co, Ev, Me, Re, Us>;
166
167
  disabled?: boolean;
168
+ enableMessageGroupingByUser?: boolean;
167
169
  lastRead?: Date;
168
170
  /**
169
171
  * Maximum time in milliseconds that should occur between messages
@@ -97,6 +97,7 @@ export type MessagesContextValue<
97
97
  DateHeader: React.ComponentType<DateHeaderProps>;
98
98
  /** Should keyboard be dismissed when messaged is touched */
99
99
  dismissKeyboardOnMessageTouch: boolean;
100
+ enableMessageGroupingByUser: boolean;
100
101
  /**
101
102
  * UI component to display File type attachment.
102
103
  * Defaults to: [FileAttachment](https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/Attachment/FileAttachment.tsx)
@@ -326,6 +327,7 @@ export type MessagesContextValue<
326
327
  handleRetry?: (message: MessageType<At, Ch, Co, Ev, Me, Re, Us>) => Promise<void>;
327
328
  /** Handler to access when a thread reply action is invoked */
328
329
  handleThreadReply?: (message: MessageType<At, Ch, Co, Ev, Me, Re, Us>) => Promise<void>;
330
+ legacyImageViewerSwipeBehaviour?: boolean;
329
331
  /** Object specifying rules defined within simple-markdown https://github.com/Khan/simple-markdown#adding-a-simple-extension */
330
332
  markdownRules?: MarkdownRules;
331
333
  /**
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "3.9.0-next.1"
2
+ "version": "3.9.0-next.2"
3
3
  }