stream-chat-react-native-core 5.3.0-beta.3 → 5.3.1-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.
- package/lib/commonjs/components/Message/MessageSimple/utils/parseLinks.js +8 -2
- package/lib/commonjs/components/Message/MessageSimple/utils/parseLinks.js.map +1 -1
- package/lib/commonjs/components/Message/MessageSimple/utils/parseLinks.test.js +4 -0
- package/lib/commonjs/components/Message/MessageSimple/utils/parseLinks.test.js.map +1 -1
- package/lib/commonjs/components/MessageList/MessageList.js +26 -30
- package/lib/commonjs/components/MessageList/MessageList.js.map +1 -1
- package/lib/commonjs/components/MessageList/hooks/useMessageList.js +7 -2
- package/lib/commonjs/components/MessageList/hooks/useMessageList.js.map +1 -1
- package/lib/commonjs/components/MessageList/utils/getDateSeparators.js +4 -2
- package/lib/commonjs/components/MessageList/utils/getDateSeparators.js.map +1 -1
- package/lib/commonjs/contexts/messagesContext/MessagesContext.js +2 -2
- package/lib/commonjs/contexts/messagesContext/MessagesContext.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Message/MessageSimple/utils/parseLinks.js +8 -2
- package/lib/module/components/Message/MessageSimple/utils/parseLinks.js.map +1 -1
- package/lib/module/components/Message/MessageSimple/utils/parseLinks.test.js +4 -0
- package/lib/module/components/Message/MessageSimple/utils/parseLinks.test.js.map +1 -1
- package/lib/module/components/MessageList/MessageList.js +26 -30
- package/lib/module/components/MessageList/MessageList.js.map +1 -1
- package/lib/module/components/MessageList/hooks/useMessageList.js +7 -2
- package/lib/module/components/MessageList/hooks/useMessageList.js.map +1 -1
- package/lib/module/components/MessageList/utils/getDateSeparators.js +4 -2
- package/lib/module/components/MessageList/utils/getDateSeparators.js.map +1 -1
- package/lib/module/contexts/messagesContext/MessagesContext.js +2 -2
- package/lib/module/contexts/messagesContext/MessagesContext.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/MessageList/MessageList.d.ts +1 -1
- package/lib/typescript/components/MessageList/hooks/useMessageList.d.ts +2 -1
- package/lib/typescript/components/MessageList/utils/__tests__/getDateSeparators.test.d.ts +1 -0
- package/lib/typescript/components/MessageList/utils/getDateSeparators.d.ts +2 -0
- package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts +2 -1
- package/package.json +1 -1
- package/src/components/Message/MessageSimple/utils/parseLinks.test.ts +6 -0
- package/src/components/Message/MessageSimple/utils/parseLinks.ts +11 -2
- package/src/components/MessageList/MessageList.tsx +0 -5
- package/src/components/MessageList/hooks/useMessageList.ts +8 -2
- package/src/components/MessageList/utils/__tests__/getDateSeparators.test.ts +71 -0
- package/src/components/MessageList/utils/getDateSeparators.ts +10 -2
- package/src/contexts/messagesContext/MessagesContext.tsx +2 -1
- package/src/version.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["MessagesContext.tsx"],"names":["MessagesContext","React","createContext","DEFAULT_BASE_CONTEXT_VALUE","MessagesProvider","children","value","useMessagesContext","contextValue","Error","withMessagesContext","Component","WithMessagesContextComponent","props","messagesContext","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAuDA;;AAEA;;AACA;;;;;;;;;AA2aO,IAAMA,eAAe,GAAGC,kBAAMC,aAAN,CAC7BC,mDAD6B,CAAxB;;;;AAIA,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAmB;AAAA,MAG9BC,QAH8B,QAG9BA,QAH8B;AAAA,MAI9BC,KAJ8B,QAI9BA,KAJ8B;AAAA,SAQ9B,gCAAC,eAAD,CAAiB,QAAjB;AAA0B,IAAA,KAAK,EAAEA,KAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KACGD,QADH,CAR8B;AAAA,CAAzB;;;;AAaA,IAAME,kBAAkB,GAAG,SAArBA,kBAAqB,GAE3B;AACL,MAAMC,YAAY,GAAG,uBACnBR,eADmB,CAArB;;AAIA,MAAIQ,YAAY,KAAKL,mDAAjB,IAA+C,CAAC,2CAApD,EAAyE;AACvE,UAAM,IAAIM,KAAJ,yOAAN;AAGD;;AAED,SAAOD,YAAP;AACD,CAdM;;;;AAqBA,IAAME,mBAAmB,GAAG,SAAtBA,mBAAsB,CAIjCC,SAJiC,EAKqC;AACtE,MAAMC,4BAA4B,GAAG,SAA/BA,4BAA+B,CACnCC,KADmC,EAEhC;AACH,QAAMC,eAAe,GAAGP,kBAAkB,EAA1C;AAEA,WAAO,gCAAC,SAAD,gCAAgBM,KAAhB,EAAiCC,eAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAND;;AAOAF,EAAAA,4BAA4B,CAACG,WAA7B,2BAAiE,oCAAeJ,SAAf,CAAjE;AACA,SAAOC,4BAAP;AACD,CAfM","sourcesContent":["import React, { PropsWithChildren, useContext } from 'react';\n\nimport type { TouchableOpacityProps } from 'react-native';\n\nimport type { ImageLoadingFailedIndicatorProps } from 'src/components/Attachment/ImageLoadingFailedIndicator';\nimport type { ImageLoadingIndicatorProps } from 'src/components/Attachment/ImageLoadingIndicator';\n\nimport type { MessagePinnedHeaderProps } from 'src/components/Message/MessageSimple/MessagePinnedHeader';\n\nimport type { Attachment, ChannelState, MessageResponse } from 'stream-chat';\n\nimport type { AttachmentProps } from '../../components/Attachment/Attachment';\nimport type { AttachmentActionsProps } from '../../components/Attachment/AttachmentActions';\nimport type { AudioAttachmentProps } from '../../components/Attachment/AudioAttachment';\nimport type { CardProps } from '../../components/Attachment/Card';\nimport type { FileAttachmentProps } from '../../components/Attachment/FileAttachment';\nimport type { FileAttachmentGroupProps } from '../../components/Attachment/FileAttachmentGroup';\nimport type { FileIconProps } from '../../components/Attachment/FileIcon';\nimport type { GalleryProps } from '../../components/Attachment/Gallery';\nimport type { GiphyProps } from '../../components/Attachment/Giphy';\nimport type { VideoThumbnailProps } from '../../components/Attachment/VideoThumbnail';\nimport type {\n MessageProps,\n MessageTouchableHandlerPayload,\n} from '../../components/Message/Message';\nimport type { MessageAvatarProps } from '../../components/Message/MessageSimple/MessageAvatar';\nimport type { MessageContentProps } from '../../components/Message/MessageSimple/MessageContent';\nimport type { MessageDeletedProps } from '../../components/Message/MessageSimple/MessageDeleted';\nimport type { MessageFooterProps } from '../../components/Message/MessageSimple/MessageFooter';\n\nimport type { MessageRepliesProps } from '../../components/Message/MessageSimple/MessageReplies';\nimport type { MessageRepliesAvatarsProps } from '../../components/Message/MessageSimple/MessageRepliesAvatars';\nimport type { MessageSimpleProps } from '../../components/Message/MessageSimple/MessageSimple';\nimport type { MessageStatusProps } from '../../components/Message/MessageSimple/MessageStatus';\nimport type { MessageTextProps } from '../../components/Message/MessageSimple/MessageTextContainer';\nimport type { ReactionListProps } from '../../components/Message/MessageSimple/ReactionList';\nimport type { MarkdownRules } from '../../components/Message/MessageSimple/utils/renderText';\nimport type { MessageActionsParams } from '../../components/Message/utils/messageActions';\nimport type { DateHeaderProps } from '../../components/MessageList/DateHeader';\nimport type { MessageType } from '../../components/MessageList/hooks/useMessageList';\nimport type { InlineDateSeparatorProps } from '../../components/MessageList/InlineDateSeparator';\nimport type { MessageListProps } from '../../components/MessageList/MessageList';\nimport type { MessageSystemProps } from '../../components/MessageList/MessageSystem';\nimport type { ScrollToBottomButtonProps } from '../../components/MessageList/ScrollToBottomButton';\nimport type { MessageActionType } from '../../components/MessageOverlay/MessageActionListItem';\nimport type { OverlayReactionListProps } from '../../components/MessageOverlay/OverlayReactionList';\nimport type { ReplyProps } from '../../components/Reply/Reply';\nimport type { FlatList } from '../../native';\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport type { ReactionData } from '../../utils/utils';\nimport type { Alignment } from '../messageContext/MessageContext';\nimport type { SuggestionCommand } from '../suggestionsContext/SuggestionsContext';\nimport type { DeepPartial } from '../themeContext/ThemeContext';\nimport type { Theme } from '../themeContext/utils/theme';\nimport type { TDateTimeParserInput } from '../translationContext/TranslationContext';\nimport { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';\n\nimport { getDisplayName } from '../utils/getDisplayName';\nimport { isTestEnvironment } from '../utils/isTestEnvironment';\n\nexport type MessageContentType = 'attachments' | 'files' | 'gallery' | 'quoted_reply' | 'text';\n\nexport type MessagesContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n /**\n * UI component for Attachment.\n * Defaults to: [Attachment](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/Attachment.tsx)\n */\n Attachment: React.ComponentType<AttachmentProps<StreamChatGenerics>>;\n /**\n * UI component to display AttachmentActions. e.g., send, shuffle, cancel in case of giphy\n * Defaults to: [AttachmentActions](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/AttachmentActions.tsx)\n */\n AttachmentActions: React.ComponentType<AttachmentActionsProps<StreamChatGenerics>>;\n /** Custom UI component for AudioAttachment. */\n AudioAttachment: React.ComponentType<AudioAttachmentProps>;\n /**\n * UI component to display generic media type e.g. giphy, url preview etc\n * Defaults to: [Card](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/Card.tsx)\n */\n Card: React.ComponentType<CardProps<StreamChatGenerics>>;\n /**\n * UI component for DateHeader\n * Defaults to: [DateHeader](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageList/DateHeader.tsx)\n **/\n DateHeader: React.ComponentType<DateHeaderProps>;\n\n /** Should keyboard be dismissed when messaged is touched */\n dismissKeyboardOnMessageTouch: boolean;\n\n enableMessageGroupingByUser: boolean;\n\n /**\n * UI component to display File type attachment.\n * Defaults to: [FileAttachment](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/FileAttachment.tsx)\n */\n FileAttachment: React.ComponentType<FileAttachmentProps<StreamChatGenerics>>;\n /**\n * UI component to display group of File type attachments or multiple file attachments (in single message).\n * Defaults to: [FileAttachmentGroup](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/FileAttachmentGroup.tsx)\n */\n FileAttachmentGroup: React.ComponentType<FileAttachmentGroupProps<StreamChatGenerics>>;\n /**\n * UI component for attachment icon for type 'file' attachment.\n * Defaults to: https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/FileIcon.tsx\n */\n FileAttachmentIcon: React.ComponentType<FileIconProps>;\n FlatList: typeof FlatList;\n /**\n * UI component to display image attachments\n * Defaults to: [Gallery](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/Gallery.tsx)\n */\n Gallery: React.ComponentType<GalleryProps<StreamChatGenerics>>;\n /**\n * UI component for Giphy\n * Defaults to: [Giphy](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/Giphy.tsx)\n */\n Giphy: React.ComponentType<GiphyProps<StreamChatGenerics>>;\n /**\n * The giphy version to render - check the keys of the [Image Object](https://developers.giphy.com/docs/api/schema#image-object) for possible values. Uses 'fixed_height' by default\n * */\n giphyVersion: keyof NonNullable<Attachment['giphy']>;\n\n /**\n * The indicator rendered when loading an image fails.\n */\n ImageLoadingFailedIndicator: React.ComponentType<ImageLoadingFailedIndicatorProps>;\n\n /**\n * The indicator rendered when image is loading. By default renders <ActivityIndicator/>\n */\n ImageLoadingIndicator: React.ComponentType<ImageLoadingIndicatorProps>;\n\n /**\n * When true, messageList will be scrolled at first unread message, when opened.\n */\n initialScrollToFirstUnreadMessage: boolean;\n /**\n * UI component for Message Date Separator Component\n * Defaults to: [InlineDateSeparator](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageList/InlineDateSeparator.tsx)\n */\n InlineDateSeparator: React.ComponentType<InlineDateSeparatorProps>;\n /**\n * UI component for InlineUnreadIndicator\n * Defaults to: [InlineUnreadIndicator](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Message/MessageSimple/InlineUnreadIndicator.tsx)\n **/\n InlineUnreadIndicator: React.ComponentType;\n\n Message: React.ComponentType<MessageProps<StreamChatGenerics>>;\n /**\n * UI component for MessageAvatar\n * Defaults to: [MessageAvatar](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Message/MessageSimple/MessageAvatar.tsx)\n **/\n MessageAvatar: React.ComponentType<MessageAvatarProps<StreamChatGenerics>>;\n /**\n * UI component for MessageContent\n * Defaults to: [MessageContent](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Message/MessageSimple/MessageContent.tsx)\n */\n MessageContent: React.ComponentType<MessageContentProps<StreamChatGenerics>>;\n /** Order to render the message content */\n messageContentOrder: MessageContentType[];\n /**\n * UI component for MessageDeleted\n * Defaults to: [MessageDeleted](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageSimple/MessageDeleted.tsx)\n */\n MessageDeleted: React.ComponentType<MessageDeletedProps<StreamChatGenerics>>;\n /**\n * Custom message footer component\n */\n MessageFooter: React.ComponentType<MessageFooterProps<StreamChatGenerics>>;\n MessageList: React.ComponentType<MessageListProps<StreamChatGenerics>>;\n /**\n * Custom message pinned component\n */\n MessagePinnedHeader: React.ComponentType<MessagePinnedHeaderProps<StreamChatGenerics>>;\n /**\n * UI component for MessageReplies\n * Defaults to: [MessageReplies](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageSimple/MessageReplies.tsx)\n */\n\n MessageReplies: React.ComponentType<MessageRepliesProps<StreamChatGenerics>>;\n /**\n * UI Component for MessageRepliesAvatars\n * Defaults to: [MessageRepliesAvatars](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageSimple/MessageRepliesAvatars.tsx)\n */\n MessageRepliesAvatars: React.ComponentType<MessageRepliesAvatarsProps<StreamChatGenerics>>;\n /**\n * UI component for MessageSimple\n * Defaults to: [MessageSimple](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Message/MessageSimple/MessageSimple.tsx)\n */\n MessageSimple: React.ComponentType<MessageSimpleProps<StreamChatGenerics>>;\n /**\n * UI component for MessageStatus (delivered/read)\n * Defaults to: [MessageStatus](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Message/MessageSimple/MessageStatus.tsx)\n */\n MessageStatus: React.ComponentType<MessageStatusProps<StreamChatGenerics>>;\n /**\n * UI component for MessageSystem\n * Defaults to: [MessageSystem](https://getstream.io/chat/docs/sdk/reactnative/ui-components/message-system/)\n */\n MessageSystem: React.ComponentType<MessageSystemProps<StreamChatGenerics>>;\n /**\n * UI component for OverlayReactionList\n */\n OverlayReactionList: React.ComponentType<OverlayReactionListProps<StreamChatGenerics>>;\n /**\n * UI component for ReactionList\n * Defaults to: [ReactionList](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Reaction/ReactionList.tsx)\n */\n ReactionList: React.ComponentType<ReactionListProps<StreamChatGenerics>>;\n removeMessage: (message: { id: string; parent_id?: string }) => void;\n /**\n * UI component for Reply\n * Defaults to: [Reply](https://getstream.io/chat/docs/sdk/reactnative/ui-components/reply/)\n */\n Reply: React.ComponentType<ReplyProps<StreamChatGenerics>>;\n /**\n * Override the api request for retry message functionality.\n */\n retrySendMessage: (message: MessageResponse<StreamChatGenerics>) => Promise<void>;\n /**\n * UI component for ScrollToBottomButton\n * Defaults to: [ScrollToBottomButton](https://getstream.io/chat/docs/sdk/reactnative/ui-components/scroll-to-bottom-button/)\n */\n ScrollToBottomButton: React.ComponentType<ScrollToBottomButtonProps>;\n setEditingState: (message: MessageType<StreamChatGenerics>) => void;\n setQuotedMessageState: (message: MessageType<StreamChatGenerics>) => void;\n supportedReactions: ReactionData[];\n /**\n * UI component for TypingIndicator\n * Defaults to: [TypingIndicator](https://getstream.io/chat/docs/sdk/reactnative/ui-components/typing-indicator/)\n */\n TypingIndicator: React.ComponentType;\n /**\n * UI component for TypingIndicatorContainer\n * Defaults to: [TypingIndicatorContainer](https://getstream.io/chat/docs/sdk/reactnative/contexts/messages-context/#typingindicatorcontainer)\n */\n TypingIndicatorContainer: React.ComponentType;\n updateMessage: (\n updatedMessage: MessageResponse<StreamChatGenerics>,\n extraState?: {\n commands?: SuggestionCommand<StreamChatGenerics>[];\n messageInput?: string;\n threadMessages?: ChannelState<StreamChatGenerics>['threads'][string];\n },\n ) => void;\n /**\n * Custom UI component to display enriched url preview.\n * Defaults to https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/Card.tsx\n */\n UrlPreview: React.ComponentType<CardProps<StreamChatGenerics>>;\n VideoThumbnail: React.ComponentType<VideoThumbnailProps>;\n /**\n * Provide any additional props for `TouchableOpacity` which wraps inner MessageContent component here.\n * Please check docs for TouchableOpacity for supported props - https://reactnative.dev/docs/touchableopacity#props\n *\n * @overrideType Object\n */\n additionalTouchableProps?: Omit<TouchableOpacityProps, 'style'>;\n /**\n * Custom UI component to override default cover (between Header and Footer) of Card component.\n * Accepts the same props as Card component.\n */\n CardCover?: React.ComponentType<CardProps<StreamChatGenerics>>;\n /**\n * Custom UI component to override default Footer of Card component.\n * Accepts the same props as Card component.\n */\n CardFooter?: React.ComponentType<CardProps<StreamChatGenerics>>;\n /**\n * Custom UI component to override default header of Card component.\n * Accepts the same props as Card component.\n */\n CardHeader?: React.ComponentType<CardProps<StreamChatGenerics>>;\n\n /**\n * Full override of the delete message button in the Message Actions\n *\n * Please check [cookbook](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#override-or-intercept-message-actions-edit-delete-reaction-reply-etc) for details.\n */\n\n /** Control if the deleted message is visible to both the send and reciever, either of them or none */\n deletedMessagesVisibilityType?: 'always' | 'never' | 'receiver' | 'sender';\n\n disableTypingIndicator?: boolean;\n\n /**\n * Whether messages should be aligned to right or left part of screen.\n * By default, messages will be received messages will be aligned to left and\n * sent messages will be aligned to right.\n */\n forceAlignMessages?: Alignment | boolean;\n /**\n * Optional function to custom format the message date\n */\n formatDate?: (date: TDateTimeParserInput) => string;\n handleBlock?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to access when a copy message action is invoked */\n handleCopy?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to access when a delete message action is invoked */\n handleDelete?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to access when an edit message action is invoked */\n handleEdit?: (message: MessageType<StreamChatGenerics>) => void;\n /** Handler to access when a flag message action is invoked */\n handleFlag?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to access when a mute user action is invoked */\n handleMute?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to access when a pin/unpin user action is invoked*/\n handlePinMessage?: ((message: MessageType<StreamChatGenerics>) => MessageActionType) | null;\n /** Handler to access when a quoted reply action is invoked */\n handleQuotedReply?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to process a reaction */\n handleReaction?: (\n message: MessageType<StreamChatGenerics>,\n reactionType: string,\n ) => Promise<void>;\n /** Handler to access when a retry action is invoked */\n handleRetry?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to access when a thread reply action is invoked */\n handleThreadReply?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to deal with custom memoization logic of Attachment */\n isAttachmentEqual?: (\n prevAttachment: Attachment<StreamChatGenerics>,\n nextAttachment: Attachment<StreamChatGenerics>,\n ) => boolean;\n legacyImageViewerSwipeBehaviour?: boolean;\n /** Object specifying rules defined within simple-markdown https://github.com/Khan/simple-markdown#adding-a-simple-extension */\n markdownRules?: MarkdownRules;\n /**\n * Use this prop to override message actions (which pop-up in message overlay).\n *\n * You can either completely override the default messageActions object.\n *\n * ```\n * <Channel\n * messageActions=[\n * {\n * action: () => { someAction() };\n * title: \"Pin Message\";\n * icon: PinIcon;\n * titleStyle: {};\n * },\n * {\n * action: () => { someAction() };\n * title: \"Delete Message\";\n * icon: PinIcon;\n * titleStyle: {};\n * }\n * ]\n * >\n * </Channel>\n * ```\n *\n * Or you can selectly keep certain action and remove some:\n *\n * e.g. Lets say you only want to keep threadReply and copyMessage actions\n *\n * ```\n * <Channel\n * messageActions={({\n * blockUser,\n * copyMessage,\n * deleteMessage,\n * editMessage,\n * flagMessage,\n * muteUser,\n * quotedReply,\n * retry,\n * threadReply,\n * }) => ([\n * threadReply, copyMessage\n * ])}\n * >\n * </Channel>\n * ```\n *\n * @overrideType Function | Array<Objects>\n */\n messageActions?: (param: MessageActionsParams<StreamChatGenerics>) => MessageActionType[];\n /**\n * Custom message header component\n */\n MessageHeader?: React.ComponentType<MessageFooterProps<StreamChatGenerics>>;\n /** Custom UI component for message text */\n MessageText?: React.ComponentType<MessageTextProps<StreamChatGenerics>>;\n\n /**\n * Theme provided only to messages that are the current users\n */\n myMessageTheme?: DeepPartial<Theme>;\n /**\n * Override default handler for onLongPress on message. You have access to payload of that handler as param:\n *\n * ```\n * <Channel\n * onLongPressMessage={({\n * actionHandlers: {\n * deleteMessage, // () => Promise<void>;\n * editMessage, // () => void;\n * quotedReply, // () => void;\n * resendMessage, // () => Promise<void>;\n * showMessageOverlay, // () => void;\n * toggleBanUser, // () => Promise<void>;\n * toggleMuteUser, // () => Promise<void>;\n * toggleReaction, // (reactionType: string) => Promise<void>;\n * },\n * defaultHandler, // () => void\n * event, // any event object corresponding to touchable feedback\n * emitter, // which component trigged this touchable feedback e.g. card, fileAttachment, gallery, message ... etc\n * message // message object on which longPress occured\n * }) => {\n * // Your custom action\n * }}\n * />\n * ```\n */\n onLongPressMessage?: (payload: MessageTouchableHandlerPayload<StreamChatGenerics>) => void;\n /**\n * Add onPressIn handler for attachments. You have access to payload of that handler as param:\n *\n * ```\n * <Channel\n * onPressInMessage={({\n * actionHandlers: {\n * deleteMessage, // () => Promise<void>;\n * editMessage, // () => void;\n * quotedReply, // () => void;\n * resendMessage, // () => Promise<void>;\n * showMessageOverlay, // () => void;\n * toggleBanUser, // () => Promise<void>;\n * toggleMuteUser, // () => Promise<void>;\n * toggleReaction, // (reactionType: string) => Promise<void>;\n * },\n * defaultHandler, // () => void\n * event, // any event object corresponding to touchable feedback\n * emitter, // which component trigged this touchable feedback e.g. card, fileAttachment, gallery, message ... etc\n * message // message object on which longPress occured\n * }) => {\n * // Your custom action\n * }}\n * />\n * ```\n */\n onPressInMessage?: (payload: MessageTouchableHandlerPayload<StreamChatGenerics>) => void;\n /**\n * Override onPress handler for message. You have access to payload of that handler as param:\n *\n * ```\n * <Channel\n * onPressMessage={({\n * actionHandlers: {\n * deleteMessage, // () => Promise<void>;\n * editMessage, // () => void;\n * quotedReply, // () => void;\n * resendMessage, // () => Promise<void>;\n * showMessageOverlay, // () => void;\n * toggleBanUser, // () => Promise<void>;\n * toggleMuteUser, // () => Promise<void>;\n * toggleReaction, // (reactionType: string) => Promise<void>;\n * },\n * defaultHandler, // () => void\n * event, // any event object corresponding to touchable feedback\n * emitter, // which component trigged this touchable feedback e.g. card, fileAttachment, gallery, message ... etc\n * message // message object on which longPress occurred\n * }) => {\n * // Your custom action\n * }}\n * />\n * ```\n */\n onPressMessage?: (payload: MessageTouchableHandlerPayload<StreamChatGenerics>) => void;\n\n /**\n * Full override of the reaction function on Message and Message Overlay\n *\n * Please check [cookbook](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#override-or-intercept-message-actions-edit-delete-reaction-reply-etc) for details.\n * */\n selectReaction?: (\n message: MessageType<StreamChatGenerics>,\n ) => (reactionType: string) => Promise<void>;\n\n targetedMessage?: string;\n};\n\nexport const MessagesContext = React.createContext(\n DEFAULT_BASE_CONTEXT_VALUE as MessagesContextValue,\n);\n\nexport const MessagesProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n value,\n}: PropsWithChildren<{\n value?: MessagesContextValue<StreamChatGenerics>;\n}>) => (\n <MessagesContext.Provider value={value as unknown as MessagesContextValue}>\n {children}\n </MessagesContext.Provider>\n);\n\nexport const useMessagesContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => {\n const contextValue = useContext(\n MessagesContext,\n ) as unknown as MessagesContextValue<StreamChatGenerics>;\n\n if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {\n throw new Error(\n `The useMessagesContext hook was called outside of the MessagesContext provider. Make sure you have configured MessageList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#message-list`,\n );\n }\n\n return contextValue;\n};\n\n/**\n * Typescript currently does not support partial inference so if MessagesContext\n * typing is desired while using the HOC withMessagesContext the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withMessagesContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof MessagesContextValue<StreamChatGenerics>>> => {\n const WithMessagesContextComponent = (\n props: Omit<P, keyof MessagesContextValue<StreamChatGenerics>>,\n ) => {\n const messagesContext = useMessagesContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...messagesContext} />;\n };\n WithMessagesContextComponent.displayName = `WithMessagesContext${getDisplayName(Component)}`;\n return WithMessagesContextComponent;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["MessagesContext.tsx"],"names":["MessagesContext","React","createContext","DEFAULT_BASE_CONTEXT_VALUE","MessagesProvider","children","value","useMessagesContext","contextValue","Error","withMessagesContext","Component","WithMessagesContextComponent","props","messagesContext","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAuDA;;AAEA;;AACA;;;;;;;;;AA4aO,IAAMA,eAAe,GAAGC,kBAAMC,aAAN,CAC7BC,mDAD6B,CAAxB;;;;AAIA,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAmB;AAAA,MAG9BC,QAH8B,QAG9BA,QAH8B;AAAA,MAI9BC,KAJ8B,QAI9BA,KAJ8B;AAAA,SAQ9B,gCAAC,eAAD,CAAiB,QAAjB;AAA0B,IAAA,KAAK,EAAEA,KAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KACGD,QADH,CAR8B;AAAA,CAAzB;;;;AAaA,IAAME,kBAAkB,GAAG,SAArBA,kBAAqB,GAE3B;AACL,MAAMC,YAAY,GAAG,uBACnBR,eADmB,CAArB;;AAIA,MAAIQ,YAAY,KAAKL,mDAAjB,IAA+C,CAAC,2CAApD,EAAyE;AACvE,UAAM,IAAIM,KAAJ,yOAAN;AAGD;;AAED,SAAOD,YAAP;AACD,CAdM;;;;AAqBA,IAAME,mBAAmB,GAAG,SAAtBA,mBAAsB,CAIjCC,SAJiC,EAKqC;AACtE,MAAMC,4BAA4B,GAAG,SAA/BA,4BAA+B,CACnCC,KADmC,EAEhC;AACH,QAAMC,eAAe,GAAGP,kBAAkB,EAA1C;AAEA,WAAO,gCAAC,SAAD,gCAAgBM,KAAhB,EAAiCC,eAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAND;;AAOAF,EAAAA,4BAA4B,CAACG,WAA7B,2BAAiE,oCAAeJ,SAAf,CAAjE;AACA,SAAOC,4BAAP;AACD,CAfM","sourcesContent":["import React, { PropsWithChildren, useContext } from 'react';\n\nimport type { TouchableOpacityProps } from 'react-native';\n\nimport type { ImageLoadingFailedIndicatorProps } from 'src/components/Attachment/ImageLoadingFailedIndicator';\nimport type { ImageLoadingIndicatorProps } from 'src/components/Attachment/ImageLoadingIndicator';\n\nimport type { MessagePinnedHeaderProps } from 'src/components/Message/MessageSimple/MessagePinnedHeader';\n\nimport type { Attachment, ChannelState, MessageResponse } from 'stream-chat';\n\nimport type { AttachmentProps } from '../../components/Attachment/Attachment';\nimport type { AttachmentActionsProps } from '../../components/Attachment/AttachmentActions';\nimport type { AudioAttachmentProps } from '../../components/Attachment/AudioAttachment';\nimport type { CardProps } from '../../components/Attachment/Card';\nimport type { FileAttachmentProps } from '../../components/Attachment/FileAttachment';\nimport type { FileAttachmentGroupProps } from '../../components/Attachment/FileAttachmentGroup';\nimport type { FileIconProps } from '../../components/Attachment/FileIcon';\nimport type { GalleryProps } from '../../components/Attachment/Gallery';\nimport type { GiphyProps } from '../../components/Attachment/Giphy';\nimport type { VideoThumbnailProps } from '../../components/Attachment/VideoThumbnail';\nimport type {\n MessageProps,\n MessageTouchableHandlerPayload,\n} from '../../components/Message/Message';\nimport type { MessageAvatarProps } from '../../components/Message/MessageSimple/MessageAvatar';\nimport type { MessageContentProps } from '../../components/Message/MessageSimple/MessageContent';\nimport type { MessageDeletedProps } from '../../components/Message/MessageSimple/MessageDeleted';\nimport type { MessageFooterProps } from '../../components/Message/MessageSimple/MessageFooter';\n\nimport type { MessageRepliesProps } from '../../components/Message/MessageSimple/MessageReplies';\nimport type { MessageRepliesAvatarsProps } from '../../components/Message/MessageSimple/MessageRepliesAvatars';\nimport type { MessageSimpleProps } from '../../components/Message/MessageSimple/MessageSimple';\nimport type { MessageStatusProps } from '../../components/Message/MessageSimple/MessageStatus';\nimport type { MessageTextProps } from '../../components/Message/MessageSimple/MessageTextContainer';\nimport type { ReactionListProps } from '../../components/Message/MessageSimple/ReactionList';\nimport type { MarkdownRules } from '../../components/Message/MessageSimple/utils/renderText';\nimport type { MessageActionsParams } from '../../components/Message/utils/messageActions';\nimport type { DateHeaderProps } from '../../components/MessageList/DateHeader';\nimport type { MessageType } from '../../components/MessageList/hooks/useMessageList';\nimport type { InlineDateSeparatorProps } from '../../components/MessageList/InlineDateSeparator';\nimport type { MessageListProps } from '../../components/MessageList/MessageList';\nimport type { MessageSystemProps } from '../../components/MessageList/MessageSystem';\nimport type { ScrollToBottomButtonProps } from '../../components/MessageList/ScrollToBottomButton';\nimport type { MessageActionType } from '../../components/MessageOverlay/MessageActionListItem';\nimport type { OverlayReactionListProps } from '../../components/MessageOverlay/OverlayReactionList';\nimport type { ReplyProps } from '../../components/Reply/Reply';\nimport type { FlatList } from '../../native';\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport type { ReactionData } from '../../utils/utils';\nimport type { Alignment } from '../messageContext/MessageContext';\nimport type { SuggestionCommand } from '../suggestionsContext/SuggestionsContext';\nimport type { DeepPartial } from '../themeContext/ThemeContext';\nimport type { Theme } from '../themeContext/utils/theme';\nimport type { TDateTimeParserInput } from '../translationContext/TranslationContext';\nimport { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';\n\nimport { getDisplayName } from '../utils/getDisplayName';\nimport { isTestEnvironment } from '../utils/isTestEnvironment';\n\nexport type MessageContentType = 'attachments' | 'files' | 'gallery' | 'quoted_reply' | 'text';\nexport type DeletedMessagesVisibilityType = 'always' | 'never' | 'receiver' | 'sender';\n\nexport type MessagesContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n /**\n * UI component for Attachment.\n * Defaults to: [Attachment](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/Attachment.tsx)\n */\n Attachment: React.ComponentType<AttachmentProps<StreamChatGenerics>>;\n /**\n * UI component to display AttachmentActions. e.g., send, shuffle, cancel in case of giphy\n * Defaults to: [AttachmentActions](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/AttachmentActions.tsx)\n */\n AttachmentActions: React.ComponentType<AttachmentActionsProps<StreamChatGenerics>>;\n /** Custom UI component for AudioAttachment. */\n AudioAttachment: React.ComponentType<AudioAttachmentProps>;\n /**\n * UI component to display generic media type e.g. giphy, url preview etc\n * Defaults to: [Card](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/Card.tsx)\n */\n Card: React.ComponentType<CardProps<StreamChatGenerics>>;\n /**\n * UI component for DateHeader\n * Defaults to: [DateHeader](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageList/DateHeader.tsx)\n **/\n DateHeader: React.ComponentType<DateHeaderProps>;\n\n /** Should keyboard be dismissed when messaged is touched */\n dismissKeyboardOnMessageTouch: boolean;\n\n enableMessageGroupingByUser: boolean;\n\n /**\n * UI component to display File type attachment.\n * Defaults to: [FileAttachment](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/FileAttachment.tsx)\n */\n FileAttachment: React.ComponentType<FileAttachmentProps<StreamChatGenerics>>;\n /**\n * UI component to display group of File type attachments or multiple file attachments (in single message).\n * Defaults to: [FileAttachmentGroup](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/FileAttachmentGroup.tsx)\n */\n FileAttachmentGroup: React.ComponentType<FileAttachmentGroupProps<StreamChatGenerics>>;\n /**\n * UI component for attachment icon for type 'file' attachment.\n * Defaults to: https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/FileIcon.tsx\n */\n FileAttachmentIcon: React.ComponentType<FileIconProps>;\n FlatList: typeof FlatList;\n /**\n * UI component to display image attachments\n * Defaults to: [Gallery](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/Gallery.tsx)\n */\n Gallery: React.ComponentType<GalleryProps<StreamChatGenerics>>;\n /**\n * UI component for Giphy\n * Defaults to: [Giphy](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/Giphy.tsx)\n */\n Giphy: React.ComponentType<GiphyProps<StreamChatGenerics>>;\n /**\n * The giphy version to render - check the keys of the [Image Object](https://developers.giphy.com/docs/api/schema#image-object) for possible values. Uses 'fixed_height' by default\n * */\n giphyVersion: keyof NonNullable<Attachment['giphy']>;\n\n /**\n * The indicator rendered when loading an image fails.\n */\n ImageLoadingFailedIndicator: React.ComponentType<ImageLoadingFailedIndicatorProps>;\n\n /**\n * The indicator rendered when image is loading. By default renders <ActivityIndicator/>\n */\n ImageLoadingIndicator: React.ComponentType<ImageLoadingIndicatorProps>;\n\n /**\n * When true, messageList will be scrolled at first unread message, when opened.\n */\n initialScrollToFirstUnreadMessage: boolean;\n /**\n * UI component for Message Date Separator Component\n * Defaults to: [InlineDateSeparator](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageList/InlineDateSeparator.tsx)\n */\n InlineDateSeparator: React.ComponentType<InlineDateSeparatorProps>;\n /**\n * UI component for InlineUnreadIndicator\n * Defaults to: [InlineUnreadIndicator](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Message/MessageSimple/InlineUnreadIndicator.tsx)\n **/\n InlineUnreadIndicator: React.ComponentType;\n\n Message: React.ComponentType<MessageProps<StreamChatGenerics>>;\n /**\n * UI component for MessageAvatar\n * Defaults to: [MessageAvatar](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Message/MessageSimple/MessageAvatar.tsx)\n **/\n MessageAvatar: React.ComponentType<MessageAvatarProps<StreamChatGenerics>>;\n /**\n * UI component for MessageContent\n * Defaults to: [MessageContent](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Message/MessageSimple/MessageContent.tsx)\n */\n MessageContent: React.ComponentType<MessageContentProps<StreamChatGenerics>>;\n /** Order to render the message content */\n messageContentOrder: MessageContentType[];\n /**\n * UI component for MessageDeleted\n * Defaults to: [MessageDeleted](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageSimple/MessageDeleted.tsx)\n */\n MessageDeleted: React.ComponentType<MessageDeletedProps<StreamChatGenerics>>;\n /**\n * Custom message footer component\n */\n MessageFooter: React.ComponentType<MessageFooterProps<StreamChatGenerics>>;\n MessageList: React.ComponentType<MessageListProps<StreamChatGenerics>>;\n /**\n * Custom message pinned component\n */\n MessagePinnedHeader: React.ComponentType<MessagePinnedHeaderProps<StreamChatGenerics>>;\n /**\n * UI component for MessageReplies\n * Defaults to: [MessageReplies](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageSimple/MessageReplies.tsx)\n */\n\n MessageReplies: React.ComponentType<MessageRepliesProps<StreamChatGenerics>>;\n /**\n * UI Component for MessageRepliesAvatars\n * Defaults to: [MessageRepliesAvatars](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageSimple/MessageRepliesAvatars.tsx)\n */\n MessageRepliesAvatars: React.ComponentType<MessageRepliesAvatarsProps<StreamChatGenerics>>;\n /**\n * UI component for MessageSimple\n * Defaults to: [MessageSimple](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Message/MessageSimple/MessageSimple.tsx)\n */\n MessageSimple: React.ComponentType<MessageSimpleProps<StreamChatGenerics>>;\n /**\n * UI component for MessageStatus (delivered/read)\n * Defaults to: [MessageStatus](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Message/MessageSimple/MessageStatus.tsx)\n */\n MessageStatus: React.ComponentType<MessageStatusProps<StreamChatGenerics>>;\n /**\n * UI component for MessageSystem\n * Defaults to: [MessageSystem](https://getstream.io/chat/docs/sdk/reactnative/ui-components/message-system/)\n */\n MessageSystem: React.ComponentType<MessageSystemProps<StreamChatGenerics>>;\n /**\n * UI component for OverlayReactionList\n */\n OverlayReactionList: React.ComponentType<OverlayReactionListProps<StreamChatGenerics>>;\n /**\n * UI component for ReactionList\n * Defaults to: [ReactionList](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Reaction/ReactionList.tsx)\n */\n ReactionList: React.ComponentType<ReactionListProps<StreamChatGenerics>>;\n removeMessage: (message: { id: string; parent_id?: string }) => void;\n /**\n * UI component for Reply\n * Defaults to: [Reply](https://getstream.io/chat/docs/sdk/reactnative/ui-components/reply/)\n */\n Reply: React.ComponentType<ReplyProps<StreamChatGenerics>>;\n /**\n * Override the api request for retry message functionality.\n */\n retrySendMessage: (message: MessageResponse<StreamChatGenerics>) => Promise<void>;\n /**\n * UI component for ScrollToBottomButton\n * Defaults to: [ScrollToBottomButton](https://getstream.io/chat/docs/sdk/reactnative/ui-components/scroll-to-bottom-button/)\n */\n ScrollToBottomButton: React.ComponentType<ScrollToBottomButtonProps>;\n setEditingState: (message: MessageType<StreamChatGenerics>) => void;\n setQuotedMessageState: (message: MessageType<StreamChatGenerics>) => void;\n supportedReactions: ReactionData[];\n /**\n * UI component for TypingIndicator\n * Defaults to: [TypingIndicator](https://getstream.io/chat/docs/sdk/reactnative/ui-components/typing-indicator/)\n */\n TypingIndicator: React.ComponentType;\n /**\n * UI component for TypingIndicatorContainer\n * Defaults to: [TypingIndicatorContainer](https://getstream.io/chat/docs/sdk/reactnative/contexts/messages-context/#typingindicatorcontainer)\n */\n TypingIndicatorContainer: React.ComponentType;\n updateMessage: (\n updatedMessage: MessageResponse<StreamChatGenerics>,\n extraState?: {\n commands?: SuggestionCommand<StreamChatGenerics>[];\n messageInput?: string;\n threadMessages?: ChannelState<StreamChatGenerics>['threads'][string];\n },\n ) => void;\n /**\n * Custom UI component to display enriched url preview.\n * Defaults to https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Attachment/Card.tsx\n */\n UrlPreview: React.ComponentType<CardProps<StreamChatGenerics>>;\n VideoThumbnail: React.ComponentType<VideoThumbnailProps>;\n /**\n * Provide any additional props for `TouchableOpacity` which wraps inner MessageContent component here.\n * Please check docs for TouchableOpacity for supported props - https://reactnative.dev/docs/touchableopacity#props\n *\n * @overrideType Object\n */\n additionalTouchableProps?: Omit<TouchableOpacityProps, 'style'>;\n /**\n * Custom UI component to override default cover (between Header and Footer) of Card component.\n * Accepts the same props as Card component.\n */\n CardCover?: React.ComponentType<CardProps<StreamChatGenerics>>;\n /**\n * Custom UI component to override default Footer of Card component.\n * Accepts the same props as Card component.\n */\n CardFooter?: React.ComponentType<CardProps<StreamChatGenerics>>;\n /**\n * Custom UI component to override default header of Card component.\n * Accepts the same props as Card component.\n */\n CardHeader?: React.ComponentType<CardProps<StreamChatGenerics>>;\n\n /**\n * Full override of the delete message button in the Message Actions\n *\n * Please check [cookbook](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#override-or-intercept-message-actions-edit-delete-reaction-reply-etc) for details.\n */\n\n /** Control if the deleted message is visible to both the send and reciever, either of them or none */\n deletedMessagesVisibilityType?: DeletedMessagesVisibilityType;\n\n disableTypingIndicator?: boolean;\n\n /**\n * Whether messages should be aligned to right or left part of screen.\n * By default, messages will be received messages will be aligned to left and\n * sent messages will be aligned to right.\n */\n forceAlignMessages?: Alignment | boolean;\n /**\n * Optional function to custom format the message date\n */\n formatDate?: (date: TDateTimeParserInput) => string;\n handleBlock?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to access when a copy message action is invoked */\n handleCopy?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to access when a delete message action is invoked */\n handleDelete?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to access when an edit message action is invoked */\n handleEdit?: (message: MessageType<StreamChatGenerics>) => void;\n /** Handler to access when a flag message action is invoked */\n handleFlag?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to access when a mute user action is invoked */\n handleMute?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to access when a pin/unpin user action is invoked*/\n handlePinMessage?: ((message: MessageType<StreamChatGenerics>) => MessageActionType) | null;\n /** Handler to access when a quoted reply action is invoked */\n handleQuotedReply?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to process a reaction */\n handleReaction?: (\n message: MessageType<StreamChatGenerics>,\n reactionType: string,\n ) => Promise<void>;\n /** Handler to access when a retry action is invoked */\n handleRetry?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to access when a thread reply action is invoked */\n handleThreadReply?: (message: MessageType<StreamChatGenerics>) => Promise<void>;\n /** Handler to deal with custom memoization logic of Attachment */\n isAttachmentEqual?: (\n prevAttachment: Attachment<StreamChatGenerics>,\n nextAttachment: Attachment<StreamChatGenerics>,\n ) => boolean;\n legacyImageViewerSwipeBehaviour?: boolean;\n /** Object specifying rules defined within simple-markdown https://github.com/Khan/simple-markdown#adding-a-simple-extension */\n markdownRules?: MarkdownRules;\n /**\n * Use this prop to override message actions (which pop-up in message overlay).\n *\n * You can either completely override the default messageActions object.\n *\n * ```\n * <Channel\n * messageActions=[\n * {\n * action: () => { someAction() };\n * title: \"Pin Message\";\n * icon: PinIcon;\n * titleStyle: {};\n * },\n * {\n * action: () => { someAction() };\n * title: \"Delete Message\";\n * icon: PinIcon;\n * titleStyle: {};\n * }\n * ]\n * >\n * </Channel>\n * ```\n *\n * Or you can selectly keep certain action and remove some:\n *\n * e.g. Lets say you only want to keep threadReply and copyMessage actions\n *\n * ```\n * <Channel\n * messageActions={({\n * blockUser,\n * copyMessage,\n * deleteMessage,\n * editMessage,\n * flagMessage,\n * muteUser,\n * quotedReply,\n * retry,\n * threadReply,\n * }) => ([\n * threadReply, copyMessage\n * ])}\n * >\n * </Channel>\n * ```\n *\n * @overrideType Function | Array<Objects>\n */\n messageActions?: (param: MessageActionsParams<StreamChatGenerics>) => MessageActionType[];\n /**\n * Custom message header component\n */\n MessageHeader?: React.ComponentType<MessageFooterProps<StreamChatGenerics>>;\n /** Custom UI component for message text */\n MessageText?: React.ComponentType<MessageTextProps<StreamChatGenerics>>;\n\n /**\n * Theme provided only to messages that are the current users\n */\n myMessageTheme?: DeepPartial<Theme>;\n /**\n * Override default handler for onLongPress on message. You have access to payload of that handler as param:\n *\n * ```\n * <Channel\n * onLongPressMessage={({\n * actionHandlers: {\n * deleteMessage, // () => Promise<void>;\n * editMessage, // () => void;\n * quotedReply, // () => void;\n * resendMessage, // () => Promise<void>;\n * showMessageOverlay, // () => void;\n * toggleBanUser, // () => Promise<void>;\n * toggleMuteUser, // () => Promise<void>;\n * toggleReaction, // (reactionType: string) => Promise<void>;\n * },\n * defaultHandler, // () => void\n * event, // any event object corresponding to touchable feedback\n * emitter, // which component trigged this touchable feedback e.g. card, fileAttachment, gallery, message ... etc\n * message // message object on which longPress occured\n * }) => {\n * // Your custom action\n * }}\n * />\n * ```\n */\n onLongPressMessage?: (payload: MessageTouchableHandlerPayload<StreamChatGenerics>) => void;\n /**\n * Add onPressIn handler for attachments. You have access to payload of that handler as param:\n *\n * ```\n * <Channel\n * onPressInMessage={({\n * actionHandlers: {\n * deleteMessage, // () => Promise<void>;\n * editMessage, // () => void;\n * quotedReply, // () => void;\n * resendMessage, // () => Promise<void>;\n * showMessageOverlay, // () => void;\n * toggleBanUser, // () => Promise<void>;\n * toggleMuteUser, // () => Promise<void>;\n * toggleReaction, // (reactionType: string) => Promise<void>;\n * },\n * defaultHandler, // () => void\n * event, // any event object corresponding to touchable feedback\n * emitter, // which component trigged this touchable feedback e.g. card, fileAttachment, gallery, message ... etc\n * message // message object on which longPress occured\n * }) => {\n * // Your custom action\n * }}\n * />\n * ```\n */\n onPressInMessage?: (payload: MessageTouchableHandlerPayload<StreamChatGenerics>) => void;\n /**\n * Override onPress handler for message. You have access to payload of that handler as param:\n *\n * ```\n * <Channel\n * onPressMessage={({\n * actionHandlers: {\n * deleteMessage, // () => Promise<void>;\n * editMessage, // () => void;\n * quotedReply, // () => void;\n * resendMessage, // () => Promise<void>;\n * showMessageOverlay, // () => void;\n * toggleBanUser, // () => Promise<void>;\n * toggleMuteUser, // () => Promise<void>;\n * toggleReaction, // (reactionType: string) => Promise<void>;\n * },\n * defaultHandler, // () => void\n * event, // any event object corresponding to touchable feedback\n * emitter, // which component trigged this touchable feedback e.g. card, fileAttachment, gallery, message ... etc\n * message // message object on which longPress occurred\n * }) => {\n * // Your custom action\n * }}\n * />\n * ```\n */\n onPressMessage?: (payload: MessageTouchableHandlerPayload<StreamChatGenerics>) => void;\n\n /**\n * Full override of the reaction function on Message and Message Overlay\n *\n * Please check [cookbook](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#override-or-intercept-message-actions-edit-delete-reaction-reply-etc) for details.\n * */\n selectReaction?: (\n message: MessageType<StreamChatGenerics>,\n ) => (reactionType: string) => Promise<void>;\n\n targetedMessage?: string;\n};\n\nexport const MessagesContext = React.createContext(\n DEFAULT_BASE_CONTEXT_VALUE as MessagesContextValue,\n);\n\nexport const MessagesProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n value,\n}: PropsWithChildren<{\n value?: MessagesContextValue<StreamChatGenerics>;\n}>) => (\n <MessagesContext.Provider value={value as unknown as MessagesContextValue}>\n {children}\n </MessagesContext.Provider>\n);\n\nexport const useMessagesContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => {\n const contextValue = useContext(\n MessagesContext,\n ) as unknown as MessagesContextValue<StreamChatGenerics>;\n\n if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {\n throw new Error(\n `The useMessagesContext hook was called outside of the MessagesContext provider. Make sure you have configured MessageList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#message-list`,\n );\n }\n\n return contextValue;\n};\n\n/**\n * Typescript currently does not support partial inference so if MessagesContext\n * typing is desired while using the HOC withMessagesContext the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withMessagesContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof MessagesContextValue<StreamChatGenerics>>> => {\n const WithMessagesContextComponent = (\n props: Omit<P, keyof MessagesContextValue<StreamChatGenerics>>,\n ) => {\n const messagesContext = useMessagesContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...messagesContext} />;\n };\n WithMessagesContextComponent.displayName = `WithMessagesContext${getDisplayName(Component)}`;\n return WithMessagesContextComponent;\n};\n"]}
|
package/lib/module/version.json
CHANGED
|
@@ -11,7 +11,7 @@ import { PaginatedMessageListContextValue } from '../../contexts/paginatedMessag
|
|
|
11
11
|
import { ThreadContextValue } from '../../contexts/threadContext/ThreadContext';
|
|
12
12
|
import { TranslationContextValue } from '../../contexts/translationContext/TranslationContext';
|
|
13
13
|
import type { DefaultStreamChatGenerics } from '../../types/types';
|
|
14
|
-
declare type MessageListPropsWithContext<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = Pick<AttachmentPickerContextValue, 'closePicker' | 'selectedPicker' | 'setSelectedPicker'> & Pick<ChannelContextValue<StreamChatGenerics>, 'channel' | 'disabled' | 'EmptyStateIndicator' | 'hideStickyDateHeader' | 'loadChannelAroundMessage' | 'loading' | 'LoadingIndicator' | 'markRead' | 'NetworkDownIndicator' | 'reloadChannel' | 'scrollToFirstUnreadThreshold' | 'setTargetedMessage' | 'StickyHeader' | 'targetedMessage'> & Pick<ChatContextValue<StreamChatGenerics>, 'client'> & Pick<ImageGalleryContextValue<StreamChatGenerics>, 'setMessages'> & Pick<PaginatedMessageListContextValue<StreamChatGenerics>, 'hasNoMoreRecentMessagesToLoad' | 'loadMore' | 'loadMoreRecent'> & Pick<OverlayContextValue, 'overlay'> & Pick<MessagesContextValue<StreamChatGenerics>, '
|
|
14
|
+
declare type MessageListPropsWithContext<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = Pick<AttachmentPickerContextValue, 'closePicker' | 'selectedPicker' | 'setSelectedPicker'> & Pick<ChannelContextValue<StreamChatGenerics>, 'channel' | 'disabled' | 'EmptyStateIndicator' | 'hideStickyDateHeader' | 'loadChannelAroundMessage' | 'loading' | 'LoadingIndicator' | 'markRead' | 'NetworkDownIndicator' | 'reloadChannel' | 'scrollToFirstUnreadThreshold' | 'setTargetedMessage' | 'StickyHeader' | 'targetedMessage'> & Pick<ChatContextValue<StreamChatGenerics>, 'client'> & Pick<ImageGalleryContextValue<StreamChatGenerics>, 'setMessages'> & Pick<PaginatedMessageListContextValue<StreamChatGenerics>, 'hasNoMoreRecentMessagesToLoad' | 'loadMore' | 'loadMoreRecent'> & Pick<OverlayContextValue, 'overlay'> & Pick<MessagesContextValue<StreamChatGenerics>, 'DateHeader' | 'disableTypingIndicator' | 'FlatList' | 'initialScrollToFirstUnreadMessage' | 'InlineDateSeparator' | 'InlineUnreadIndicator' | 'legacyImageViewerSwipeBehaviour' | 'Message' | 'ScrollToBottomButton' | 'MessageSystem' | 'myMessageTheme' | 'TypingIndicator' | 'TypingIndicatorContainer'> & Pick<ThreadContextValue<StreamChatGenerics>, 'loadMoreThread' | 'thread'> & Pick<TranslationContextValue, 't' | 'tDateTimeParser'> & {
|
|
15
15
|
/**
|
|
16
16
|
* Besides existing (default) UX behavior of underlying FlatList of MessageList component, if you want
|
|
17
17
|
* to attach some additional props to underlying FlatList, you can add it to following prop.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ChannelState, MessageResponse } from 'stream-chat';
|
|
2
|
+
import { DeletedMessagesVisibilityType } from '../../../contexts/messagesContext/MessagesContext';
|
|
2
3
|
import type { DefaultStreamChatGenerics } from '../../../types/types';
|
|
3
4
|
export declare type UseMessageListParams = {
|
|
4
|
-
deletedMessagesVisibilityType?:
|
|
5
|
+
deletedMessagesVisibilityType?: DeletedMessagesVisibilityType;
|
|
5
6
|
inverted?: boolean;
|
|
6
7
|
noGroupByUser?: boolean;
|
|
7
8
|
threadList?: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { DeletedMessagesVisibilityType } from '../../../contexts/messagesContext/MessagesContext';
|
|
1
2
|
import type { PaginatedMessageListContextValue } from '../../../contexts/paginatedMessageListContext/PaginatedMessageListContext';
|
|
2
3
|
import type { ThreadContextValue } from '../../../contexts/threadContext/ThreadContext';
|
|
3
4
|
import type { DefaultStreamChatGenerics } from '../../../types/types';
|
|
4
5
|
export declare type GetDateSeparatorsParams<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = {
|
|
5
6
|
messages: PaginatedMessageListContextValue<StreamChatGenerics>['messages'] | ThreadContextValue<StreamChatGenerics>['threadMessages'];
|
|
7
|
+
deletedMessagesVisibilityType?: DeletedMessagesVisibilityType;
|
|
6
8
|
hideDateSeparators?: boolean;
|
|
7
9
|
userId?: string;
|
|
8
10
|
};
|
|
@@ -45,6 +45,7 @@ import type { DeepPartial } from '../themeContext/ThemeContext';
|
|
|
45
45
|
import type { Theme } from '../themeContext/utils/theme';
|
|
46
46
|
import type { TDateTimeParserInput } from '../translationContext/TranslationContext';
|
|
47
47
|
export declare type MessageContentType = 'attachments' | 'files' | 'gallery' | 'quoted_reply' | 'text';
|
|
48
|
+
export declare type DeletedMessagesVisibilityType = 'always' | 'never' | 'receiver' | 'sender';
|
|
48
49
|
export declare type MessagesContextValue<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = {
|
|
49
50
|
/**
|
|
50
51
|
* UI component for Attachment.
|
|
@@ -254,7 +255,7 @@ export declare type MessagesContextValue<StreamChatGenerics extends DefaultStrea
|
|
|
254
255
|
* Please check [cookbook](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#override-or-intercept-message-actions-edit-delete-reaction-reply-etc) for details.
|
|
255
256
|
*/
|
|
256
257
|
/** Control if the deleted message is visible to both the send and reciever, either of them or none */
|
|
257
|
-
deletedMessagesVisibilityType?:
|
|
258
|
+
deletedMessagesVisibilityType?: DeletedMessagesVisibilityType;
|
|
258
259
|
disableTypingIndicator?: boolean;
|
|
259
260
|
/**
|
|
260
261
|
* Whether messages should be aligned to right or left part of screen.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-chat-react-native-core",
|
|
3
3
|
"description": "The official React Native and Expo components for Stream Chat, a service for building chat applications",
|
|
4
|
-
"version": "5.3.
|
|
4
|
+
"version": "5.3.1-beta.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"company": "Stream.io Inc",
|
|
7
7
|
"name": "Stream.io Inc"
|
|
@@ -43,10 +43,19 @@ interface Link {
|
|
|
43
43
|
* */
|
|
44
44
|
const removeMarkdownLinksFromText = (input: string) => input.replace(/\[[\w\s]+\]\(.*\)/g, '');
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Hermes doesn't support lookbehind, so this is done separately to avoid
|
|
48
|
+
* parsing user names as links.
|
|
49
|
+
* */
|
|
50
|
+
const removeUserNamesFromText = (input: string) => input.replace(/^@\w+\.?\w/, '');
|
|
51
|
+
|
|
46
52
|
export const parseLinksFromText = (input: string): Link[] => {
|
|
47
53
|
let matches;
|
|
48
54
|
|
|
49
|
-
const
|
|
55
|
+
const strippedInput = [removeMarkdownLinksFromText, removeUserNamesFromText].reduce(
|
|
56
|
+
(acc, fn) => fn(acc),
|
|
57
|
+
input,
|
|
58
|
+
);
|
|
50
59
|
|
|
51
60
|
const results: Link[] = [];
|
|
52
61
|
|
|
@@ -61,7 +70,7 @@ export const parseLinksFromText = (input: string): Link[] => {
|
|
|
61
70
|
* to avoid overlapping matches being duplicated in the output.
|
|
62
71
|
* */
|
|
63
72
|
const linkRegex = new RegExp(`${fqdnLinkPattern}|${schemePrefixedLinkPattern}`, 'gi');
|
|
64
|
-
while ((matches = linkRegex.exec(
|
|
73
|
+
while ((matches = linkRegex.exec(strippedInput)) !== null) {
|
|
65
74
|
const [
|
|
66
75
|
raw,
|
|
67
76
|
fqdnScheme = '',
|
|
@@ -133,7 +133,6 @@ type MessageListPropsWithContext<
|
|
|
133
133
|
Pick<OverlayContextValue, 'overlay'> &
|
|
134
134
|
Pick<
|
|
135
135
|
MessagesContextValue<StreamChatGenerics>,
|
|
136
|
-
| 'deletedMessagesVisibilityType'
|
|
137
136
|
| 'DateHeader'
|
|
138
137
|
| 'disableTypingIndicator'
|
|
139
138
|
| 'FlatList'
|
|
@@ -236,7 +235,6 @@ const MessageListWithContext = <
|
|
|
236
235
|
client,
|
|
237
236
|
closePicker,
|
|
238
237
|
DateHeader,
|
|
239
|
-
deletedMessagesVisibilityType,
|
|
240
238
|
disabled,
|
|
241
239
|
disableTypingIndicator,
|
|
242
240
|
EmptyStateIndicator,
|
|
@@ -296,7 +294,6 @@ const MessageListWithContext = <
|
|
|
296
294
|
);
|
|
297
295
|
|
|
298
296
|
const messageList = useMessageList<StreamChatGenerics>({
|
|
299
|
-
deletedMessagesVisibilityType,
|
|
300
297
|
inverted,
|
|
301
298
|
noGroupByUser,
|
|
302
299
|
threadList,
|
|
@@ -1062,7 +1059,6 @@ export const MessageList = <
|
|
|
1062
1059
|
const { setMessages } = useImageGalleryContext<StreamChatGenerics>();
|
|
1063
1060
|
const {
|
|
1064
1061
|
DateHeader,
|
|
1065
|
-
deletedMessagesVisibilityType,
|
|
1066
1062
|
disableTypingIndicator,
|
|
1067
1063
|
FlatList,
|
|
1068
1064
|
initialScrollToFirstUnreadMessage,
|
|
@@ -1089,7 +1085,6 @@ export const MessageList = <
|
|
|
1089
1085
|
client,
|
|
1090
1086
|
closePicker,
|
|
1091
1087
|
DateHeader,
|
|
1092
|
-
deletedMessagesVisibilityType,
|
|
1093
1088
|
disabled,
|
|
1094
1089
|
disableTypingIndicator,
|
|
1095
1090
|
EmptyStateIndicator,
|
|
@@ -5,6 +5,10 @@ import {
|
|
|
5
5
|
useChannelContext,
|
|
6
6
|
} from '../../../contexts/channelContext/ChannelContext';
|
|
7
7
|
import { useChatContext } from '../../../contexts/chatContext/ChatContext';
|
|
8
|
+
import {
|
|
9
|
+
DeletedMessagesVisibilityType,
|
|
10
|
+
useMessagesContext,
|
|
11
|
+
} from '../../../contexts/messagesContext/MessagesContext';
|
|
8
12
|
import { usePaginatedMessageListContext } from '../../../contexts/paginatedMessageListContext/PaginatedMessageListContext';
|
|
9
13
|
import { useThreadContext } from '../../../contexts/threadContext/ThreadContext';
|
|
10
14
|
import type { DefaultStreamChatGenerics } from '../../../types/types';
|
|
@@ -13,7 +17,7 @@ import { getGroupStyles } from '../utils/getGroupStyles';
|
|
|
13
17
|
import { getReadStates } from '../utils/getReadStates';
|
|
14
18
|
|
|
15
19
|
export type UseMessageListParams = {
|
|
16
|
-
deletedMessagesVisibilityType?:
|
|
20
|
+
deletedMessagesVisibilityType?: DeletedMessagesVisibilityType;
|
|
17
21
|
inverted?: boolean;
|
|
18
22
|
noGroupByUser?: boolean;
|
|
19
23
|
threadList?: boolean;
|
|
@@ -48,10 +52,11 @@ export const useMessageList = <
|
|
|
48
52
|
>(
|
|
49
53
|
params: UseMessageListParams,
|
|
50
54
|
) => {
|
|
51
|
-
const {
|
|
55
|
+
const { inverted, noGroupByUser, threadList } = params;
|
|
52
56
|
const { client } = useChatContext<StreamChatGenerics>();
|
|
53
57
|
const { hideDateSeparators, maxTimeBetweenGroupedMessages, read } =
|
|
54
58
|
useChannelContext<StreamChatGenerics>();
|
|
59
|
+
const { deletedMessagesVisibilityType } = useMessagesContext<StreamChatGenerics>();
|
|
55
60
|
const { messages } = usePaginatedMessageListContext<StreamChatGenerics>();
|
|
56
61
|
const { threadMessages } = useThreadContext<StreamChatGenerics>();
|
|
57
62
|
|
|
@@ -61,6 +66,7 @@ export const useMessageList = <
|
|
|
61
66
|
: read;
|
|
62
67
|
|
|
63
68
|
const dateSeparators = getDateSeparators<StreamChatGenerics>({
|
|
69
|
+
deletedMessagesVisibilityType,
|
|
64
70
|
hideDateSeparators,
|
|
65
71
|
messages: messageList,
|
|
66
72
|
userId: client.userID,
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { PaginatedMessageListContextValue } from '../../../../contexts/paginatedMessageListContext/PaginatedMessageListContext';
|
|
2
|
+
import { getDateSeparators } from '../getDateSeparators';
|
|
3
|
+
|
|
4
|
+
describe('getDateSeparators', () => {
|
|
5
|
+
it('should return an empty object if no messages are passed', () => {
|
|
6
|
+
expect(getDateSeparators({ messages: [] })).toEqual({});
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('should return a date separator for each message in a new day', () => {
|
|
10
|
+
const firstDate = new Date('2020-01-01T00:00:00.000Z');
|
|
11
|
+
const secondDate = new Date('2020-01-02T00:00:00.000Z');
|
|
12
|
+
const messages = [
|
|
13
|
+
{
|
|
14
|
+
created_at: firstDate,
|
|
15
|
+
id: '1',
|
|
16
|
+
text: 'foo',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
created_at: secondDate,
|
|
20
|
+
id: '2',
|
|
21
|
+
text: 'bar',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
created_at: secondDate,
|
|
25
|
+
id: '3',
|
|
26
|
+
text: 'baz',
|
|
27
|
+
},
|
|
28
|
+
] as PaginatedMessageListContextValue['messages'];
|
|
29
|
+
|
|
30
|
+
expect(getDateSeparators({ messages })).toEqual({
|
|
31
|
+
1: firstDate,
|
|
32
|
+
2: secondDate,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should return a date separator for the visible message in a day if deleted messages are not visible to the user', () => {
|
|
37
|
+
const firstDate = new Date('2020-01-01T00:00:00.000Z');
|
|
38
|
+
const secondDate = new Date('2020-01-02T00:00:00.000Z');
|
|
39
|
+
|
|
40
|
+
const messages = [
|
|
41
|
+
{
|
|
42
|
+
created_at: firstDate,
|
|
43
|
+
id: '1',
|
|
44
|
+
text: 'foo',
|
|
45
|
+
type: 'regular',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
created_at: secondDate,
|
|
49
|
+
id: '2',
|
|
50
|
+
text: 'bar',
|
|
51
|
+
type: 'deleted',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
created_at: secondDate,
|
|
55
|
+
id: '3',
|
|
56
|
+
text: 'baz',
|
|
57
|
+
type: 'regular',
|
|
58
|
+
},
|
|
59
|
+
] as PaginatedMessageListContextValue['messages'];
|
|
60
|
+
|
|
61
|
+
expect(getDateSeparators({ deletedMessagesVisibilityType: 'never', messages })).toEqual({
|
|
62
|
+
1: firstDate,
|
|
63
|
+
3: secondDate,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(getDateSeparators({ deletedMessagesVisibilityType: 'receiver', messages })).toEqual({
|
|
67
|
+
1: firstDate,
|
|
68
|
+
3: secondDate,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DeletedMessagesVisibilityType } from '../../../contexts/messagesContext/MessagesContext';
|
|
1
2
|
import type { PaginatedMessageListContextValue } from '../../../contexts/paginatedMessageListContext/PaginatedMessageListContext';
|
|
2
3
|
import type { ThreadContextValue } from '../../../contexts/threadContext/ThreadContext';
|
|
3
4
|
import type { DefaultStreamChatGenerics } from '../../../types/types';
|
|
@@ -8,6 +9,7 @@ export type GetDateSeparatorsParams<
|
|
|
8
9
|
messages:
|
|
9
10
|
| PaginatedMessageListContextValue<StreamChatGenerics>['messages']
|
|
10
11
|
| ThreadContextValue<StreamChatGenerics>['threadMessages'];
|
|
12
|
+
deletedMessagesVisibilityType?: DeletedMessagesVisibilityType;
|
|
11
13
|
hideDateSeparators?: boolean;
|
|
12
14
|
userId?: string;
|
|
13
15
|
};
|
|
@@ -21,7 +23,7 @@ export const getDateSeparators = <
|
|
|
21
23
|
>(
|
|
22
24
|
params: GetDateSeparatorsParams<StreamChatGenerics>,
|
|
23
25
|
) => {
|
|
24
|
-
const { hideDateSeparators, messages, userId } = params;
|
|
26
|
+
const { deletedMessagesVisibilityType, hideDateSeparators, messages, userId } = params;
|
|
25
27
|
const dateSeparators: DateSeparators = {};
|
|
26
28
|
|
|
27
29
|
if (hideDateSeparators) {
|
|
@@ -30,7 +32,13 @@ export const getDateSeparators = <
|
|
|
30
32
|
|
|
31
33
|
const messagesWithoutDeleted = messages.filter((message) => {
|
|
32
34
|
const isMessageTypeDeleted = message.type === 'deleted';
|
|
33
|
-
|
|
35
|
+
|
|
36
|
+
const isDeletedMessageVisibleToSender =
|
|
37
|
+
deletedMessagesVisibilityType === 'sender' || deletedMessagesVisibilityType === 'always';
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
!isMessageTypeDeleted || (userId === message.user?.id && isDeletedMessageVisibleToSender)
|
|
41
|
+
);
|
|
34
42
|
});
|
|
35
43
|
|
|
36
44
|
for (let i = 0; i < messagesWithoutDeleted.length; i++) {
|
|
@@ -59,6 +59,7 @@ import { getDisplayName } from '../utils/getDisplayName';
|
|
|
59
59
|
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
60
60
|
|
|
61
61
|
export type MessageContentType = 'attachments' | 'files' | 'gallery' | 'quoted_reply' | 'text';
|
|
62
|
+
export type DeletedMessagesVisibilityType = 'always' | 'never' | 'receiver' | 'sender';
|
|
62
63
|
|
|
63
64
|
export type MessagesContextValue<
|
|
64
65
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
@@ -281,7 +282,7 @@ export type MessagesContextValue<
|
|
|
281
282
|
*/
|
|
282
283
|
|
|
283
284
|
/** Control if the deleted message is visible to both the send and reciever, either of them or none */
|
|
284
|
-
deletedMessagesVisibilityType?:
|
|
285
|
+
deletedMessagesVisibilityType?: DeletedMessagesVisibilityType;
|
|
285
286
|
|
|
286
287
|
disableTypingIndicator?: boolean;
|
|
287
288
|
|
package/src/version.json
CHANGED