stream-chat-react-native-core 4.7.0 → 4.7.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/Attachment/Card.js +61 -21
- package/lib/commonjs/components/Attachment/Card.js.map +1 -1
- package/lib/commonjs/components/AutoCompleteInput/AutoCompleteSuggestionList.js +1 -1
- package/lib/commonjs/components/AutoCompleteInput/AutoCompleteSuggestionList.js.map +1 -1
- package/lib/commonjs/components/MessageInput/SendMessageDisallowedIndicator.js +2 -2
- package/lib/commonjs/components/MessageInput/SendMessageDisallowedIndicator.js.map +1 -1
- package/lib/commonjs/components/Reply/Reply.js +12 -12
- package/lib/commonjs/components/Reply/Reply.js.map +1 -1
- package/lib/commonjs/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js +2 -2
- package/lib/commonjs/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js.map +1 -1
- package/lib/commonjs/contexts/attachmentPickerContext/AttachmentPickerContext.js +14 -4
- package/lib/commonjs/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
- package/lib/commonjs/contexts/channelContext/ChannelContext.js +14 -4
- package/lib/commonjs/contexts/channelContext/ChannelContext.js.map +1 -1
- package/lib/commonjs/contexts/channelsContext/ChannelsContext.js +14 -4
- package/lib/commonjs/contexts/channelsContext/ChannelsContext.js.map +1 -1
- package/lib/commonjs/contexts/channelsStateContext/ChannelsStateContext.js +15 -9
- package/lib/commonjs/contexts/channelsStateContext/ChannelsStateContext.js.map +1 -1
- package/lib/commonjs/contexts/chatContext/ChatContext.js +14 -4
- package/lib/commonjs/contexts/chatContext/ChatContext.js.map +1 -1
- package/lib/commonjs/contexts/imageGalleryContext/ImageGalleryContext.js +14 -4
- package/lib/commonjs/contexts/imageGalleryContext/ImageGalleryContext.js.map +1 -1
- package/lib/commonjs/contexts/keyboardContext/KeyboardContext.js +2 -2
- package/lib/commonjs/contexts/keyboardContext/KeyboardContext.js.map +1 -1
- package/lib/commonjs/contexts/messageContext/MessageContext.js +14 -4
- package/lib/commonjs/contexts/messageContext/MessageContext.js.map +1 -1
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +16 -6
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js +14 -4
- package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
- package/lib/commonjs/contexts/messageOverlayContext/hooks/useResettableState.test.js +4 -4
- package/lib/commonjs/contexts/messageOverlayContext/hooks/useResettableState.test.js.map +1 -1
- package/lib/commonjs/contexts/messagesContext/MessagesContext.js +14 -4
- package/lib/commonjs/contexts/messagesContext/MessagesContext.js.map +1 -1
- package/lib/commonjs/contexts/overlayContext/OverlayContext.js +13 -3
- package/lib/commonjs/contexts/overlayContext/OverlayContext.js.map +1 -1
- package/lib/commonjs/contexts/overlayContext/OverlayProvider.js +12 -12
- package/lib/commonjs/contexts/overlayContext/OverlayProvider.js.map +1 -1
- package/lib/commonjs/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js +13 -3
- package/lib/commonjs/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js.map +1 -1
- package/lib/commonjs/contexts/paginatedMessageListContext/PaginatedMessageListContext.js +14 -4
- package/lib/commonjs/contexts/paginatedMessageListContext/PaginatedMessageListContext.js.map +1 -1
- package/lib/commonjs/contexts/suggestionsContext/SuggestionsContext.js +14 -4
- package/lib/commonjs/contexts/suggestionsContext/SuggestionsContext.js.map +1 -1
- package/lib/commonjs/contexts/themeContext/ThemeContext.js +13 -7
- package/lib/commonjs/contexts/themeContext/ThemeContext.js.map +1 -1
- package/lib/commonjs/contexts/themeContext/utils/theme.js +9 -0
- package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
- package/lib/commonjs/contexts/threadContext/ThreadContext.js +14 -4
- package/lib/commonjs/contexts/threadContext/ThreadContext.js.map +1 -1
- package/lib/commonjs/contexts/translationContext/TranslationContext.js +15 -6
- package/lib/commonjs/contexts/translationContext/TranslationContext.js.map +1 -1
- package/lib/commonjs/contexts/typingContext/TypingContext.js +14 -4
- package/lib/commonjs/contexts/typingContext/TypingContext.js.map +1 -1
- package/lib/commonjs/contexts/utils/defaultBaseContextValue.js +7 -0
- package/lib/commonjs/contexts/utils/defaultBaseContextValue.js.map +1 -0
- package/lib/commonjs/contexts/utils/isTestEnvironment.js +11 -0
- package/lib/commonjs/contexts/utils/isTestEnvironment.js.map +1 -0
- package/lib/commonjs/mock-builders/mock.js +30 -5
- package/lib/commonjs/mock-builders/mock.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Attachment/Card.js +61 -21
- package/lib/module/components/Attachment/Card.js.map +1 -1
- package/lib/module/components/AutoCompleteInput/AutoCompleteSuggestionList.js +1 -1
- package/lib/module/components/AutoCompleteInput/AutoCompleteSuggestionList.js.map +1 -1
- package/lib/module/components/MessageInput/SendMessageDisallowedIndicator.js +2 -2
- package/lib/module/components/MessageInput/SendMessageDisallowedIndicator.js.map +1 -1
- package/lib/module/components/Reply/Reply.js +12 -12
- package/lib/module/components/Reply/Reply.js.map +1 -1
- package/lib/module/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js +2 -2
- package/lib/module/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js.map +1 -1
- package/lib/module/contexts/attachmentPickerContext/AttachmentPickerContext.js +14 -4
- package/lib/module/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
- package/lib/module/contexts/channelContext/ChannelContext.js +14 -4
- package/lib/module/contexts/channelContext/ChannelContext.js.map +1 -1
- package/lib/module/contexts/channelsContext/ChannelsContext.js +14 -4
- package/lib/module/contexts/channelsContext/ChannelsContext.js.map +1 -1
- package/lib/module/contexts/channelsStateContext/ChannelsStateContext.js +15 -9
- package/lib/module/contexts/channelsStateContext/ChannelsStateContext.js.map +1 -1
- package/lib/module/contexts/chatContext/ChatContext.js +14 -4
- package/lib/module/contexts/chatContext/ChatContext.js.map +1 -1
- package/lib/module/contexts/imageGalleryContext/ImageGalleryContext.js +14 -4
- package/lib/module/contexts/imageGalleryContext/ImageGalleryContext.js.map +1 -1
- package/lib/module/contexts/keyboardContext/KeyboardContext.js +2 -2
- package/lib/module/contexts/keyboardContext/KeyboardContext.js.map +1 -1
- package/lib/module/contexts/messageContext/MessageContext.js +14 -4
- package/lib/module/contexts/messageContext/MessageContext.js.map +1 -1
- package/lib/module/contexts/messageInputContext/MessageInputContext.js +16 -6
- package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js +14 -4
- package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
- package/lib/module/contexts/messageOverlayContext/hooks/useResettableState.test.js +4 -4
- package/lib/module/contexts/messageOverlayContext/hooks/useResettableState.test.js.map +1 -1
- package/lib/module/contexts/messagesContext/MessagesContext.js +14 -4
- package/lib/module/contexts/messagesContext/MessagesContext.js.map +1 -1
- package/lib/module/contexts/overlayContext/OverlayContext.js +13 -3
- package/lib/module/contexts/overlayContext/OverlayContext.js.map +1 -1
- package/lib/module/contexts/overlayContext/OverlayProvider.js +12 -12
- package/lib/module/contexts/overlayContext/OverlayProvider.js.map +1 -1
- package/lib/module/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js +13 -3
- package/lib/module/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js.map +1 -1
- package/lib/module/contexts/paginatedMessageListContext/PaginatedMessageListContext.js +14 -4
- package/lib/module/contexts/paginatedMessageListContext/PaginatedMessageListContext.js.map +1 -1
- package/lib/module/contexts/suggestionsContext/SuggestionsContext.js +14 -4
- package/lib/module/contexts/suggestionsContext/SuggestionsContext.js.map +1 -1
- package/lib/module/contexts/themeContext/ThemeContext.js +13 -7
- package/lib/module/contexts/themeContext/ThemeContext.js.map +1 -1
- package/lib/module/contexts/themeContext/utils/theme.js +9 -0
- package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
- package/lib/module/contexts/threadContext/ThreadContext.js +14 -4
- package/lib/module/contexts/threadContext/ThreadContext.js.map +1 -1
- package/lib/module/contexts/translationContext/TranslationContext.js +15 -6
- package/lib/module/contexts/translationContext/TranslationContext.js.map +1 -1
- package/lib/module/contexts/typingContext/TypingContext.js +14 -4
- package/lib/module/contexts/typingContext/TypingContext.js.map +1 -1
- package/lib/module/contexts/utils/defaultBaseContextValue.js +7 -0
- package/lib/module/contexts/utils/defaultBaseContextValue.js.map +1 -0
- package/lib/module/contexts/utils/isTestEnvironment.js +11 -0
- package/lib/module/contexts/utils/isTestEnvironment.js.map +1 -0
- package/lib/module/mock-builders/mock.js +30 -5
- package/lib/module/mock-builders/mock.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/contexts/__tests__/index.test.d.ts +1 -0
- package/lib/typescript/contexts/keyboardContext/KeyboardContext.d.ts +6 -2
- package/lib/typescript/contexts/themeContext/ThemeContext.d.ts +5 -2
- package/lib/typescript/contexts/themeContext/utils/theme.d.ts +6 -0
- package/lib/typescript/contexts/utils/defaultBaseContextValue.d.ts +1 -0
- package/lib/typescript/contexts/utils/isTestEnvironment.d.ts +1 -0
- package/lib/typescript/mock-builders/mock.d.ts +2 -2
- package/package.json +1 -1
- package/src/components/Attachment/Card.tsx +29 -6
- package/src/components/Attachment/__tests__/Attachment.test.js +0 -14
- package/src/components/Attachment/__tests__/Giphy.test.js +9 -5
- package/src/components/AutoCompleteInput/AutoCompleteSuggestionList.tsx +1 -0
- package/src/components/ImageGallery/components/__tests__/ImageGalleryHeader.test.tsx +5 -3
- package/src/components/MessageInput/SendMessageDisallowedIndicator.tsx +1 -0
- package/src/components/MessageInput/__tests__/FileUploadPreview.test.js +1 -1
- package/src/components/Reply/Reply.tsx +6 -3
- package/src/contexts/__tests__/index.test.tsx +103 -0
- package/src/contexts/activeChannelsRefContext/ActiveChannelsRefContext.tsx +1 -0
- package/src/contexts/attachmentPickerContext/AttachmentPickerContext.tsx +18 -4
- package/src/contexts/channelContext/ChannelContext.tsx +18 -2
- package/src/contexts/channelsContext/ChannelsContext.tsx +18 -2
- package/src/contexts/channelsStateContext/ChannelsStateContext.tsx +19 -10
- package/src/contexts/chatContext/ChatContext.tsx +15 -2
- package/src/contexts/imageGalleryContext/ImageGalleryContext.tsx +18 -3
- package/src/contexts/keyboardContext/KeyboardContext.tsx +2 -1
- package/src/contexts/messageContext/MessageContext.tsx +19 -2
- package/src/contexts/messageInputContext/MessageInputContext.tsx +22 -4
- package/src/contexts/messageOverlayContext/MessageOverlayContext.tsx +19 -3
- package/src/contexts/messageOverlayContext/hooks/useResettableState.test.tsx +1 -0
- package/src/contexts/messagesContext/MessagesContext.tsx +19 -2
- package/src/contexts/overlayContext/OverlayContext.tsx +17 -2
- package/src/contexts/overlayContext/OverlayProvider.tsx +1 -0
- package/src/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.tsx +18 -3
- package/src/contexts/paginatedMessageListContext/PaginatedMessageListContext.tsx +15 -3
- package/src/contexts/suggestionsContext/SuggestionsContext.tsx +19 -2
- package/src/contexts/suggestionsContext/__tests__/Suggestions.test.js +1 -0
- package/src/contexts/themeContext/ThemeContext.tsx +19 -5
- package/src/contexts/themeContext/utils/theme.ts +15 -0
- package/src/contexts/threadContext/ThreadContext.tsx +16 -2
- package/src/contexts/translationContext/TranslationContext.tsx +18 -4
- package/src/contexts/typingContext/TypingContext.tsx +17 -2
- package/src/contexts/utils/defaultBaseContextValue.ts +1 -0
- package/src/contexts/utils/isTestEnvironment.ts +1 -0
- package/src/mock-builders/mock.js +16 -3
- package/src/version.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Reply.tsx"],"names":["styles","StyleSheet","create","container","alignItems","flexDirection","fileAttachmentContainer","paddingLeft","paddingVertical","imageAttachment","borderRadius","height","marginLeft","marginVertical","width","messageContainer","borderBottomLeftRadius","borderBottomRightRadius","borderTopLeftRadius","borderTopRightRadius","flexGrow","flexShrink","text","fontSize","textContainer","maxWidth","undefined","paddingHorizontal","videoAttachment","getMessageType","lastAttachment","messageType","isLastAttachmentFile","type","isLastAttachmentVideo","isLastAttachmentGiphy","isLastAttachmentImageOrGiphy","title_link","og_scrape_url","isLastAttachmentImage","image_url","thumb_url","ReplyWithContext","props","FileAttachmentIcon","attachmentSize","MessageAvatar","quotedMessage","stylesProp","t","error","setError","theme","colors","blue_alice","border","grey","transparent","white","deletedText","messageSimple","content","reply","markdownStyles","attachments","slice","hasImage","onlyEmojis","emojiRegex","test","backgroundColor","borderColor","borderWidth","mime_type","uri","url","deleted_at","em","color","length","title","marginRight","Number","areEqual","prevProps","nextProps","prevQuotedMessage","nextQuotedMessage","quotedMessageEqual","id","MemoizedReply","React","memo","Reply","message","FileIconDefault","MessageAvatarDefault","editing","quotedEditingMessage","quoted_message","displayName"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AAIA;;AACA;;AAIA;;AAIA;;AACA;;AAKA;;AACA;;AAEA;;AACA;;AACA;;AACA;;;;;;;;;AAEA,IAAMA,MAAM,GAAGC,wBAAWC,MAAX,CAAkB;AAC/BC,EAAAA,SAAS,EAAE;AACTC,IAAAA,UAAU,EAAE,UADH;AAETC,IAAAA,aAAa,EAAE;AAFN,GADoB;AAK/BC,EAAAA,uBAAuB,EAAE;AAAEC,IAAAA,WAAW,EAAE,CAAf;AAAkBC,IAAAA,eAAe,EAAE;AAAnC,GALM;AAM/BC,EAAAA,eAAe,EAAE;AACfC,IAAAA,YAAY,EAAE,CADC;AAEfC,IAAAA,MAAM,EAAE,EAFO;AAGfC,IAAAA,UAAU,EAAE,CAHG;AAIfC,IAAAA,cAAc,EAAE,CAJD;AAKfC,IAAAA,KAAK,EAAE;AALQ,GANc;AAa/BC,EAAAA,gBAAgB,EAAE;AAChBX,IAAAA,UAAU,EAAE,YADI;AAEhBY,IAAAA,sBAAsB,EAAE,CAFR;AAGhBC,IAAAA,uBAAuB,EAAE,EAHT;AAIhBC,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mB,EAIhB;AACH,2BAAoB,wCAApB;AAAA,MAAQmD,OAAR,sBAAQA,OAAR;;AAEA,4BACE,0CADF;AAAA,kDAAQlD,kBAAR;AAAA,MAAQA,kBAAR,sCAA6BmD,kBAA7B;AAAA,kDAA8CjD,aAA9C;AAAA,MAA8CA,aAA9C,sCAA8DkD,4BAA9D;;AAGA,8BAAmC,kDAAnC;AAAA,MAAQC,OAAR,yBAAQA,OAAR;AAAA,MAAiBlD,aAAjB,yBAAiBA,aAAjB;;AAEA,MAAMmD,oBAAoB,GACxB,OAAOD,OAAP,KAAmB,SAAnB,GAA+B,CAAAA,OAAO,QAAP,YAAAA,OAAO,CAAEE,cAAT,KAA2B,KAA1D,GAAkE,KADpE;;AAIA,8BAAc,gDAAd;AAAA,MAAQlD,CAAR,yBAAQA,CAAR;;AAEA,SACE,gCAAC,aAAD;AAEIL,IAAAA,kBAAkB,EAAlBA,kBAFJ;AAGIE,IAAAA,aAAa,EAAbA,aAHJ;AAIIC,IAAAA,aAAa,EAAE+C,OAAO,GACjBA,OAAO,CAACK,cADS,GAElBpD,aAAa,IAAImD,oBANzB;AAOIjD,IAAAA,CAAC,EAADA;AAPJ,KASMN,KATN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KADF;AAaD,CA/BM;;;AAiCPkD,KAAK,CAACO,WAAN,GAAoB,cAApB","sourcesContent":["import React, { useState } from 'react';\nimport { Image, ImageStyle, StyleSheet, View, ViewStyle } from 'react-native';\n\nimport merge from 'lodash/merge';\n\nimport type { Attachment } from 'stream-chat';\n\nimport { useMessageContext } from '../../contexts/messageContext/MessageContext';\nimport {\n MessageInputContextValue,\n useMessageInputContext,\n} from '../../contexts/messageInputContext/MessageInputContext';\nimport {\n MessagesContextValue,\n useMessagesContext,\n} from '../../contexts/messagesContext/MessagesContext';\nimport { useTheme } from '../../contexts/themeContext/ThemeContext';\nimport {\n TranslationContextValue,\n useTranslationContext,\n} from '../../contexts/translationContext/TranslationContext';\nimport type { DefaultStreamChatGenerics } from '../../types/types';\nimport { getResizedImageUrl } from '../../utils/getResizedImageUrl';\nimport { emojiRegex } from '../../utils/utils';\n\nimport { FileIcon as FileIconDefault } from '../Attachment/FileIcon';\nimport { VideoThumbnail } from '../Attachment/VideoThumbnail';\nimport { MessageAvatar as MessageAvatarDefault } from '../Message/MessageSimple/MessageAvatar';\nimport { MessageTextContainer } from '../Message/MessageSimple/MessageTextContainer';\n\nconst styles = StyleSheet.create({\n container: {\n alignItems: 'flex-end',\n flexDirection: 'row',\n },\n fileAttachmentContainer: { paddingLeft: 8, paddingVertical: 8 },\n imageAttachment: {\n borderRadius: 8,\n height: 32,\n marginLeft: 8,\n marginVertical: 8,\n width: 32,\n },\n messageContainer: {\n alignItems: 'flex-start',\n borderBottomLeftRadius: 0,\n borderBottomRightRadius: 12,\n borderTopLeftRadius: 12,\n borderTopRightRadius: 12,\n flexDirection: 'row',\n flexGrow: 1,\n flexShrink: 1,\n },\n text: { fontSize: 12 },\n textContainer: { maxWidth: undefined, paddingHorizontal: 8 },\n videoAttachment: {\n borderRadius: 8,\n height: 50,\n marginLeft: 8,\n marginVertical: 8,\n width: 50,\n },\n});\n\ntype ReplyPropsWithContext<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = Pick<MessageInputContextValue<StreamChatGenerics>, 'quotedMessage'> &\n Pick<MessagesContextValue<StreamChatGenerics>, 'FileAttachmentIcon' | 'MessageAvatar'> &\n Pick<TranslationContextValue, 't'> & {\n attachmentSize?: number;\n styles?: Partial<{\n container: ViewStyle;\n fileAttachmentContainer: ViewStyle;\n imageAttachment: ImageStyle;\n messageContainer: ViewStyle;\n textContainer: ViewStyle;\n }>;\n };\n\nconst getMessageType = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n lastAttachment: Attachment<StreamChatGenerics>,\n) => {\n let messageType;\n\n const isLastAttachmentFile = lastAttachment.type === 'file' || lastAttachment.type === 'audio';\n\n const isLastAttachmentVideo = lastAttachment.type === 'video';\n\n const isLastAttachmentGiphy = lastAttachment.type === 'giphy' || lastAttachment.type === 'imgur';\n\n const isLastAttachmentImageOrGiphy =\n lastAttachment.type === 'image' && !lastAttachment.title_link && !lastAttachment.og_scrape_url;\n\n const isLastAttachmentImage = lastAttachment.image_url || lastAttachment.thumb_url;\n\n if (isLastAttachmentFile) {\n messageType = 'file';\n } else if (isLastAttachmentVideo) {\n messageType = 'video';\n } else if (isLastAttachmentImageOrGiphy) {\n if (isLastAttachmentImage) messageType = 'image';\n else messageType = undefined;\n } else if (isLastAttachmentGiphy) messageType = 'giphy';\n else messageType = 'other';\n\n return messageType;\n};\n\nconst ReplyWithContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: ReplyPropsWithContext<StreamChatGenerics>,\n) => {\n const {\n FileAttachmentIcon,\n attachmentSize = 40,\n MessageAvatar,\n quotedMessage,\n styles: stylesProp = {},\n t,\n } = props;\n\n const [error, setError] = useState(false);\n\n const {\n theme: {\n colors: { blue_alice, border, grey, transparent, white },\n messageSimple: {\n content: { deletedText },\n },\n reply: {\n container,\n fileAttachmentContainer,\n imageAttachment,\n markdownStyles,\n messageContainer,\n textContainer,\n },\n },\n } = useTheme();\n\n if (typeof quotedMessage === 'boolean') return null;\n\n const lastAttachment = quotedMessage.attachments?.slice(-1)[0] as Attachment<StreamChatGenerics>;\n const messageType = lastAttachment && getMessageType(lastAttachment);\n\n const hasImage =\n !error &&\n lastAttachment &&\n messageType !== 'file' &&\n (lastAttachment.image_url || lastAttachment.thumb_url || lastAttachment.og_scrape_url);\n\n const onlyEmojis = !lastAttachment && !!quotedMessage.text && emojiRegex.test(quotedMessage.text);\n\n return (\n <View style={[styles.container, container, stylesProp.container]}>\n <MessageAvatar alignment={'left'} lastGroupMessage message={quotedMessage} size={24} />\n <View\n style={[\n styles.messageContainer,\n {\n backgroundColor:\n messageType === 'other' ? blue_alice : messageType === 'giphy' ? transparent : white,\n borderColor: border,\n borderWidth: messageType === 'other' ? 0 : 1,\n },\n messageContainer,\n stylesProp.messageContainer,\n ]}\n >\n {!error && lastAttachment ? (\n messageType === 'file' ? (\n <View\n style={[\n styles.fileAttachmentContainer,\n fileAttachmentContainer,\n stylesProp.fileAttachmentContainer,\n ]}\n >\n <FileAttachmentIcon mimeType={lastAttachment.mime_type} size={attachmentSize} />\n </View>\n ) : hasImage ? (\n <Image\n onError={() => setError(true)}\n source={{\n uri: getResizedImageUrl({\n height:\n stylesProp.imageAttachment?.height ||\n imageAttachment?.height ||\n styles.imageAttachment.height,\n url: (lastAttachment.image_url ||\n lastAttachment.thumb_url ||\n lastAttachment.og_scrape_url) as string,\n width:\n stylesProp.imageAttachment?.width ||\n imageAttachment?.width ||\n styles.imageAttachment.width,\n }),\n }}\n style={[styles.imageAttachment, imageAttachment, stylesProp.imageAttachment]}\n />\n ) : null\n ) : null}\n {messageType === 'video' && !lastAttachment.og_scrape_url ? (\n <VideoThumbnail style={[styles.videoAttachment]} />\n ) : null}\n <MessageTextContainer<StreamChatGenerics>\n markdownStyles={\n quotedMessage.deleted_at\n ? merge({ em: { color: grey } }, deletedText)\n : { text: styles.text, ...markdownStyles }\n }\n message={{\n ...quotedMessage,\n text: quotedMessage.deleted_at\n ? `_${t('Message deleted')}_`\n : quotedMessage.text\n ? quotedMessage.text.length > 170\n ? `${quotedMessage.text.slice(0, 170)}...`\n : quotedMessage.text\n : messageType === 'image'\n ? t('Photo')\n : messageType === 'video'\n ? 'Video'\n : messageType === 'file'\n ? lastAttachment?.title || ''\n : '',\n }}\n onlyEmojis={onlyEmojis}\n styles={{\n textContainer: [\n {\n marginRight:\n hasImage || messageType === 'video'\n ? Number(\n stylesProp.imageAttachment?.height ||\n imageAttachment.height ||\n styles.imageAttachment.height,\n ) +\n Number(\n stylesProp.imageAttachment?.marginLeft ||\n imageAttachment.marginLeft ||\n styles.imageAttachment.marginLeft,\n )\n : messageType === 'file'\n ? attachmentSize +\n Number(\n stylesProp.fileAttachmentContainer?.paddingLeft ||\n fileAttachmentContainer.paddingLeft ||\n styles.fileAttachmentContainer.paddingLeft,\n )\n : undefined,\n },\n styles.textContainer,\n textContainer,\n stylesProp.textContainer,\n ],\n }}\n />\n </View>\n </View>\n );\n};\n\nconst areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(\n prevProps: ReplyPropsWithContext<StreamChatGenerics>,\n nextProps: ReplyPropsWithContext<StreamChatGenerics>,\n) => {\n const { quotedMessage: prevQuotedMessage } = prevProps;\n const { quotedMessage: nextQuotedMessage } = nextProps;\n\n const quotedMessageEqual =\n !!prevQuotedMessage &&\n !!nextQuotedMessage &&\n typeof prevQuotedMessage !== 'boolean' &&\n typeof nextQuotedMessage !== 'boolean'\n ? prevQuotedMessage.id === nextQuotedMessage.id &&\n prevQuotedMessage.deleted_at === nextQuotedMessage.deleted_at\n : !!prevQuotedMessage === !!nextQuotedMessage;\n\n if (!quotedMessageEqual) return false;\n\n return true;\n};\n\nconst MemoizedReply = React.memo(ReplyWithContext, areEqual) as typeof ReplyWithContext;\n\nexport type ReplyProps<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = Partial<ReplyPropsWithContext<StreamChatGenerics>>;\n\n/**\n * UI Component for reply\n */\nexport const Reply = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: ReplyProps<StreamChatGenerics>,\n) => {\n const { message } = useMessageContext<StreamChatGenerics>();\n\n const { FileAttachmentIcon = FileIconDefault, MessageAvatar = MessageAvatarDefault } =\n useMessagesContext<StreamChatGenerics>();\n\n const { editing, quotedMessage } = useMessageInputContext<StreamChatGenerics>();\n\n const quotedEditingMessage = (\n typeof editing !== 'boolean' ? editing?.quoted_message || false : false\n ) as MessageInputContextValue<StreamChatGenerics>['quotedMessage'];\n\n const { t } = useTranslationContext();\n\n return (\n <MemoizedReply\n {...{\n FileAttachmentIcon,\n MessageAvatar,\n quotedMessage: message\n ? (message.quoted_message as MessageInputContextValue<StreamChatGenerics>['quotedMessage'])\n : quotedMessage || quotedEditingMessage,\n t,\n }}\n {...props}\n />\n );\n};\n\nReply.displayName = 'Reply{reply}';\n"]}
|
|
1
|
+
{"version":3,"sources":["Reply.tsx"],"names":["styles","StyleSheet","create","container","alignItems","flexDirection","fileAttachmentContainer","paddingLeft","paddingVertical","imageAttachment","borderRadius","height","marginLeft","marginVertical","width","messageContainer","borderBottomLeftRadius","borderBottomRightRadius","borderTopLeftRadius","borderTopRightRadius","flexGrow","flexShrink","text","fontSize","textContainer","maxWidth","undefined","paddingHorizontal","videoAttachment","getMessageType","lastAttachment","messageType","isLastAttachmentFile","type","isLastAttachmentVideo","isLastAttachmentGiphy","isLastAttachmentImageOrGiphy","title_link","og_scrape_url","isLastAttachmentImage","image_url","thumb_url","ReplyWithContext","props","FileAttachmentIcon","attachmentSize","MessageAvatar","quotedMessage","stylesProp","t","error","setError","theme","colors","blue_alice","border","grey","transparent","white","deletedText","messageSimple","content","reply","markdownStyles","attachments","slice","hasImage","onlyEmojis","emojiRegex","test","backgroundColor","borderColor","borderWidth","mime_type","uri","url","deleted_at","em","color","length","title","marginRight","Number","areEqual","prevProps","nextProps","prevQuotedMessage","nextQuotedMessage","quotedMessageEqual","id","MemoizedReply","React","memo","Reply","message","FileIconDefault","MessageAvatarDefault","editing","quotedEditingMessage","quoted_message","displayName"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AAIA;;AACA;;AAIA;;AAIA;;AACA;;AAKA;;AACA;;AAEA;;AACA;;AACA;;AACA;;;;;;;;;AAEA,IAAMA,MAAM,GAAGC,wBAAWC,MAAX,CAAkB;AAC/BC,EAAAA,SAAS,EAAE;AACTC,IAAAA,UAAU,EAAE,UADH;AAETC,IAAAA,aAAa,EAAE;AAFN,GADoB;AAK/BC,EAAAA,uBAAuB,EAAE;AAAEC,IAAAA,WAAW,EAAE,CAAf;AAAkBC,IAAAA,eAAe,EAAE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,EAADA;AAPJ,KASMN,KATN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KADF;AAaD,CA/BM;;;AAiCPkD,KAAK,CAACO,WAAN,GAAoB,cAApB","sourcesContent":["import React, { useState } from 'react';\nimport { Image, ImageStyle, StyleSheet, View, ViewStyle } from 'react-native';\n\nimport merge from 'lodash/merge';\n\nimport type { Attachment } from 'stream-chat';\n\nimport { useMessageContext } from '../../contexts/messageContext/MessageContext';\nimport {\n MessageInputContextValue,\n useMessageInputContext,\n} from '../../contexts/messageInputContext/MessageInputContext';\nimport {\n MessagesContextValue,\n useMessagesContext,\n} from '../../contexts/messagesContext/MessagesContext';\nimport { useTheme } from '../../contexts/themeContext/ThemeContext';\nimport {\n TranslationContextValue,\n useTranslationContext,\n} from '../../contexts/translationContext/TranslationContext';\nimport type { DefaultStreamChatGenerics } from '../../types/types';\nimport { getResizedImageUrl } from '../../utils/getResizedImageUrl';\nimport { emojiRegex } from '../../utils/utils';\n\nimport { FileIcon as FileIconDefault } from '../Attachment/FileIcon';\nimport { VideoThumbnail } from '../Attachment/VideoThumbnail';\nimport { MessageAvatar as MessageAvatarDefault } from '../Message/MessageSimple/MessageAvatar';\nimport { MessageTextContainer } from '../Message/MessageSimple/MessageTextContainer';\n\nconst styles = StyleSheet.create({\n container: {\n alignItems: 'flex-end',\n flexDirection: 'row',\n },\n fileAttachmentContainer: { paddingLeft: 8, paddingVertical: 8 },\n imageAttachment: {\n borderRadius: 8,\n height: 32,\n marginLeft: 8,\n marginVertical: 8,\n width: 32,\n },\n messageContainer: {\n alignItems: 'flex-start',\n borderBottomLeftRadius: 0,\n borderBottomRightRadius: 12,\n borderTopLeftRadius: 12,\n borderTopRightRadius: 12,\n flexDirection: 'row',\n flexGrow: 1,\n flexShrink: 1,\n },\n text: { fontSize: 12 },\n textContainer: { maxWidth: undefined, paddingHorizontal: 8 },\n videoAttachment: {\n borderRadius: 8,\n height: 50,\n marginLeft: 8,\n marginVertical: 8,\n width: 50,\n },\n});\n\ntype ReplyPropsWithContext<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = Pick<MessageInputContextValue<StreamChatGenerics>, 'quotedMessage'> &\n Pick<MessagesContextValue<StreamChatGenerics>, 'FileAttachmentIcon' | 'MessageAvatar'> &\n Pick<TranslationContextValue, 't'> & {\n attachmentSize?: number;\n styles?: Partial<{\n container: ViewStyle;\n fileAttachmentContainer: ViewStyle;\n imageAttachment: ImageStyle;\n messageContainer: ViewStyle;\n textContainer: ViewStyle;\n }>;\n };\n\nconst getMessageType = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n lastAttachment: Attachment<StreamChatGenerics>,\n) => {\n let messageType;\n\n const isLastAttachmentFile = lastAttachment.type === 'file' || lastAttachment.type === 'audio';\n\n const isLastAttachmentVideo = lastAttachment.type === 'video';\n\n const isLastAttachmentGiphy =\n lastAttachment?.type === 'giphy' || lastAttachment?.type === 'imgur';\n\n const isLastAttachmentImageOrGiphy =\n lastAttachment?.type === 'image' &&\n !lastAttachment?.title_link &&\n !lastAttachment?.og_scrape_url;\n\n const isLastAttachmentImage = lastAttachment?.image_url || lastAttachment?.thumb_url;\n\n if (isLastAttachmentFile) {\n messageType = 'file';\n } else if (isLastAttachmentVideo) {\n messageType = 'video';\n } else if (isLastAttachmentImageOrGiphy) {\n if (isLastAttachmentImage) messageType = 'image';\n else messageType = undefined;\n } else if (isLastAttachmentGiphy) messageType = 'giphy';\n else messageType = 'other';\n\n return messageType;\n};\n\nconst ReplyWithContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: ReplyPropsWithContext<StreamChatGenerics>,\n) => {\n const {\n FileAttachmentIcon,\n attachmentSize = 40,\n MessageAvatar,\n quotedMessage,\n styles: stylesProp = {},\n t,\n } = props;\n\n const [error, setError] = useState(false);\n\n const {\n theme: {\n colors: { blue_alice, border, grey, transparent, white },\n messageSimple: {\n content: { deletedText },\n },\n reply: {\n container,\n fileAttachmentContainer,\n imageAttachment,\n markdownStyles,\n messageContainer,\n textContainer,\n },\n },\n } = useTheme();\n\n if (typeof quotedMessage === 'boolean') return null;\n\n const lastAttachment = quotedMessage.attachments?.slice(-1)[0] as Attachment<StreamChatGenerics>;\n const messageType = lastAttachment && getMessageType(lastAttachment);\n\n const hasImage =\n !error &&\n lastAttachment &&\n messageType !== 'file' &&\n (lastAttachment.image_url || lastAttachment.thumb_url || lastAttachment.og_scrape_url);\n\n const onlyEmojis = !lastAttachment && !!quotedMessage.text && emojiRegex.test(quotedMessage.text);\n\n return (\n <View style={[styles.container, container, stylesProp.container]}>\n <MessageAvatar alignment={'left'} lastGroupMessage message={quotedMessage} size={24} />\n <View\n style={[\n styles.messageContainer,\n {\n backgroundColor:\n messageType === 'other' ? blue_alice : messageType === 'giphy' ? transparent : white,\n borderColor: border,\n borderWidth: messageType === 'other' ? 0 : 1,\n },\n messageContainer,\n stylesProp.messageContainer,\n ]}\n >\n {!error && lastAttachment ? (\n messageType === 'file' ? (\n <View\n style={[\n styles.fileAttachmentContainer,\n fileAttachmentContainer,\n stylesProp.fileAttachmentContainer,\n ]}\n >\n <FileAttachmentIcon mimeType={lastAttachment.mime_type} size={attachmentSize} />\n </View>\n ) : hasImage ? (\n <Image\n onError={() => setError(true)}\n source={{\n uri: getResizedImageUrl({\n height:\n stylesProp.imageAttachment?.height ||\n imageAttachment?.height ||\n styles.imageAttachment.height,\n url: (lastAttachment.image_url ||\n lastAttachment.thumb_url ||\n lastAttachment.og_scrape_url) as string,\n width:\n stylesProp.imageAttachment?.width ||\n imageAttachment?.width ||\n styles.imageAttachment.width,\n }),\n }}\n style={[styles.imageAttachment, imageAttachment, stylesProp.imageAttachment]}\n />\n ) : null\n ) : null}\n {messageType === 'video' && !lastAttachment.og_scrape_url ? (\n <VideoThumbnail style={[styles.videoAttachment]} />\n ) : null}\n <MessageTextContainer<StreamChatGenerics>\n markdownStyles={\n quotedMessage.deleted_at\n ? merge({ em: { color: grey } }, deletedText)\n : { text: styles.text, ...markdownStyles }\n }\n message={{\n ...quotedMessage,\n text: quotedMessage.deleted_at\n ? `_${t('Message deleted')}_`\n : quotedMessage.text\n ? quotedMessage.text.length > 170\n ? `${quotedMessage.text.slice(0, 170)}...`\n : quotedMessage.text\n : messageType === 'image'\n ? t('Photo')\n : messageType === 'video'\n ? 'Video'\n : messageType === 'file'\n ? lastAttachment?.title || ''\n : '',\n }}\n onlyEmojis={onlyEmojis}\n styles={{\n textContainer: [\n {\n marginRight:\n hasImage || messageType === 'video'\n ? Number(\n stylesProp.imageAttachment?.height ||\n imageAttachment.height ||\n styles.imageAttachment.height,\n ) +\n Number(\n stylesProp.imageAttachment?.marginLeft ||\n imageAttachment.marginLeft ||\n styles.imageAttachment.marginLeft,\n )\n : messageType === 'file'\n ? attachmentSize +\n Number(\n stylesProp.fileAttachmentContainer?.paddingLeft ||\n fileAttachmentContainer.paddingLeft ||\n styles.fileAttachmentContainer.paddingLeft,\n )\n : undefined,\n },\n styles.textContainer,\n textContainer,\n stylesProp.textContainer,\n ],\n }}\n />\n </View>\n </View>\n );\n};\n\nconst areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(\n prevProps: ReplyPropsWithContext<StreamChatGenerics>,\n nextProps: ReplyPropsWithContext<StreamChatGenerics>,\n) => {\n const { quotedMessage: prevQuotedMessage } = prevProps;\n const { quotedMessage: nextQuotedMessage } = nextProps;\n\n const quotedMessageEqual =\n !!prevQuotedMessage &&\n !!nextQuotedMessage &&\n typeof prevQuotedMessage !== 'boolean' &&\n typeof nextQuotedMessage !== 'boolean'\n ? prevQuotedMessage.id === nextQuotedMessage.id &&\n prevQuotedMessage.deleted_at === nextQuotedMessage.deleted_at\n : !!prevQuotedMessage === !!nextQuotedMessage;\n\n if (!quotedMessageEqual) return false;\n\n return true;\n};\n\nconst MemoizedReply = React.memo(ReplyWithContext, areEqual) as typeof ReplyWithContext;\n\nexport type ReplyProps<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = Partial<ReplyPropsWithContext<StreamChatGenerics>>;\n\n/**\n * UI Component for reply\n */\nexport const Reply = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: ReplyProps<StreamChatGenerics>,\n) => {\n const { message } = useMessageContext<StreamChatGenerics>();\n\n const { FileAttachmentIcon = FileIconDefault, MessageAvatar = MessageAvatarDefault } =\n useMessagesContext<StreamChatGenerics>();\n\n const { editing, quotedMessage } = useMessageInputContext<StreamChatGenerics>();\n\n const quotedEditingMessage = (\n typeof editing !== 'boolean' ? editing?.quoted_message || false : false\n ) as MessageInputContextValue<StreamChatGenerics>['quotedMessage'];\n\n const { t } = useTranslationContext();\n\n return (\n <MemoizedReply\n {...{\n FileAttachmentIcon,\n MessageAvatar,\n quotedMessage: message\n ? (message.quoted_message as MessageInputContextValue<StreamChatGenerics>['quotedMessage'])\n : quotedMessage || quotedEditingMessage,\n t,\n }}\n {...props}\n />\n );\n};\n\nReply.displayName = 'Reply{reply}';\n"]}
|
|
@@ -32,7 +32,7 @@ var ActiveChannelsProvider = function ActiveChannelsProvider(_ref) {
|
|
|
32
32
|
__self: _this,
|
|
33
33
|
__source: {
|
|
34
34
|
fileName: _jsxFileName,
|
|
35
|
-
lineNumber:
|
|
35
|
+
lineNumber: 16,
|
|
36
36
|
columnNumber: 8
|
|
37
37
|
}
|
|
38
38
|
}, children);
|
|
@@ -54,7 +54,7 @@ var withActiveChannelsRefContext = function withActiveChannelsRefContext(Compone
|
|
|
54
54
|
__self: _this,
|
|
55
55
|
__source: {
|
|
56
56
|
fileName: _jsxFileName,
|
|
57
|
-
lineNumber:
|
|
57
|
+
lineNumber: 27,
|
|
58
58
|
columnNumber: 12
|
|
59
59
|
}
|
|
60
60
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ActiveChannelsRefContext.tsx"],"names":["ActiveChannelsContext","React","createContext","current","ActiveChannelsProvider","children","value","useActiveChannelsRefContext","withActiveChannelsRefContext","Component","WithActiveChannelsContextComponent","props","displayName"],"mappings":";;;;;;;;;;;AAAA;;
|
|
1
|
+
{"version":3,"sources":["ActiveChannelsRefContext.tsx"],"names":["ActiveChannelsContext","React","createContext","current","ActiveChannelsProvider","children","value","useActiveChannelsRefContext","withActiveChannelsRefContext","Component","WithActiveChannelsContextComponent","props","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAIA;;;;;;;;;AAIA,IAAMA,qBAAqB,GAAGC,kBAAMC,aAAN,CAAoB;AAAEC,EAAAA,OAAO,EAAE;AAAX,CAApB,CAA9B;;AAEO,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAyB;AAAA,MACpCC,QADoC,QACpCA,QADoC;AAAA,MAEpCC,KAFoC,QAEpCA,KAFoC;AAAA,SAK/B,gCAAC,qBAAD,CAAuB,QAAvB;AAAgC,IAAA,KAAK,EAAEA,KAAvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAA+CD,QAA/C,CAL+B;AAAA,CAA/B;;;;AAOA,IAAME,2BAA2B,GAAG,SAA9BA,2BAA8B;AAAA,SACzC,uBAAWP,qBAAX,CADyC;AAAA,CAApC;;;;AAGA,IAAMQ,4BAA4B,GAAG,SAA/BA,4BAA+B,CAC1CC,SAD0C,EAEF;AACxC,MAAMC,kCAAkC,GAAG,SAArCA,kCAAqC,CAACC,KAAD,EAAsC;AAC/E,QAAMX,qBAAqB,GAAGO,2BAA2B,EAAzD;AAEA,WAAO,gCAAC,SAAD,gCAAgBI,KAAhB;AAA6B,MAAA,cAAc,EAAEX,qBAA7C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAJD;;AAKAU,EAAAA,kCAAkC,CAACE,WAAnC,iCAA6E,oCAC3EH,SAD2E,CAA7E;AAGA,SAAOC,kCAAP;AACD,CAZM","sourcesContent":["import React, { PropsWithChildren, useContext } from 'react';\n\nimport type { UnknownType } from '../../types/types';\n\nimport { getDisplayName } from '../utils/getDisplayName';\n\ntype ActiveChannels = React.MutableRefObject<string[]>;\n\nconst ActiveChannelsContext = React.createContext({ current: [] } as ActiveChannels);\n\nexport const ActiveChannelsProvider = ({\n children,\n value,\n}: PropsWithChildren<{\n value: ActiveChannels;\n}>) => <ActiveChannelsContext.Provider value={value}>{children}</ActiveChannelsContext.Provider>;\n\nexport const useActiveChannelsRefContext = () =>\n useContext(ActiveChannelsContext) as unknown as ActiveChannels;\n\nexport const withActiveChannelsRefContext = <P extends UnknownType>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, 'activeChannels'>> => {\n const WithActiveChannelsContextComponent = (props: Omit<P, 'activeChannels'>) => {\n const ActiveChannelsContext = useActiveChannelsRefContext();\n\n return <Component {...(props as P)} activeChannels={ActiveChannelsContext} />;\n };\n WithActiveChannelsContextComponent.displayName = `WithActiveChannelsContext${getDisplayName(\n Component,\n )}`;\n return WithActiveChannelsContextComponent;\n};\n"]}
|
|
@@ -13,8 +13,12 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
13
13
|
|
|
14
14
|
var _react = _interopRequireWildcard(require("react"));
|
|
15
15
|
|
|
16
|
+
var _defaultBaseContextValue = require("../utils/defaultBaseContextValue");
|
|
17
|
+
|
|
16
18
|
var _getDisplayName = require("../utils/getDisplayName");
|
|
17
19
|
|
|
20
|
+
var _isTestEnvironment = require("../utils/isTestEnvironment");
|
|
21
|
+
|
|
18
22
|
var _this = this,
|
|
19
23
|
_jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/contexts/attachmentPickerContext/AttachmentPickerContext.tsx";
|
|
20
24
|
|
|
@@ -22,7 +26,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
22
26
|
|
|
23
27
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
24
28
|
|
|
25
|
-
var AttachmentPickerContext = _react["default"].createContext(
|
|
29
|
+
var AttachmentPickerContext = _react["default"].createContext(_defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE);
|
|
26
30
|
|
|
27
31
|
exports.AttachmentPickerContext = AttachmentPickerContext;
|
|
28
32
|
|
|
@@ -90,7 +94,7 @@ var AttachmentPickerProvider = function AttachmentPickerProvider(_ref) {
|
|
|
90
94
|
__self: _this,
|
|
91
95
|
__source: {
|
|
92
96
|
fileName: _jsxFileName,
|
|
93
|
-
lineNumber:
|
|
97
|
+
lineNumber: 116,
|
|
94
98
|
columnNumber: 5
|
|
95
99
|
}
|
|
96
100
|
}, children);
|
|
@@ -99,7 +103,13 @@ var AttachmentPickerProvider = function AttachmentPickerProvider(_ref) {
|
|
|
99
103
|
exports.AttachmentPickerProvider = AttachmentPickerProvider;
|
|
100
104
|
|
|
101
105
|
var useAttachmentPickerContext = function useAttachmentPickerContext() {
|
|
102
|
-
|
|
106
|
+
var contextValue = (0, _react.useContext)(AttachmentPickerContext);
|
|
107
|
+
|
|
108
|
+
if (contextValue === _defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE && !(0, _isTestEnvironment.isTestEnvironment)()) {
|
|
109
|
+
throw new Error("The useAttachmentPickerContext hook was called outside the AttachmentPickerContext provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return contextValue;
|
|
103
113
|
};
|
|
104
114
|
|
|
105
115
|
exports.useAttachmentPickerContext = useAttachmentPickerContext;
|
|
@@ -111,7 +121,7 @@ var withAttachmentPickerContext = function withAttachmentPickerContext(Component
|
|
|
111
121
|
__self: _this,
|
|
112
122
|
__source: {
|
|
113
123
|
fileName: _jsxFileName,
|
|
114
|
-
lineNumber:
|
|
124
|
+
lineNumber: 148,
|
|
115
125
|
columnNumber: 12
|
|
116
126
|
}
|
|
117
127
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["AttachmentPickerContext.tsx"],"names":["AttachmentPickerContext","React","createContext","AttachmentPickerProvider","children","value","bottomInsetValue","bottomInset","topInsetValue","topInset","setBottomInset","maxNumberOfFiles","setMaxNumberOfFiles","selectedImages","setSelectedImages","selectedFiles","setSelectedFiles","selectedPicker","setSelectedPicker","setTopInset","combinedValue","useAttachmentPickerContext","withAttachmentPickerContext","Component","WithAttachmentPickerContextComponent","props","attachmentPickerContext","displayName"],"mappings":";;;;;;;;;;;;;AAAA;;AAGA;;;;;;;;;AAsDO,IAAMA,uBAAuB,GAAGC,kBAAMC,aAAN,
|
|
1
|
+
{"version":3,"sources":["AttachmentPickerContext.tsx"],"names":["AttachmentPickerContext","React","createContext","DEFAULT_BASE_CONTEXT_VALUE","AttachmentPickerProvider","children","value","bottomInsetValue","bottomInset","topInsetValue","topInset","setBottomInset","maxNumberOfFiles","setMaxNumberOfFiles","selectedImages","setSelectedImages","selectedFiles","setSelectedFiles","selectedPicker","setSelectedPicker","setTopInset","combinedValue","useAttachmentPickerContext","contextValue","Error","withAttachmentPickerContext","Component","WithAttachmentPickerContextComponent","props","attachmentPickerContext","displayName"],"mappings":";;;;;;;;;;;;;AAAA;;AAGA;;AAEA;;AACA;;;;;;;;;AAsDO,IAAMA,uBAAuB,GAAGC,kBAAMC,aAAN,CACrCC,mDADq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JiB;AAKjBP,IAAAA,cAAc,EAAdA,cALiB;AAMjBE,IAAAA,mBAAmB,EAAnBA,mBANiB;AAOjBI,IAAAA,gBAAgB,EAAhBA,gBAPiB;AAQjBF,IAAAA,iBAAiB,EAAjBA,iBARiB;AASjBI,IAAAA,iBAAiB,EAAjBA,iBATiB;AAUjBC,IAAAA,WAAW,EAAXA;AAViB,KAWdd,KAXc;AAYjBE,IAAAA,WAAW,EAAXA,WAZiB;AAajBE,IAAAA,QAAQ,EAARA;AAbiB,IAAnB;AAgBA,SACE,gCAAC,uBAAD,CAAyB,QAAzB;AACE,IAAA,KAAK,EAAEW,aADT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAGGhB,QAHH,CADF;AAOD,CAzDM;;;;AA2DA,IAAMiB,0BAA0B,GAAG,SAA7BA,0BAA6B,GAAM;AAC9C,MAAMC,YAAY,GAAG,uBACnBvB,uBADmB,CAArB;;AAIA,MAAIuB,YAAY,KAAKpB,mDAAjB,IAA+C,CAAC,2CAApD,EAAyE;AACvE,UAAM,IAAIqB,KAAJ,8PAAN;AAGD;;AAED,SAAOD,YAAP;AACD,CAZM;;;;AAcA,IAAME,2BAA2B,GAAG,SAA9BA,2BAA8B,CAGzCC,SAHyC,EAIkC;AAC3E,MAAMC,oCAAoC,GAAG,SAAvCA,oCAAuC,CAC3CC,KAD2C,EAExC;AACH,QAAMC,uBAAuB,GAAGP,0BAA0B,EAA1D;AAEA,WAAO,gCAAC,SAAD,gCAAgBM,KAAhB,EAAkDC,uBAAlD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAND;;AAOAF,EAAAA,oCAAoC,CAACG,WAArC,mCAAiF,oCAC/EJ,SAD+E,CAAjF;AAGA,SAAOC,oCAAP;AACD,CAhBM","sourcesContent":["import React, { PropsWithChildren, useContext, useEffect, useState } from 'react';\n\nimport type { Asset, DefaultStreamChatGenerics, File } from '../../types/types';\nimport { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';\n\nimport { getDisplayName } from '../utils/getDisplayName';\nimport { isTestEnvironment } from '../utils/isTestEnvironment';\n\nexport type AttachmentPickerIconProps = {\n numberOfImageUploads: number;\n selectedPicker?: 'images';\n};\n\nexport type AttachmentPickerContextValue = {\n /**\n * `bottomInset` determine the height of the `AttachmentPicker` and the underlying shift to the `MessageList` when it is opened.\n * This can also be set via the `setBottomInset` function provided by the `useAttachmentPickerContext` hook.\n *\n * Please check [OverlayProvider](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#overlayprovider) section in Cookbook\n * for more details.\n */\n bottomInset: number;\n /**\n * Custom UI component for [camera selector icon](https://github.com/GetStream/stream-chat-react-native/blob/main/screenshots/docs/1.png)\n *\n * **Default: ** [CameraSelectorIcon](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/CameraSelectorIcon.tsx)\n */\n CameraSelectorIcon: React.ComponentType<AttachmentPickerIconProps>;\n closePicker: () => void;\n /**\n * Custom UI component for [file selector icon](https://github.com/GetStream/stream-chat-react-native/blob/main/screenshots/docs/1.png)\n *\n * **Default: ** [FileSelectorIcon](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/FileSelectorIcon.tsx)\n */\n FileSelectorIcon: React.ComponentType<AttachmentPickerIconProps>;\n /**\n * Custom UI component for [image selector icon](https://github.com/GetStream/stream-chat-react-native/blob/main/screenshots/docs/1.png)\n *\n * **Default: ** [ImageSelectorIcon](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/ImageSelectorIcon.tsx)\n */\n ImageSelectorIcon: React.ComponentType<AttachmentPickerIconProps>;\n /**\n * Limit for maximum files that can be attached per message.\n */\n maxNumberOfFiles: number;\n openPicker: () => void;\n selectedFiles: File[];\n selectedImages: Asset[];\n setBottomInset: React.Dispatch<React.SetStateAction<number>>;\n setMaxNumberOfFiles: React.Dispatch<React.SetStateAction<number>>;\n setSelectedFiles: React.Dispatch<React.SetStateAction<File[]>>;\n setSelectedImages: React.Dispatch<React.SetStateAction<Asset[]>>;\n setSelectedPicker: React.Dispatch<React.SetStateAction<'images' | undefined>>;\n setTopInset: React.Dispatch<React.SetStateAction<number>>;\n topInset: number;\n attachmentPickerBottomSheetHeight?: number;\n attachmentSelectionBarHeight?: number;\n selectedPicker?: 'images';\n};\n\nexport const AttachmentPickerContext = React.createContext(\n DEFAULT_BASE_CONTEXT_VALUE as AttachmentPickerContextValue,\n);\n\nexport const AttachmentPickerProvider = ({\n children,\n value,\n}: PropsWithChildren<{\n value?: Pick<\n AttachmentPickerContextValue,\n | 'attachmentSelectionBarHeight'\n | 'attachmentPickerBottomSheetHeight'\n | 'CameraSelectorIcon'\n | 'closePicker'\n | 'FileSelectorIcon'\n | 'ImageSelectorIcon'\n | 'openPicker'\n > &\n Partial<Pick<AttachmentPickerContextValue, 'bottomInset' | 'topInset'>>;\n}>) => {\n const bottomInsetValue = value?.bottomInset;\n const topInsetValue = value?.topInset;\n\n const [bottomInset, setBottomInset] = useState<number>(bottomInsetValue ?? 0);\n const [maxNumberOfFiles, setMaxNumberOfFiles] = useState(10);\n const [selectedImages, setSelectedImages] = useState<Asset[]>([]);\n const [selectedFiles, setSelectedFiles] = useState<File[]>([]);\n const [selectedPicker, setSelectedPicker] = useState<'images'>();\n const [topInset, setTopInset] = useState<number>(value?.topInset ?? 0);\n\n useEffect(() => {\n setBottomInset(bottomInsetValue ?? 0);\n }, [bottomInsetValue]);\n\n useEffect(() => {\n setTopInset(topInsetValue ?? 0);\n }, [topInsetValue]);\n\n const combinedValue = {\n maxNumberOfFiles,\n selectedFiles,\n selectedImages,\n selectedPicker,\n setBottomInset,\n setMaxNumberOfFiles,\n setSelectedFiles,\n setSelectedImages,\n setSelectedPicker,\n setTopInset,\n ...value,\n bottomInset,\n topInset,\n };\n\n return (\n <AttachmentPickerContext.Provider\n value={combinedValue as unknown as AttachmentPickerContextValue}\n >\n {children}\n </AttachmentPickerContext.Provider>\n );\n};\n\nexport const useAttachmentPickerContext = () => {\n const contextValue = useContext(\n AttachmentPickerContext,\n ) as unknown as AttachmentPickerContextValue;\n\n if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {\n throw new Error(\n `The useAttachmentPickerContext hook was called outside the AttachmentPickerContext provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,\n );\n }\n\n return contextValue;\n};\n\nexport const withAttachmentPickerContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<StreamChatGenerics>,\n): React.FC<Omit<StreamChatGenerics, keyof AttachmentPickerContextValue>> => {\n const WithAttachmentPickerContextComponent = (\n props: Omit<StreamChatGenerics, keyof AttachmentPickerContextValue>,\n ) => {\n const attachmentPickerContext = useAttachmentPickerContext();\n\n return <Component {...(props as StreamChatGenerics)} {...attachmentPickerContext} />;\n };\n WithAttachmentPickerContextComponent.displayName = `WithAttachmentPickerContext${getDisplayName(\n Component as React.ComponentType,\n )}`;\n return WithAttachmentPickerContextComponent;\n};\n"]}
|
|
@@ -11,8 +11,12 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
11
11
|
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
13
|
|
|
14
|
+
var _defaultBaseContextValue = require("../utils/defaultBaseContextValue");
|
|
15
|
+
|
|
14
16
|
var _getDisplayName = require("../utils/getDisplayName");
|
|
15
17
|
|
|
18
|
+
var _isTestEnvironment = require("../utils/isTestEnvironment");
|
|
19
|
+
|
|
16
20
|
var _this = this,
|
|
17
21
|
_jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/contexts/channelContext/ChannelContext.tsx";
|
|
18
22
|
|
|
@@ -20,7 +24,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
20
24
|
|
|
21
25
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
22
26
|
|
|
23
|
-
var ChannelContext = _react["default"].createContext(
|
|
27
|
+
var ChannelContext = _react["default"].createContext(_defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE);
|
|
24
28
|
|
|
25
29
|
exports.ChannelContext = ChannelContext;
|
|
26
30
|
|
|
@@ -32,7 +36,7 @@ var ChannelProvider = function ChannelProvider(_ref) {
|
|
|
32
36
|
__self: _this,
|
|
33
37
|
__source: {
|
|
34
38
|
fileName: _jsxFileName,
|
|
35
|
-
lineNumber:
|
|
39
|
+
lineNumber: 185,
|
|
36
40
|
columnNumber: 3
|
|
37
41
|
}
|
|
38
42
|
}, children);
|
|
@@ -41,7 +45,13 @@ var ChannelProvider = function ChannelProvider(_ref) {
|
|
|
41
45
|
exports.ChannelProvider = ChannelProvider;
|
|
42
46
|
|
|
43
47
|
var useChannelContext = function useChannelContext() {
|
|
44
|
-
|
|
48
|
+
var contextValue = (0, _react.useContext)(ChannelContext);
|
|
49
|
+
|
|
50
|
+
if (contextValue === _defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE && !(0, _isTestEnvironment.isTestEnvironment)()) {
|
|
51
|
+
throw new Error("The useChannelContext hook was called outside of the ChannelContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return contextValue;
|
|
45
55
|
};
|
|
46
56
|
|
|
47
57
|
exports.useChannelContext = useChannelContext;
|
|
@@ -53,7 +63,7 @@ var withChannelContext = function withChannelContext(Component) {
|
|
|
53
63
|
__self: _this,
|
|
54
64
|
__source: {
|
|
55
65
|
fileName: _jsxFileName,
|
|
56
|
-
lineNumber:
|
|
66
|
+
lineNumber: 221,
|
|
57
67
|
columnNumber: 12
|
|
58
68
|
}
|
|
59
69
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ChannelContext.tsx"],"names":["ChannelContext","React","createContext","ChannelProvider","children","value","useChannelContext","withChannelContext","Component","WithChannelContextComponent","props","channelContext","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAOA;;;;;;;;;AAkKO,IAAMA,cAAc,GAAGC,kBAAMC,aAAN,
|
|
1
|
+
{"version":3,"sources":["ChannelContext.tsx"],"names":["ChannelContext","React","createContext","DEFAULT_BASE_CONTEXT_VALUE","ChannelProvider","children","value","useChannelContext","contextValue","Error","withChannelContext","Component","WithChannelContextComponent","props","channelContext","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAOA;;AAEA;;AACA;;;;;;;;;AAkKO,IAAMA,cAAc,GAAGC,kBAAMC,aAAN,CAC5BC,mDAD4B,CAAvB;;;;AAIA,IAAMC,eAAe,GAAG,SAAlBA,eAAkB;AAAA,MAG7BC,QAH6B,QAG7BA,QAH6B;AAAA,MAI7BC,KAJ6B,QAI7BA,KAJ6B;AAAA,SAQ7B,gCAAC,cAAD,CAAgB,QAAhB;AAAyB,IAAA,KAAK,EAAEA,KAAhC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KACGD,QADH,CAR6B;AAAA,CAAxB;;;;AAaA,IAAME,iBAAiB,GAAG,SAApBA,iBAAoB,GAE1B;AACL,MAAMC,YAAY,GAAG,uBACnBR,cADmB,CAArB;;AAIA,MAAIQ,YAAY,KAAKL,mDAAjB,IAA+C,CAAC,2CAApD,EAAyE;AACvE,UAAM,IAAIM,KAAJ,8NAAN;AAGD;;AAED,SAAOD,YAAP;AACD,CAdM;;;;AAoBA,IAAME,kBAAkB,GAAG,SAArBA,kBAAqB,CAIhCC,SAJgC,EAKqC;AACrE,MAAMC,2BAA2B,GAAG,SAA9BA,2BAA8B,CAClCC,KADkC,EAE/B;AACH,QAAMC,cAAc,GAAGP,iBAAiB,EAAxC;AAEA,WAAO,gCAAC,SAAD,gCAAgBM,KAAhB,EAAiCC,cAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAND;;AAOAF,EAAAA,2BAA2B,CAACG,WAA5B,0BAA+D,oCAAeJ,SAAf,CAA/D;AACA,SAAOC,2BAAP;AACD,CAfM","sourcesContent":["import React, { PropsWithChildren, useContext } from 'react';\n\nimport type { Channel, ChannelState } from 'stream-chat';\n\nimport type { EmptyStateProps } from '../../components/Indicators/EmptyStateIndicator';\nimport type { LoadingProps } from '../../components/Indicators/LoadingIndicator';\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';\n\nimport { getDisplayName } from '../utils/getDisplayName';\nimport { isTestEnvironment } from '../utils/isTestEnvironment';\n\nexport type ChannelContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n /**\n * Instance of channel object from stream-chat package.\n *\n * Please check the docs around how to create or query channel - https://getstream.io/chat/docs/javascript/creating_channels/?language=javascript\n *\n * ```\n * import { StreamChat, Channel } from 'stream-chat';\n * import { Chat, Channel} from 'stream-chat-react-native';\n *\n * const client = StreamChat.getInstance('api_key');\n * await client.connectUser('user_id', 'user_token');\n * const channel = client.channel('messaging', 'channel_id');\n * await channel.watch();\n *\n * <Chat client={client}>\n * <Channel channel={channel}>\n * </Channel>\n * </Chat>\n * ```\n *\n * @overrideType Channel\n */\n channel: Channel<StreamChatGenerics>;\n /**\n * Custom UI component to display empty state when channel has no messages.\n *\n * **Default** [EmptyStateIndicator](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Indicators/EmptyStateIndicator.tsx)\n */\n EmptyStateIndicator: React.ComponentType<EmptyStateProps>;\n /**\n * When set to true, reactions will be limited to 1 per user. If user selects another reaction\n * then his previous reaction will be removed and replaced with new one.\n *\n * This is similar to reaction UX on [iMessage application](https://en.wikipedia.org/wiki/IMessage).\n */\n enforceUniqueReaction: boolean;\n error: boolean | Error;\n /**\n * When set to false, it will disable giphy command on MessageInput component.\n */\n giphyEnabled: boolean;\n /**\n * Hide inline date separators on channel\n */\n hideDateSeparators: boolean;\n hideStickyDateHeader: boolean;\n /**\n * Returns true if the current user has admin privileges\n */\n isAdmin: boolean;\n /**\n * Returns true if the current user is a moderator\n */\n isModerator: boolean;\n /**\n * Returns true if the current user is a owner\n */\n isOwner: boolean;\n loadChannelAtMessage: ({\n after,\n before,\n messageId,\n }: {\n after?: number;\n before?: number;\n messageId?: string;\n }) => Promise<void>;\n loading: boolean;\n /**\n * Custom loading indicator to override the Stream default\n */\n LoadingIndicator: React.ComponentType<LoadingProps>;\n markRead: () => void;\n /**\n *\n * ```json\n * {\n * \"thierry-123\": {\n * \"id\": \"thierry-123\",\n * \"role\": \"user\",\n * \"created_at\": \"2019-04-03T14:42:47.087869Z\",\n * \"updated_at\": \"2019-04-16T09:20:03.982283Z\",\n * \"last_active\": \"2019-04-16T11:23:51.168113408+02:00\",\n * \"online\": true\n * },\n * \"vishal-123\": {\n * \"id\": \"vishal-123\",\n * \"role\": \"user\",\n * \"created_at\": \"2019-05-03T14:42:47.087869Z\",\n * \"updated_at\": \"2019-05-16T09:20:03.982283Z\",\n * \"last_active\": \"2019-06-16T11:23:51.168113408+02:00\",\n * \"online\": false\n * }\n * }\n * ```\n */\n members: ChannelState<StreamChatGenerics>['members'];\n /**\n * Custom network down indicator to override the Stream default\n */\n NetworkDownIndicator: React.ComponentType;\n read: ChannelState<StreamChatGenerics>['read'];\n reloadChannel: () => Promise<void>;\n /**\n * When true, messagelist will be scrolled to first unread message, when opened.\n */\n scrollToFirstUnreadThreshold: number;\n setLastRead: React.Dispatch<React.SetStateAction<Date | undefined>>;\n setTargetedMessage: (messageId: string) => void;\n /**\n *\n * ```json\n * {\n * \"thierry-123\": {\n * \"id\": \"thierry-123\",\n * \"role\": \"user\",\n * \"created_at\": \"2019-04-03T14:42:47.087869Z\",\n * \"updated_at\": \"2019-04-16T09:20:03.982283Z\",\n * \"last_active\": \"2019-04-16T11:23:51.168113408+02:00\",\n * \"online\": true\n * },\n * \"vishal-123\": {\n * \"id\": \"vishal-123\",\n * \"role\": \"user\",\n * \"created_at\": \"2019-05-03T14:42:47.087869Z\",\n * \"updated_at\": \"2019-05-16T09:20:03.982283Z\",\n * \"last_active\": \"2019-06-16T11:23:51.168113408+02:00\",\n * \"online\": false\n * }\n * }\n * ```\n */\n watchers: ChannelState<StreamChatGenerics>['watchers'];\n disabled?: boolean;\n enableMessageGroupingByUser?: boolean;\n isChannelActive?: boolean;\n lastRead?: Date;\n /**\n * Maximum time in milliseconds that should occur between messages\n * to still consider them grouped together\n */\n maxTimeBetweenGroupedMessages?: number;\n /**\n * Custom UI component for sticky header of channel.\n *\n * **Default** [DateHeader](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageList/DateHeader.tsx)\n */\n StickyHeader?: React.ComponentType<{ dateString: string }>;\n /**\n * Id of message, around which Channel/MessageList gets loaded when opened.\n * You will see a highlighted background for targetted message, when opened.\n */\n targetedMessage?: string;\n threadList?: boolean;\n watcherCount?: ChannelState<StreamChatGenerics>['watcher_count'];\n};\n\nexport const ChannelContext = React.createContext(\n DEFAULT_BASE_CONTEXT_VALUE as ChannelContextValue,\n);\n\nexport const ChannelProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n value,\n}: PropsWithChildren<{\n value: ChannelContextValue<StreamChatGenerics>;\n}>) => (\n <ChannelContext.Provider value={value as unknown as ChannelContextValue}>\n {children}\n </ChannelContext.Provider>\n);\n\nexport const useChannelContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => {\n const contextValue = useContext(\n ChannelContext,\n ) as unknown as ChannelContextValue<StreamChatGenerics>;\n\n if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {\n throw new Error(\n `The useChannelContext hook was called outside of the ChannelContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,\n );\n }\n\n return contextValue;\n};\n/**\n * Typescript currently does not support partial inference so if ChatContext\n * typing is desired while using the HOC withChannelContext the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withChannelContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof ChannelContextValue<StreamChatGenerics>>> => {\n const WithChannelContextComponent = (\n props: Omit<P, keyof ChannelContextValue<StreamChatGenerics>>,\n ) => {\n const channelContext = useChannelContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...channelContext} />;\n };\n WithChannelContextComponent.displayName = `WithChannelContext${getDisplayName(Component)}`;\n return WithChannelContextComponent;\n};\n"]}
|
|
@@ -11,8 +11,12 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
11
11
|
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
13
|
|
|
14
|
+
var _defaultBaseContextValue = require("../utils/defaultBaseContextValue");
|
|
15
|
+
|
|
14
16
|
var _getDisplayName = require("../utils/getDisplayName");
|
|
15
17
|
|
|
18
|
+
var _isTestEnvironment = require("../utils/isTestEnvironment");
|
|
19
|
+
|
|
16
20
|
var _this = this,
|
|
17
21
|
_jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/contexts/channelsContext/ChannelsContext.tsx";
|
|
18
22
|
|
|
@@ -20,7 +24,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
20
24
|
|
|
21
25
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
22
26
|
|
|
23
|
-
var ChannelsContext = _react["default"].createContext(
|
|
27
|
+
var ChannelsContext = _react["default"].createContext(_defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE);
|
|
24
28
|
|
|
25
29
|
exports.ChannelsContext = ChannelsContext;
|
|
26
30
|
|
|
@@ -32,7 +36,7 @@ var ChannelsProvider = function ChannelsProvider(_ref) {
|
|
|
32
36
|
__self: _this,
|
|
33
37
|
__source: {
|
|
34
38
|
fileName: _jsxFileName,
|
|
35
|
-
lineNumber:
|
|
39
|
+
lineNumber: 225,
|
|
36
40
|
columnNumber: 3
|
|
37
41
|
}
|
|
38
42
|
}, children);
|
|
@@ -41,7 +45,13 @@ var ChannelsProvider = function ChannelsProvider(_ref) {
|
|
|
41
45
|
exports.ChannelsProvider = ChannelsProvider;
|
|
42
46
|
|
|
43
47
|
var useChannelsContext = function useChannelsContext() {
|
|
44
|
-
|
|
48
|
+
var contextValue = (0, _react.useContext)(ChannelsContext);
|
|
49
|
+
|
|
50
|
+
if (contextValue === _defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE && !(0, _isTestEnvironment.isTestEnvironment)()) {
|
|
51
|
+
throw new Error("The useChannelsContext hook was called outside of the ChannelsContext provider. Make sure you have configured ChannelList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel-list");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return contextValue;
|
|
45
55
|
};
|
|
46
56
|
|
|
47
57
|
exports.useChannelsContext = useChannelsContext;
|
|
@@ -53,7 +63,7 @@ var withChannelsContext = function withChannelsContext(Component) {
|
|
|
53
63
|
__self: _this,
|
|
54
64
|
__source: {
|
|
55
65
|
fileName: _jsxFileName,
|
|
56
|
-
lineNumber:
|
|
66
|
+
lineNumber: 261,
|
|
57
67
|
columnNumber: 12
|
|
58
68
|
}
|
|
59
69
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ChannelsContext.tsx"],"names":["ChannelsContext","React","createContext","ChannelsProvider","children","value","useChannelsContext","withChannelsContext","Component","WithChannelsContextComponent","props","channelsContext","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAqBA;;;;;;;;;AA4LO,IAAMA,eAAe,GAAGC,kBAAMC,aAAN,CAAoB,EAApB,CAAxB;;;;AAEA,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;AAAA,SAE3B,uBAAWN,eAAX,CAF2B;AAAA,CAA3B;;;;AASA,IAAMO,mBAAmB,GAAG,SAAtBA,mBAAsB,CAIjCC,SAJiC,EAKqC;AACtE,MAAMC,4BAA4B,GAAG,SAA/BA,4BAA+B,CACnCC,KADmC,EAEhC;AACH,QAAMC,eAAe,GAAGL,kBAAkB,EAA1C;AAEA,WAAO,gCAAC,SAAD,gCAAgBI,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 { FlatListProps } from 'react-native';\nimport type { FlatList } from 'react-native-gesture-handler';\n\nimport type { ChannelPreviewMutedStatusProps } from 'src/components/ChannelPreview/ChannelPreviewMutedStatus';\n\nimport type { Channel } from 'stream-chat';\n\nimport type { HeaderErrorProps } from '../../components/ChannelList/ChannelListHeaderErrorIndicator';\nimport type { QueryChannels } from '../../components/ChannelList/hooks/usePaginatedChannels';\nimport type { ChannelAvatarProps } from '../../components/ChannelPreview/ChannelAvatar';\nimport type { ChannelPreviewMessageProps } from '../../components/ChannelPreview/ChannelPreviewMessage';\nimport type { ChannelPreviewMessengerProps } from '../../components/ChannelPreview/ChannelPreviewMessenger';\nimport type { ChannelPreviewStatusProps } from '../../components/ChannelPreview/ChannelPreviewStatus';\nimport type { ChannelPreviewTitleProps } from '../../components/ChannelPreview/ChannelPreviewTitle';\nimport type { ChannelPreviewUnreadCountProps } from '../../components/ChannelPreview/ChannelPreviewUnreadCount';\nimport type { EmptyStateProps } from '../../components/Indicators/EmptyStateIndicator';\nimport type { LoadingErrorProps } from '../../components/Indicators/LoadingErrorIndicator';\nimport type { LoadingProps } from '../../components/Indicators/LoadingIndicator';\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport { getDisplayName } from '../utils/getDisplayName';\n\nexport type ChannelsContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n /**\n * Besides the existing default behavior of the ChannelListMessenger component, you can attach\n * additional props to the underlying React Native FlatList.\n *\n * You can find list of all the available FlatList props here - https://facebook.github.io/react-native/docs/flatlist#props\n *\n * **EXAMPLE:**\n *\n * ```\n * <ChannelListMessenger\n * channels={channels}\n * additionalFlatListProps={{ bounces: true }}\n * />\n * ```\n *\n * **Note:** Don't use `additionalFlatListProps` to access the FlatList ref, use `setFlatListRef`\n */\n additionalFlatListProps: Partial<FlatListProps<Channel<StreamChatGenerics>>>;\n /**\n * Channels can be either an array of channels or a promise which resolves to an array of channels\n */\n channels: Channel<StreamChatGenerics>[];\n /**\n * Custom indicator to use when channel list is empty\n *\n * Default: [EmptyStateIndicator](https://getstream.github.io/stream-chat-react-native/v3/#emptystateindicator)\n * */\n EmptyStateIndicator: React.ComponentType<EmptyStateProps>;\n /**\n * Custom loading indicator to display at bottom of the list, while loading further pages\n *\n * Default: [ChannelListFooterLoadingIndicator](https://getstream.github.io/stream-chat-react-native/v3/#ChannelListFooterLoadingIndicator)\n */\n FooterLoadingIndicator: React.ComponentType;\n /**\n * Incremental number change to force update the FlatList\n */\n forceUpdate: number;\n /**\n * Whether or not the FlatList has another page to render\n */\n hasNextPage: boolean;\n /**\n * Custom indicator to display error at top of list, if loading/pagination error occurs\n *\n * Default: [ChannelListHeaderErrorIndicator](https://getstream.github.io/stream-chat-react-native/v3/#ChannelListHeaderErrorIndicator)\n */\n HeaderErrorIndicator: React.ComponentType<HeaderErrorProps>;\n /**\n * Custom indicator to display network-down error at top of list, if there is connectivity issue\n *\n * Default: [ChannelListHeaderNetworkDownIndicator](https://getstream.github.io/stream-chat-react-native/v3/#ChannelListHeaderNetworkDownIndicator)\n */\n HeaderNetworkDownIndicator: React.ComponentType;\n /**\n * Initial channels query loading state, triggers the LoadingIndicator\n */\n loadingChannels: boolean;\n /**\n * Custom indicator to use when there is error in fetching channels\n *\n * Default: [LoadingErrorIndicator](https://getstream.github.io/stream-chat-react-native/v3/#loadingerrorindicator)\n * */\n LoadingErrorIndicator: React.ComponentType<LoadingErrorProps>;\n /**\n * Custom loading indicator to use on Channel List\n *\n * */\n LoadingIndicator: React.ComponentType<Pick<LoadingProps, 'listType'>>;\n /**\n * Whether or not additional channels are being loaded, triggers the FooterLoadingIndicator\n */\n loadingNextPage: boolean;\n /**\n * The React Native FlatList threshold to fetch more data\n * @see See loadMoreThreshold [doc](https://facebook.github.io/react-native/docs/flatlist#onendreachedthreshold)\n * */\n loadMoreThreshold: number;\n /**\n * Loads the next page of `channels`, which is present as a required prop\n */\n loadNextPage: QueryChannels | undefined;\n /**\n * Max number to display within notification badge. Default: 255 and it cannot be higher than that for now due to backend limitations\n */\n maxUnreadCount: number;\n /**\n * Number of skeletons that should show when loading. Default: 6\n */\n numberOfSkeletons: number;\n /**\n * Custom UI component to display individual channel list items\n *\n * Default: [ChannelPreviewMessenger](https://getstream.github.io/stream-chat-react-native/v3/#channelpreviewmessenger)\n */\n Preview: React.ComponentType<ChannelPreviewMessengerProps<StreamChatGenerics>>;\n /**\n * Triggered when the channel list is refreshing, displays a loading spinner at the top of the list\n */\n refreshing: boolean;\n /**\n * Function to refresh the channel list that is similar to `reloadList`, but it doesn't wipe out existing channels\n * from UI before loading the new ones\n */\n refreshList: () => void | Promise<void>;\n /**\n * Removes all the existing channels from UI and loads fresh channels\n * */\n reloadList: () => Promise<void>;\n // /**\n // * Function to set the currently active channel, acts as a bridge between ChannelList and Channel components\n // *\n // * @param channel A channel object\n // */\n // setActiveChannel?: (channel: Channel<StreamChatGenerics>) => void;\n /**\n * Function to gain access to the inner FlatList ref\n *\n * **Example:**\n *\n * ```\n * <ChannelListMessenger\n * setFlatListRef={(ref) => {\n * // Use ref for your own good\n * }}\n * ```\n */\n setFlatListRef: (ref: FlatList<Channel<StreamChatGenerics>> | null) => void;\n /**\n * Custom UI component to display loading channel skeletons\n *\n * Default: [Skeleton](https://getstream.github.io/stream-chat-react-native/v3/#skeleton)\n */\n Skeleton: React.ComponentType;\n /**\n * Error in channels query, if any\n */\n error?: Error;\n ListHeaderComponent?: React.ComponentType;\n /**\n * Function to set the currently active channel, acts as a bridge between ChannelList and Channel components\n *\n * @param channel A channel object\n */\n onSelect?: (channel: Channel<StreamChatGenerics>) => void;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelAvatar](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelAvatar.tsx)\n */\n PreviewAvatar?: React.ComponentType<ChannelAvatarProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview of latest message on channel.\n *\n * **Default** [ChannelPreviewMessage](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewMessage.tsx)\n */\n PreviewMessage?: React.ComponentType<ChannelPreviewMessageProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render muted status.\n *\n * **Default** [ChannelMutedStatus](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewMutedStatus.tsx)\n */\n PreviewMutedStatus?: React.ComponentType<ChannelPreviewMutedStatusProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelPreviewStatus](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewStatus.tsx)\n */\n PreviewStatus?: React.ComponentType<ChannelPreviewStatusProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelPreviewTitle](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewTitle.tsx)\n */\n PreviewTitle?: React.ComponentType<ChannelPreviewTitleProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelPreviewUnreadCount](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewUnreadCount.tsx)\n */\n PreviewUnreadCount?: React.ComponentType<ChannelPreviewUnreadCountProps<StreamChatGenerics>>;\n};\n\nexport const ChannelsContext = React.createContext({} as ChannelsContextValue);\n\nexport const ChannelsProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n value,\n}: PropsWithChildren<{\n value: ChannelsContextValue<StreamChatGenerics>;\n}>) => (\n <ChannelsContext.Provider value={value as unknown as ChannelsContextValue}>\n {children}\n </ChannelsContext.Provider>\n);\n\nexport const useChannelsContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => useContext(ChannelsContext) as unknown as ChannelsContextValue<StreamChatGenerics>;\n\n/**\n * Typescript currently does not support partial inference so if ChatContext\n * typing is desired while using the HOC withChannelContext the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withChannelsContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof ChannelsContextValue<StreamChatGenerics>>> => {\n const WithChannelsContextComponent = (\n props: Omit<P, keyof ChannelsContextValue<StreamChatGenerics>>,\n ) => {\n const channelsContext = useChannelsContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...channelsContext} />;\n };\n WithChannelsContextComponent.displayName = `WithChannelsContext${getDisplayName(Component)}`;\n return WithChannelsContextComponent;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["ChannelsContext.tsx"],"names":["ChannelsContext","React","createContext","DEFAULT_BASE_CONTEXT_VALUE","ChannelsProvider","children","value","useChannelsContext","contextValue","Error","withChannelsContext","Component","WithChannelsContextComponent","props","channelsContext","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAqBA;;AAEA;;AACA;;;;;;;;;AA4LO,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;;;;AAoBA,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 { FlatListProps } from 'react-native';\nimport type { FlatList } from 'react-native-gesture-handler';\n\nimport type { ChannelPreviewMutedStatusProps } from 'src/components/ChannelPreview/ChannelPreviewMutedStatus';\n\nimport type { Channel } from 'stream-chat';\n\nimport type { HeaderErrorProps } from '../../components/ChannelList/ChannelListHeaderErrorIndicator';\nimport type { QueryChannels } from '../../components/ChannelList/hooks/usePaginatedChannels';\nimport type { ChannelAvatarProps } from '../../components/ChannelPreview/ChannelAvatar';\nimport type { ChannelPreviewMessageProps } from '../../components/ChannelPreview/ChannelPreviewMessage';\nimport type { ChannelPreviewMessengerProps } from '../../components/ChannelPreview/ChannelPreviewMessenger';\nimport type { ChannelPreviewStatusProps } from '../../components/ChannelPreview/ChannelPreviewStatus';\nimport type { ChannelPreviewTitleProps } from '../../components/ChannelPreview/ChannelPreviewTitle';\nimport type { ChannelPreviewUnreadCountProps } from '../../components/ChannelPreview/ChannelPreviewUnreadCount';\nimport type { EmptyStateProps } from '../../components/Indicators/EmptyStateIndicator';\nimport type { LoadingErrorProps } from '../../components/Indicators/LoadingErrorIndicator';\nimport type { LoadingProps } from '../../components/Indicators/LoadingIndicator';\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';\n\nimport { getDisplayName } from '../utils/getDisplayName';\nimport { isTestEnvironment } from '../utils/isTestEnvironment';\n\nexport type ChannelsContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n /**\n * Besides the existing default behavior of the ChannelListMessenger component, you can attach\n * additional props to the underlying React Native FlatList.\n *\n * You can find list of all the available FlatList props here - https://facebook.github.io/react-native/docs/flatlist#props\n *\n * **EXAMPLE:**\n *\n * ```\n * <ChannelListMessenger\n * channels={channels}\n * additionalFlatListProps={{ bounces: true }}\n * />\n * ```\n *\n * **Note:** Don't use `additionalFlatListProps` to access the FlatList ref, use `setFlatListRef`\n */\n additionalFlatListProps: Partial<FlatListProps<Channel<StreamChatGenerics>>>;\n /**\n * Channels can be either an array of channels or a promise which resolves to an array of channels\n */\n channels: Channel<StreamChatGenerics>[];\n /**\n * Custom indicator to use when channel list is empty\n *\n * Default: [EmptyStateIndicator](https://getstream.github.io/stream-chat-react-native/v3/#emptystateindicator)\n * */\n EmptyStateIndicator: React.ComponentType<EmptyStateProps>;\n /**\n * Custom loading indicator to display at bottom of the list, while loading further pages\n *\n * Default: [ChannelListFooterLoadingIndicator](https://getstream.github.io/stream-chat-react-native/v3/#ChannelListFooterLoadingIndicator)\n */\n FooterLoadingIndicator: React.ComponentType;\n /**\n * Incremental number change to force update the FlatList\n */\n forceUpdate: number;\n /**\n * Whether or not the FlatList has another page to render\n */\n hasNextPage: boolean;\n /**\n * Custom indicator to display error at top of list, if loading/pagination error occurs\n *\n * Default: [ChannelListHeaderErrorIndicator](https://getstream.github.io/stream-chat-react-native/v3/#ChannelListHeaderErrorIndicator)\n */\n HeaderErrorIndicator: React.ComponentType<HeaderErrorProps>;\n /**\n * Custom indicator to display network-down error at top of list, if there is connectivity issue\n *\n * Default: [ChannelListHeaderNetworkDownIndicator](https://getstream.github.io/stream-chat-react-native/v3/#ChannelListHeaderNetworkDownIndicator)\n */\n HeaderNetworkDownIndicator: React.ComponentType;\n /**\n * Initial channels query loading state, triggers the LoadingIndicator\n */\n loadingChannels: boolean;\n /**\n * Custom indicator to use when there is error in fetching channels\n *\n * Default: [LoadingErrorIndicator](https://getstream.github.io/stream-chat-react-native/v3/#loadingerrorindicator)\n * */\n LoadingErrorIndicator: React.ComponentType<LoadingErrorProps>;\n /**\n * Custom loading indicator to use on Channel List\n *\n * */\n LoadingIndicator: React.ComponentType<Pick<LoadingProps, 'listType'>>;\n /**\n * Whether or not additional channels are being loaded, triggers the FooterLoadingIndicator\n */\n loadingNextPage: boolean;\n /**\n * The React Native FlatList threshold to fetch more data\n * @see See loadMoreThreshold [doc](https://facebook.github.io/react-native/docs/flatlist#onendreachedthreshold)\n * */\n loadMoreThreshold: number;\n /**\n * Loads the next page of `channels`, which is present as a required prop\n */\n loadNextPage: QueryChannels | undefined;\n /**\n * Max number to display within notification badge. Default: 255 and it cannot be higher than that for now due to backend limitations\n */\n maxUnreadCount: number;\n /**\n * Number of skeletons that should show when loading. Default: 6\n */\n numberOfSkeletons: number;\n /**\n * Custom UI component to display individual channel list items\n *\n * Default: [ChannelPreviewMessenger](https://getstream.github.io/stream-chat-react-native/v3/#channelpreviewmessenger)\n */\n Preview: React.ComponentType<ChannelPreviewMessengerProps<StreamChatGenerics>>;\n /**\n * Triggered when the channel list is refreshing, displays a loading spinner at the top of the list\n */\n refreshing: boolean;\n /**\n * Function to refresh the channel list that is similar to `reloadList`, but it doesn't wipe out existing channels\n * from UI before loading the new ones\n */\n refreshList: () => void | Promise<void>;\n /**\n * Removes all the existing channels from UI and loads fresh channels\n * */\n reloadList: () => Promise<void>;\n // /**\n // * Function to set the currently active channel, acts as a bridge between ChannelList and Channel components\n // *\n // * @param channel A channel object\n // */\n // setActiveChannel?: (channel: Channel<StreamChatGenerics>) => void;\n /**\n * Function to gain access to the inner FlatList ref\n *\n * **Example:**\n *\n * ```\n * <ChannelListMessenger\n * setFlatListRef={(ref) => {\n * // Use ref for your own good\n * }}\n * ```\n */\n setFlatListRef: (ref: FlatList<Channel<StreamChatGenerics>> | null) => void;\n /**\n * Custom UI component to display loading channel skeletons\n *\n * Default: [Skeleton](https://getstream.github.io/stream-chat-react-native/v3/#skeleton)\n */\n Skeleton: React.ComponentType;\n /**\n * Error in channels query, if any\n */\n error?: Error;\n ListHeaderComponent?: React.ComponentType;\n /**\n * Function to set the currently active channel, acts as a bridge between ChannelList and Channel components\n *\n * @param channel A channel object\n */\n onSelect?: (channel: Channel<StreamChatGenerics>) => void;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelAvatar](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelAvatar.tsx)\n */\n PreviewAvatar?: React.ComponentType<ChannelAvatarProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview of latest message on channel.\n *\n * **Default** [ChannelPreviewMessage](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewMessage.tsx)\n */\n PreviewMessage?: React.ComponentType<ChannelPreviewMessageProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render muted status.\n *\n * **Default** [ChannelMutedStatus](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewMutedStatus.tsx)\n */\n PreviewMutedStatus?: React.ComponentType<ChannelPreviewMutedStatusProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelPreviewStatus](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewStatus.tsx)\n */\n PreviewStatus?: React.ComponentType<ChannelPreviewStatusProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelPreviewTitle](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewTitle.tsx)\n */\n PreviewTitle?: React.ComponentType<ChannelPreviewTitleProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelPreviewUnreadCount](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewUnreadCount.tsx)\n */\n PreviewUnreadCount?: React.ComponentType<ChannelPreviewUnreadCountProps<StreamChatGenerics>>;\n};\n\nexport const ChannelsContext = React.createContext(\n DEFAULT_BASE_CONTEXT_VALUE as ChannelsContextValue,\n);\n\nexport const ChannelsProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n value,\n}: PropsWithChildren<{\n value: ChannelsContextValue<StreamChatGenerics>;\n}>) => (\n <ChannelsContext.Provider value={value as unknown as ChannelsContextValue}>\n {children}\n </ChannelsContext.Provider>\n);\n\nexport const useChannelsContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => {\n const contextValue = useContext(\n ChannelsContext,\n ) as unknown as ChannelsContextValue<StreamChatGenerics>;\n\n if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {\n throw new Error(\n `The useChannelsContext hook was called outside of the ChannelsContext provider. Make sure you have configured ChannelList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel-list`,\n );\n }\n\n return contextValue;\n};\n/**\n * Typescript currently does not support partial inference so if ChatContext\n * typing is desired while using the HOC withChannelContext the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withChannelsContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof ChannelsContextValue<StreamChatGenerics>>> => {\n const WithChannelsContextComponent = (\n props: Omit<P, keyof ChannelsContextValue<StreamChatGenerics>>,\n ) => {\n const channelsContext = useChannelsContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...channelsContext} />;\n };\n WithChannelsContextComponent.displayName = `WithChannelsContext${getDisplayName(Component)}`;\n return WithChannelsContextComponent;\n};\n"]}
|
|
@@ -17,8 +17,12 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
17
17
|
|
|
18
18
|
var _ActiveChannelsRefContext = require("../activeChannelsRefContext/ActiveChannelsRefContext");
|
|
19
19
|
|
|
20
|
+
var _defaultBaseContextValue = require("../utils/defaultBaseContextValue");
|
|
21
|
+
|
|
20
22
|
var _getDisplayName = require("../utils/getDisplayName");
|
|
21
23
|
|
|
24
|
+
var _isTestEnvironment = require("../utils/isTestEnvironment");
|
|
25
|
+
|
|
22
26
|
var _this = this,
|
|
23
27
|
_jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/contexts/channelsStateContext/ChannelsStateContext.tsx";
|
|
24
28
|
|
|
@@ -63,11 +67,7 @@ function reducer(state, action) {
|
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
var ChannelsStateContext = _react["default"].createContext(
|
|
67
|
-
removeChannelState: function removeChannelState() {},
|
|
68
|
-
setState: function setState() {},
|
|
69
|
-
state: {}
|
|
70
|
-
});
|
|
70
|
+
var ChannelsStateContext = _react["default"].createContext(_defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE);
|
|
71
71
|
|
|
72
72
|
var ChannelsStateProvider = function ChannelsStateProvider(_ref) {
|
|
73
73
|
var children = _ref.children;
|
|
@@ -112,7 +112,7 @@ var ChannelsStateProvider = function ChannelsStateProvider(_ref) {
|
|
|
112
112
|
__self: _this,
|
|
113
113
|
__source: {
|
|
114
114
|
fileName: _jsxFileName,
|
|
115
|
-
lineNumber:
|
|
115
|
+
lineNumber: 179,
|
|
116
116
|
columnNumber: 5
|
|
117
117
|
}
|
|
118
118
|
}, _react["default"].createElement(_ActiveChannelsRefContext.ActiveChannelsProvider, {
|
|
@@ -120,7 +120,7 @@ var ChannelsStateProvider = function ChannelsStateProvider(_ref) {
|
|
|
120
120
|
__self: _this,
|
|
121
121
|
__source: {
|
|
122
122
|
fileName: _jsxFileName,
|
|
123
|
-
lineNumber:
|
|
123
|
+
lineNumber: 180,
|
|
124
124
|
columnNumber: 7
|
|
125
125
|
}
|
|
126
126
|
}, children));
|
|
@@ -129,7 +129,13 @@ var ChannelsStateProvider = function ChannelsStateProvider(_ref) {
|
|
|
129
129
|
exports.ChannelsStateProvider = ChannelsStateProvider;
|
|
130
130
|
|
|
131
131
|
var useChannelsStateContext = function useChannelsStateContext() {
|
|
132
|
-
|
|
132
|
+
var contextValue = (0, _react.useContext)(ChannelsStateContext);
|
|
133
|
+
|
|
134
|
+
if (contextValue === _defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE && !(0, _isTestEnvironment.isTestEnvironment)()) {
|
|
135
|
+
throw new Error("The useChannelStateContext hook was called outside the ChannelStateContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return contextValue;
|
|
133
139
|
};
|
|
134
140
|
|
|
135
141
|
exports.useChannelsStateContext = useChannelsStateContext;
|
|
@@ -141,7 +147,7 @@ var withChannelsStateContext = function withChannelsStateContext(Component) {
|
|
|
141
147
|
__self: _this,
|
|
142
148
|
__source: {
|
|
143
149
|
fileName: _jsxFileName,
|
|
144
|
-
lineNumber:
|
|
150
|
+
lineNumber: 212,
|
|
145
151
|
columnNumber: 12
|
|
146
152
|
}
|
|
147
153
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ChannelsStateContext.tsx"],"names":["reducer","state","action","type","payload","cid","key","value","currentCount","subscriberCount","stateShallowCopy","Error","ChannelsStateContext","React","createContext","removeChannelState","setState","ChannelsStateProvider","children","dispatch","increaseSubscriberCount","decreaseSubscriberCount","activeChannelsRef","Object","keys","current","useChannelsStateContext","withChannelsStateContext","Component","WithChannelsStateContextComponent","props","channelsStateContext","displayName"],"mappings":";;;;;;;;;;;;;;;AAAA;;AAWA;;AAMA;;;;;;;;;AAmEA,SAASA,OAAT,CAAiBC,KAAjB,EAAuCC,MAAvC,EAAuD;AACrD,UAAQA,MAAM,CAACC,IAAf;AACE,SAAK,WAAL;AACE,2CACKF,KADL,uCAEGC,MAAM,CAACE,OAAP,CAAeC,GAFlB,gCAGQJ,KAAK,CAACC,MAAM,CAACE,OAAP,CAAeC,GAAhB,CAAL,IAA6B,EAHrC,uCAIKH,MAAM,CAACE,OAAP,CAAeE,GAJpB,EAI0BJ,MAAM,CAACE,OAAP,CAAeG,KAJzC;;AAQF,SAAK,2BAAL;AAAkC;AAAA;;AAChC,YAAMC,YAAY,sDAAGP,KAAK,CAACC,MAAM,CAACE,OAAP,CAAeC,GAAhB,CAAR,qBAAG,uBAA2BI,eAA9B,oCAAiD,CAAnE;AACA,6CACKR,KADL,uCAEGC,MAAM,CAACE,OAAP,CAAeC,GAFlB,gCAGQJ,KAAK,CAACC,MAAM,CAACE,OAAP,CAAeC,GAAhB,CAAL,IAA6B,EAHrC;AAIII,UAAAA,eAAe,EAAED,YAAY,GAAG;AAJpC;AAOD;;AAED,SAAK,2BAAL;AAAkC;AAAA;;AAChC,YAAMA,aAAY,uDAAGP,KAAK,CAACC,MAAM,CAACE,OAAP,CAAeC,GAAhB,CAAR,qBAAG,uBAA2BI,eAA9B,qCAAiD,CAAnE;;AAGA,YAAID,aAAY,IAAI,CAApB,EAAuB;AACrB,cAAME,gBAAgB,iCACjBT,KADiB,CAAtB;AAIA,iB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3E;AAGA,SAAOC,iCAAP;AACD,CAjBM","sourcesContent":["import React, {\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useReducer,\n useRef,\n} from 'react';\n\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport { ActiveChannelsProvider } from '../activeChannelsRefContext/ActiveChannelsRefContext';\n\nimport type { ChannelContextValue } from '../channelContext/ChannelContext';\nimport type { PaginatedMessageListContextValue } from '../paginatedMessageListContext/PaginatedMessageListContext';\nimport type { ThreadContextValue } from '../threadContext/ThreadContext';\nimport type { TypingContextValue } from '../typingContext/TypingContext';\nimport { getDisplayName } from '../utils/getDisplayName';\n\nexport type ChannelState<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n members: ChannelContextValue<StreamChatGenerics>['members'];\n messages: PaginatedMessageListContextValue<StreamChatGenerics>['messages'];\n read: ChannelContextValue<StreamChatGenerics>['read'];\n subscriberCount: number;\n threadMessages: ThreadContextValue<StreamChatGenerics>['threadMessages'];\n typing: TypingContextValue<StreamChatGenerics>['typing'];\n watcherCount: ChannelContextValue<StreamChatGenerics>['watcherCount'];\n watchers: ChannelContextValue<StreamChatGenerics>['watchers'];\n};\n\ntype ChannelsState<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n [cid: string]: ChannelState<StreamChatGenerics>;\n};\n\nexport type Keys = keyof ChannelState;\n\nexport type Payload<\n Key extends Keys = Keys,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n cid: string;\n key: Key;\n value: ChannelState<StreamChatGenerics>[Key];\n};\n\ntype SetStateAction<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n payload: Payload<Keys, StreamChatGenerics>;\n type: 'SET_STATE';\n};\n\ntype IncreaseSubscriberCountAction = {\n payload: { cid: string };\n type: 'INCREASE_SUBSCRIBER_COUNT';\n};\ntype DecreaseSubscriberCountAction = {\n payload: { cid: string };\n type: 'DECREASE_SUBSCRIBER_COUNT';\n};\n\ntype Action<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> =\n | SetStateAction<StreamChatGenerics>\n | IncreaseSubscriberCountAction\n | DecreaseSubscriberCountAction;\n\nexport type ChannelsStateContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n decreaseSubscriberCount: (value: { cid: string }) => void;\n increaseSubscriberCount: (value: { cid: string }) => void;\n setState: (value: Payload<Keys, StreamChatGenerics>) => void;\n state: ChannelsState<StreamChatGenerics>;\n};\n\ntype Reducer<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = (\n state: ChannelsState<StreamChatGenerics>,\n action: Action<StreamChatGenerics>,\n) => ChannelsState<StreamChatGenerics>;\n\nfunction reducer(state: ChannelsState, action: Action) {\n switch (action.type) {\n case 'SET_STATE':\n return {\n ...state,\n [action.payload.cid]: {\n ...(state[action.payload.cid] || {}),\n [action.payload.key]: action.payload.value,\n },\n };\n\n case 'INCREASE_SUBSCRIBER_COUNT': {\n const currentCount = state[action.payload.cid]?.subscriberCount ?? 0;\n return {\n ...state,\n [action.payload.cid]: {\n ...(state[action.payload.cid] || {}),\n subscriberCount: currentCount + 1,\n },\n };\n }\n\n case 'DECREASE_SUBSCRIBER_COUNT': {\n const currentCount = state[action.payload.cid]?.subscriberCount ?? 0;\n\n // If there last subscribed Channel component unsubscribes, we clear the channel state.\n if (currentCount <= 1) {\n const stateShallowCopy = {\n ...state,\n };\n\n delete stateShallowCopy[action.payload.cid];\n\n return stateShallowCopy;\n }\n\n return {\n ...state,\n [action.payload.cid]: {\n ...(state[action.payload.cid] || {}),\n subscriberCount: currentCount - 1,\n },\n };\n }\n default:\n throw new Error();\n }\n}\n\nconst ChannelsStateContext = React.createContext({\n removeChannelState: () => {\n // do nothing.\n },\n setState: () => {\n // do nothing.\n },\n state: {},\n} as unknown as ChannelsStateContextValue);\n\nexport const ChannelsStateProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n}: {\n children: ReactNode;\n}) => {\n const [state, dispatch] = useReducer(reducer as unknown as Reducer<StreamChatGenerics>, {});\n\n const setState = useCallback((payload: Payload<Keys, StreamChatGenerics>) => {\n dispatch({ payload, type: 'SET_STATE' });\n }, []);\n\n const increaseSubscriberCount = useCallback((payload: { cid: string }) => {\n dispatch({ payload, type: 'INCREASE_SUBSCRIBER_COUNT' });\n }, []);\n\n const decreaseSubscriberCount = useCallback((payload: { cid: string }) => {\n dispatch({ payload, type: 'DECREASE_SUBSCRIBER_COUNT' });\n }, []);\n\n const value = useMemo(\n () => ({\n decreaseSubscriberCount,\n increaseSubscriberCount,\n setState,\n state,\n }),\n [state],\n );\n\n const activeChannelsRef = useRef(Object.keys(state));\n\n useEffect(() => {\n activeChannelsRef.current = Object.keys(state);\n }, [state]);\n\n return (\n <ChannelsStateContext.Provider value={value as unknown as ChannelsStateContextValue}>\n <ActiveChannelsProvider value={activeChannelsRef}>{children}</ActiveChannelsProvider>\n </ChannelsStateContext.Provider>\n );\n};\n\nexport const useChannelsStateContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => useContext(ChannelsStateContext) as unknown as ChannelsStateContextValue<StreamChatGenerics>;\n\nexport const withChannelsStateContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof ChannelsStateContextValue<StreamChatGenerics>>> => {\n const WithChannelsStateContextComponent = (\n props: Omit<P, keyof ChannelsStateContextValue<StreamChatGenerics>>,\n ) => {\n const channelsStateContext = useChannelsStateContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...channelsStateContext} />;\n };\n WithChannelsStateContextComponent.displayName = `WithChannelsStateContext${getDisplayName(\n Component,\n )}`;\n return WithChannelsStateContextComponent;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["ChannelsStateContext.tsx"],"names":["reducer","state","action","type","payload","cid","key","value","currentCount","subscriberCount","stateShallowCopy","Error","ChannelsStateContext","React","createContext","DEFAULT_BASE_CONTEXT_VALUE","ChannelsStateProvider","children","dispatch","setState","increaseSubscriberCount","decreaseSubscriberCount","activeChannelsRef","Object","keys","current","useChannelsStateContext","contextValue","withChannelsStateContext","Component","WithChannelsStateContextComponent","props","channelsStateContext","displayName"],"mappings":";;;;;;;;;;;;;;;AAAA;;AAWA;;AAMA;;AAEA;;AACA;;;;;;;;;AAmEA,SAASA,OAAT,CAAiBC,KAAjB,EAAuCC,MAAvC,EAAuD;AACrD,UAAQA,MAAM,CAACC,IAAf;AACE,SAAK,WAAL;AACE,2CACKF,KADL,uCAEGC,MAAM,CAACE,OAAP,CAAeC,GAFlB,gCAGQJ,KAAK,CAACC,MAAM,CAACE,OAAP,CAAeC,GAAhB,CAAL,IAA6B,EAHrC,uCAIKH,MAAM,CAACE,OAAP,CAAeE,GAJpB,EAI0BJ,MAAM,CAACE,OAAP,CAAeG,KAJzC;;AAQF,SAAK,2BAAL;AAAkC;AAAA;;AAChC,YAAMC,YAAY,sDAAGP,KAAK,CAACC,MAAM,CAACE,OAAP,CAAeC,GAAhB,CAAR,qBAAG,uBAA2BI,eAA9B,oCAAiD,CAAnE;AACA,6CACKR,KADL,uCAEGC,MAAM,CAACE,OAAP,CAAeC,GAFlB,gCAGQJ,KAAK,CAACC,MAAM,CAACE,OAAP,CAAeC,GAAhB,CAAL,IAA6B,EAHrC;AAIII,UAAAA,eAAe,EAAED,YAAY,GAAG;AAJpC;AAOD;;AAED,SAAK,2BAAL;AAAkC;AAAA;;AAChC,YAAMA,aAAY,uDAAGP,KAAK,CAACC,MAAM,CAACE,OAAP,CAAeC,GAAhB,CAAR,qBAAG,uBAA2BI,eAA9B,qCAAiD,CAAnE;;AAGA,YAAID,aAAY,IAAI,CAApB,EAAuB;AACrB,cAAME,gB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AACG,WAAlC,gCAA2E,oCACzEJ,SADyE,CAA3E;AAGA,SAAOC,iCAAP;AACD,CAjBM","sourcesContent":["import React, {\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useReducer,\n useRef,\n} from 'react';\n\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport { ActiveChannelsProvider } from '../activeChannelsRefContext/ActiveChannelsRefContext';\n\nimport type { ChannelContextValue } from '../channelContext/ChannelContext';\nimport type { PaginatedMessageListContextValue } from '../paginatedMessageListContext/PaginatedMessageListContext';\nimport type { ThreadContextValue } from '../threadContext/ThreadContext';\nimport type { TypingContextValue } from '../typingContext/TypingContext';\nimport { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';\n\nimport { getDisplayName } from '../utils/getDisplayName';\nimport { isTestEnvironment } from '../utils/isTestEnvironment';\n\nexport type ChannelState<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n members: ChannelContextValue<StreamChatGenerics>['members'];\n messages: PaginatedMessageListContextValue<StreamChatGenerics>['messages'];\n read: ChannelContextValue<StreamChatGenerics>['read'];\n subscriberCount: number;\n threadMessages: ThreadContextValue<StreamChatGenerics>['threadMessages'];\n typing: TypingContextValue<StreamChatGenerics>['typing'];\n watcherCount: ChannelContextValue<StreamChatGenerics>['watcherCount'];\n watchers: ChannelContextValue<StreamChatGenerics>['watchers'];\n};\n\ntype ChannelsState<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n [cid: string]: ChannelState<StreamChatGenerics>;\n};\n\nexport type Keys = keyof ChannelState;\n\nexport type Payload<\n Key extends Keys = Keys,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n cid: string;\n key: Key;\n value: ChannelState<StreamChatGenerics>[Key];\n};\n\ntype SetStateAction<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n payload: Payload<Keys, StreamChatGenerics>;\n type: 'SET_STATE';\n};\n\ntype IncreaseSubscriberCountAction = {\n payload: { cid: string };\n type: 'INCREASE_SUBSCRIBER_COUNT';\n};\ntype DecreaseSubscriberCountAction = {\n payload: { cid: string };\n type: 'DECREASE_SUBSCRIBER_COUNT';\n};\n\ntype Action<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> =\n | SetStateAction<StreamChatGenerics>\n | IncreaseSubscriberCountAction\n | DecreaseSubscriberCountAction;\n\nexport type ChannelsStateContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n decreaseSubscriberCount: (value: { cid: string }) => void;\n increaseSubscriberCount: (value: { cid: string }) => void;\n setState: (value: Payload<Keys, StreamChatGenerics>) => void;\n state: ChannelsState<StreamChatGenerics>;\n};\n\ntype Reducer<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = (\n state: ChannelsState<StreamChatGenerics>,\n action: Action<StreamChatGenerics>,\n) => ChannelsState<StreamChatGenerics>;\n\nfunction reducer(state: ChannelsState, action: Action) {\n switch (action.type) {\n case 'SET_STATE':\n return {\n ...state,\n [action.payload.cid]: {\n ...(state[action.payload.cid] || {}),\n [action.payload.key]: action.payload.value,\n },\n };\n\n case 'INCREASE_SUBSCRIBER_COUNT': {\n const currentCount = state[action.payload.cid]?.subscriberCount ?? 0;\n return {\n ...state,\n [action.payload.cid]: {\n ...(state[action.payload.cid] || {}),\n subscriberCount: currentCount + 1,\n },\n };\n }\n\n case 'DECREASE_SUBSCRIBER_COUNT': {\n const currentCount = state[action.payload.cid]?.subscriberCount ?? 0;\n\n // If there last subscribed Channel component unsubscribes, we clear the channel state.\n if (currentCount <= 1) {\n const stateShallowCopy = {\n ...state,\n };\n\n delete stateShallowCopy[action.payload.cid];\n\n return stateShallowCopy;\n }\n\n return {\n ...state,\n [action.payload.cid]: {\n ...(state[action.payload.cid] || {}),\n subscriberCount: currentCount - 1,\n },\n };\n }\n default:\n throw new Error();\n }\n}\n\nconst ChannelsStateContext = React.createContext(\n DEFAULT_BASE_CONTEXT_VALUE as ChannelsStateContextValue,\n);\n\nexport const ChannelsStateProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n}: {\n children: ReactNode;\n}) => {\n const [state, dispatch] = useReducer(reducer as unknown as Reducer<StreamChatGenerics>, {});\n\n const setState = useCallback((payload: Payload<Keys, StreamChatGenerics>) => {\n dispatch({ payload, type: 'SET_STATE' });\n }, []);\n\n const increaseSubscriberCount = useCallback((payload: { cid: string }) => {\n dispatch({ payload, type: 'INCREASE_SUBSCRIBER_COUNT' });\n }, []);\n\n const decreaseSubscriberCount = useCallback((payload: { cid: string }) => {\n dispatch({ payload, type: 'DECREASE_SUBSCRIBER_COUNT' });\n }, []);\n\n const value = useMemo(\n () => ({\n decreaseSubscriberCount,\n increaseSubscriberCount,\n setState,\n state,\n }),\n [state],\n );\n\n const activeChannelsRef = useRef(Object.keys(state));\n\n useEffect(() => {\n activeChannelsRef.current = Object.keys(state);\n }, [state]);\n\n return (\n <ChannelsStateContext.Provider value={value as unknown as ChannelsStateContextValue}>\n <ActiveChannelsProvider value={activeChannelsRef}>{children}</ActiveChannelsProvider>\n </ChannelsStateContext.Provider>\n );\n};\n\nexport const useChannelsStateContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => {\n const contextValue = useContext(\n ChannelsStateContext,\n ) as unknown as ChannelsStateContextValue<StreamChatGenerics>;\n\n if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {\n throw new Error(\n `The useChannelStateContext hook was called outside the ChannelStateContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,\n );\n }\n\n return contextValue;\n};\n\nexport const withChannelsStateContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof ChannelsStateContextValue<StreamChatGenerics>>> => {\n const WithChannelsStateContextComponent = (\n props: Omit<P, keyof ChannelsStateContextValue<StreamChatGenerics>>,\n ) => {\n const channelsStateContext = useChannelsStateContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...channelsStateContext} />;\n };\n WithChannelsStateContextComponent.displayName = `WithChannelsStateContext${getDisplayName(\n Component,\n )}`;\n return WithChannelsStateContextComponent;\n};\n"]}
|