stream-chat-react-native-core 5.8.0 → 5.8.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/lib/commonjs/components/ChannelList/ChannelList.js +5 -3
  2. package/lib/commonjs/components/ChannelList/ChannelList.js.map +1 -1
  3. package/lib/commonjs/components/ChannelList/ChannelListFooterLoadingIndicator.js +2 -0
  4. package/lib/commonjs/components/ChannelList/ChannelListFooterLoadingIndicator.js.map +1 -1
  5. package/lib/commonjs/components/ChannelList/ChannelListMessenger.js +23 -25
  6. package/lib/commonjs/components/ChannelList/ChannelListMessenger.js.map +1 -1
  7. package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessage.js +5 -2
  8. package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessage.js.map +1 -1
  9. package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessageNotification.js +11 -8
  10. package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessageNotification.js.map +1 -1
  11. package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js +64 -48
  12. package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
  13. package/lib/commonjs/components/Message/utils/messageActions.js.map +1 -1
  14. package/lib/commonjs/contexts/channelsContext/ChannelsContext.js.map +1 -1
  15. package/lib/commonjs/version.json +1 -1
  16. package/lib/module/components/ChannelList/ChannelList.js +5 -3
  17. package/lib/module/components/ChannelList/ChannelList.js.map +1 -1
  18. package/lib/module/components/ChannelList/ChannelListFooterLoadingIndicator.js +2 -0
  19. package/lib/module/components/ChannelList/ChannelListFooterLoadingIndicator.js.map +1 -1
  20. package/lib/module/components/ChannelList/ChannelListMessenger.js +23 -25
  21. package/lib/module/components/ChannelList/ChannelListMessenger.js.map +1 -1
  22. package/lib/module/components/ChannelList/hooks/listeners/useNewMessage.js +5 -2
  23. package/lib/module/components/ChannelList/hooks/listeners/useNewMessage.js.map +1 -1
  24. package/lib/module/components/ChannelList/hooks/listeners/useNewMessageNotification.js +11 -8
  25. package/lib/module/components/ChannelList/hooks/listeners/useNewMessageNotification.js.map +1 -1
  26. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js +64 -48
  27. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
  28. package/lib/module/components/Message/utils/messageActions.js.map +1 -1
  29. package/lib/module/contexts/channelsContext/ChannelsContext.js.map +1 -1
  30. package/lib/module/version.json +1 -1
  31. package/lib/typescript/components/ChannelList/ChannelListMessenger.d.ts +1 -1
  32. package/lib/typescript/components/ChannelList/hooks/listeners/useNewMessage.d.ts +3 -2
  33. package/lib/typescript/components/ChannelList/hooks/listeners/useNewMessageNotification.d.ts +3 -2
  34. package/lib/typescript/components/ChannelList/hooks/usePaginatedChannels.d.ts +2 -2
  35. package/lib/typescript/components/Message/utils/messageActions.d.ts +1 -1
  36. package/lib/typescript/contexts/channelsContext/ChannelsContext.d.ts +1 -1
  37. package/package.json +1 -1
  38. package/src/components/ChannelList/ChannelList.tsx +4 -2
  39. package/src/components/ChannelList/ChannelListFooterLoadingIndicator.tsx +1 -1
  40. package/src/components/ChannelList/ChannelListMessenger.tsx +9 -7
  41. package/src/components/ChannelList/hooks/listeners/useNewMessage.ts +14 -2
  42. package/src/components/ChannelList/hooks/listeners/useNewMessageNotification.ts +8 -2
  43. package/src/components/ChannelList/hooks/usePaginatedChannels.ts +11 -12
  44. package/src/components/Message/utils/messageActions.ts +1 -1
  45. package/src/contexts/channelsContext/ChannelsContext.tsx +1 -1
  46. package/src/version.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"names":["waitSeconds","seconds","Promise","resolve","setTimeout","ONE_SECOND_IN_MS","DEFAULT_OPTIONS","message_limit","MAX_NUMBER_OF_RETRIES","RETRY_INTERVAL_IN_MS","usePaginatedChannels","enableOfflineSupport","filters","options","setForceUpdate","sort","useChatContext","client","useState","channels","setChannels","staticChannelsActive","setStaticChannelsActive","activeChannels","useActiveChannelsRefContext","error","setError","hasNextPage","setHasNextPage","lastRefresh","useRef","Date","now","isQueryingRef","activeQueryType","setActiveQueryType","isMountedRef","useIsMountedRef","filtersRef","sortRef","activeRequestId","queryChannels","queryType","retryCount","current","hasUpdatedData","JSON","stringify","some","Boolean","isQueryStale","currentRequestId","undefined","newOptions","limit","MAX_QUERY_CHANNELS_LIMIT","offset","length","activeChannelIds","cid","id","push","skipInitialization","channelQueryResponse","newChannels","map","c","existingChannel","console","warn","Error","loadNextPage","refreshList","reloadList","filterStr","useMemo","sortStr","useEffect","loadOfflineChannels","user","channelsFromDB","getChannelsForFilterSort","currentUserId","hydrateActiveChannels","offlineMode","e","listener","DBSyncManager","onSyncStatusChange","syncStatus","dbSyncStatus","getSyncStatus","on","event","online","u","unsubscribe","loadingChannels","loadingNextPage","refreshing"],"sources":["usePaginatedChannels.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\n\nimport type { Channel, ChannelFilters, ChannelOptions, ChannelSort } from 'stream-chat';\n\nimport { useActiveChannelsRefContext } from '../../../contexts/activeChannelsRefContext/ActiveChannelsRefContext';\n\nimport { useChatContext } from '../../../contexts/chatContext/ChatContext';\nimport { useIsMountedRef } from '../../../hooks/useIsMountedRef';\n\nimport { getChannelsForFilterSort } from '../../../store/apis/getChannelsForFilterSort';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\nimport { ONE_SECOND_IN_MS } from '../../../utils/date';\nimport { DBSyncManager } from '../../../utils/DBSyncManager';\nimport { MAX_QUERY_CHANNELS_LIMIT } from '../utils';\n\nconst waitSeconds = (seconds: number) =>\n new Promise((resolve) => {\n setTimeout(resolve, seconds * ONE_SECOND_IN_MS);\n });\n\ntype Parameters<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> =\n {\n enableOfflineSupport: boolean;\n filters: ChannelFilters<StreamChatGenerics>;\n options: ChannelOptions;\n setForceUpdate: React.Dispatch<React.SetStateAction<number>>;\n sort: ChannelSort<StreamChatGenerics>;\n };\n\nconst DEFAULT_OPTIONS = {\n message_limit: 10,\n};\n\nconst MAX_NUMBER_OF_RETRIES = 3;\nconst RETRY_INTERVAL_IN_MS = 5000;\n\ntype QueryType = 'queryLocalDB' | 'reload' | 'refresh' | 'loadChannels';\n\nexport type QueryChannels = (queryType?: QueryType, retryCount?: number) => Promise<void>;\n\nexport const usePaginatedChannels = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n enableOfflineSupport,\n filters = {},\n options = DEFAULT_OPTIONS,\n setForceUpdate,\n sort = {},\n}: Parameters<StreamChatGenerics>) => {\n const { client } = useChatContext<StreamChatGenerics>();\n const [channels, setChannels] = useState<Channel<StreamChatGenerics>[] | null>(null);\n const [staticChannelsActive, setStaticChannelsActive] = useState<boolean>(false);\n const activeChannels = useActiveChannelsRefContext();\n const [error, setError] = useState<Error>();\n const [hasNextPage, setHasNextPage] = useState(true);\n const lastRefresh = useRef(Date.now());\n const isQueryingRef = useRef(false);\n const [activeQueryType, setActiveQueryType] = useState<QueryType | null>('queryLocalDB');\n const isMountedRef = useIsMountedRef();\n const filtersRef = useRef<typeof filters | null>(null);\n const sortRef = useRef<typeof sort | null>(null);\n const activeRequestId = useRef<number>(0);\n\n const queryChannels: QueryChannels = async (\n queryType: QueryType = 'loadChannels',\n retryCount = 0,\n ): Promise<void> => {\n if (!client || !isMountedRef.current) return;\n\n const hasUpdatedData =\n queryType === 'loadChannels' ||\n queryType === 'refresh' ||\n [\n JSON.stringify(filtersRef.current) !== JSON.stringify(filters),\n JSON.stringify(sortRef.current) !== JSON.stringify(sort),\n ].some(Boolean);\n\n const isQueryStale = () => !isMountedRef || activeRequestId.current !== currentRequestId;\n\n /**\n * We don't need to make another call to query channels if we don't\n * have new data for the query to include\n * */\n if (!hasUpdatedData) {\n if (activeQueryType === null) return;\n }\n\n filtersRef.current = filters;\n sortRef.current = sort;\n isQueryingRef.current = true;\n setError(undefined);\n activeRequestId.current++;\n const currentRequestId = activeRequestId.current;\n setActiveQueryType(queryType);\n\n const newOptions = {\n limit: options?.limit ?? MAX_QUERY_CHANNELS_LIMIT,\n offset:\n queryType === 'loadChannels' && !staticChannelsActive && channels ? channels.length : 0,\n ...options,\n };\n\n try {\n const activeChannelIds: string[] = [];\n for (const cid in client.activeChannels) {\n if (client.activeChannels[cid].id) {\n // @ts-ignore\n activeChannelIds.push(client.activeChannels[cid].id);\n }\n }\n\n // TODO: Think about the implications of this.\n const channelQueryResponse = await client.queryChannels(filters, sort, newOptions, {\n skipInitialization: enableOfflineSupport ? activeChannelIds : activeChannels.current,\n });\n if (isQueryStale() || !isMountedRef.current) {\n return;\n }\n\n const newChannels =\n queryType === 'loadChannels' && !staticChannelsActive && channels\n ? [...channels, ...channelQueryResponse]\n : channelQueryResponse.map((c) => {\n const existingChannel = client.activeChannels[c.cid];\n if (existingChannel) {\n return existingChannel;\n }\n\n return c;\n });\n\n setChannels(newChannels);\n setStaticChannelsActive(false);\n setHasNextPage(channelQueryResponse.length >= newOptions.limit);\n setError(undefined);\n isQueryingRef.current = false;\n } catch (err: unknown) {\n isQueryingRef.current = false;\n await waitSeconds(2);\n\n if (isQueryStale()) {\n return;\n }\n\n // querying.current check is needed in order to make sure the next query call doesnt flick an error\n // state and then succeed (reconnect case)\n if (retryCount === MAX_NUMBER_OF_RETRIES && !isQueryingRef.current) {\n setActiveQueryType(null);\n console.warn(err);\n\n setError(\n new Error(\n `Maximum number of retries reached in queryChannels. Last error message is: ${err}`,\n ),\n );\n return;\n }\n\n return queryChannels(queryType, retryCount + 1);\n }\n\n setActiveQueryType(null);\n };\n\n const loadNextPage = hasNextPage ? queryChannels : undefined;\n\n const refreshList = () => {\n const now = Date.now();\n // Only allow pull-to-refresh 5 seconds after last successful refresh.\n if (now - lastRefresh.current < RETRY_INTERVAL_IN_MS && error === undefined) {\n return;\n }\n\n lastRefresh.current = Date.now();\n return queryChannels('refresh');\n };\n\n const reloadList = () => queryChannels('reload');\n\n /**\n * Equality check using stringified filters/sort ensure that we don't make un-necessary queryChannels api calls\n * for the scenario:\n *\n * <ChannelList\n * filters={{\n * members: { $in: ['vishal'] }\n * }}\n * ...\n * />\n *\n * Here we have passed filters as inline object, which means on every re-render of\n * parent component, ChannelList will receive new object reference (even though value is same), which\n * in return will trigger useEffect. To avoid this, we can add a value check.\n */\n const filterStr = useMemo(() => JSON.stringify(filters), [filters]);\n const sortStr = useMemo(() => JSON.stringify(sort), [sort]);\n\n useEffect(() => {\n const loadOfflineChannels = () => {\n if (!client?.user?.id) return;\n\n try {\n const channelsFromDB = getChannelsForFilterSort({\n currentUserId: client.user.id,\n filters,\n sort,\n });\n\n if (channelsFromDB) {\n setChannels(\n client.hydrateActiveChannels(channelsFromDB, {\n offlineMode: true,\n }),\n );\n setStaticChannelsActive(true);\n }\n } catch (e) {\n console.warn('Failed to get channels from database: ', e);\n }\n\n setActiveQueryType(null);\n };\n\n let listener: ReturnType<typeof DBSyncManager.onSyncStatusChange>;\n if (enableOfflineSupport) {\n // Any time DB is synced, we need to update the UI with local DB channels first,\n // and then call queryChannels to ensure any new channels are added to UI.\n listener = DBSyncManager.onSyncStatusChange((syncStatus) => {\n if (syncStatus) {\n loadOfflineChannels();\n reloadList();\n }\n });\n // On start, load the channels from local db.\n loadOfflineChannels();\n\n // If db is already synced (sync api and pending api calls), then\n // right away call queryChannels.\n const dbSyncStatus = DBSyncManager.getSyncStatus();\n if (dbSyncStatus) {\n reloadList();\n }\n } else {\n listener = client.on('connection.changed', async (event) => {\n if (event.online) {\n await refreshList();\n setForceUpdate((u) => u + 1);\n }\n });\n\n reloadList();\n }\n\n return () => listener?.unsubscribe?.();\n }, [filterStr, sortStr]);\n\n return {\n channels,\n error,\n hasNextPage,\n loadingChannels:\n activeQueryType === 'queryLocalDB'\n ? true\n : (activeQueryType === 'reload' || activeQueryType === null) && channels === null,\n loadingNextPage: activeQueryType === 'loadChannels',\n loadNextPage,\n refreshing: activeQueryType === 'refresh',\n refreshList,\n reloadList,\n // Although channels can be null, there is no practical case where channels will be null\n // when setChannels is used. setChannels is only recommended to be used for overriding\n // event handler. Thus instead of adding if check for channels === null, its better to\n // simply reassign types here.\n setChannels,\n staticChannelsActive,\n };\n};\n"],"mappings":";;;;;;;;;;AAAA;AAIA;AAEA;AACA;AAEA;AAEA;AACA;AACA;AAEA,IAAMA,WAAW,GAAG,SAAdA,WAAW,CAAIC,OAAe;EAAA,OAClC,IAAIC,OAAO,CAAC,UAACC,OAAO,EAAK;IACvBC,UAAU,CAACD,OAAO,EAAEF,OAAO,GAAGI,sBAAgB,CAAC;EACjD,CAAC,CAAC;AAAA;AAWJ,IAAMC,eAAe,GAAG;EACtBC,aAAa,EAAE;AACjB,CAAC;AAED,IAAMC,qBAAqB,GAAG,CAAC;AAC/B,IAAMC,oBAAoB,GAAG,IAAI;AAM1B,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAoB,OAQK;EAAA,IALpCC,oBAAoB,QAApBA,oBAAoB;IAAA,oBACpBC,OAAO;IAAPA,OAAO,6BAAG,CAAC,CAAC;IAAA,oBACZC,OAAO;IAAPA,OAAO,6BAAGP,eAAe;IACzBQ,cAAc,QAAdA,cAAc;IAAA,iBACdC,IAAI;IAAJA,IAAI,0BAAG,CAAC,CAAC;EAET,sBAAmB,IAAAC,2BAAc,GAAsB;IAA/CC,MAAM,mBAANA,MAAM;EACd,gBAAgC,IAAAC,eAAQ,EAAuC,IAAI,CAAC;IAAA;IAA7EC,QAAQ;IAAEC,WAAW;EAC5B,iBAAwD,IAAAF,eAAQ,EAAU,KAAK,CAAC;IAAA;IAAzEG,oBAAoB;IAAEC,uBAAuB;EACpD,IAAMC,cAAc,GAAG,IAAAC,qDAA2B,GAAE;EACpD,iBAA0B,IAAAN,eAAQ,GAAS;IAAA;IAApCO,KAAK;IAAEC,QAAQ;EACtB,iBAAsC,IAAAR,eAAQ,EAAC,IAAI,CAAC;IAAA;IAA7CS,WAAW;IAAEC,cAAc;EAClC,IAAMC,WAAW,GAAG,IAAAC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AULT_OPTIONS","message_limit","MAX_NUMBER_OF_RETRIES","RETRY_INTERVAL_IN_MS","usePaginatedChannels","enableOfflineSupport","filters","options","setForceUpdate","sort","useState","channels","setChannels","undefined","error","setError","staticChannelsActive","setStaticChannelsActive","activeQueryType","setActiveQueryType","hasNextPage","setHasNextPage","activeChannels","useActiveChannelsRefContext","isMountedRef","useIsMountedRef","useChatContext","client","filtersRef","useRef","sortRef","activeRequestId","isQueryingRef","lastRefresh","Date","now","queryChannels","queryType","retryCount","current","hasUpdatedData","JSON","stringify","some","Boolean","isQueryStale","currentRequestId","newOptions","limit","MAX_QUERY_CHANNELS_LIMIT","offset","length","activeChannelIds","cid","id","push","skipInitialization","channelQueryResponse","newChannels","map","c","existingChannel","console","warn","Error","refreshList","reloadList","filterStr","useMemo","sortStr","useEffect","loadOfflineChannels","user","channelsFromDB","getChannelsForFilterSort","currentUserId","hydrateActiveChannels","offlineMode","e","listener","DBSyncManager","onSyncStatusChange","syncStatus","dbSyncStatus","getSyncStatus","on","event","online","u","unsubscribe","loadingChannels","loadingNextPage","loadNextPage","refreshing"],"sources":["usePaginatedChannels.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\n\nimport type { Channel, ChannelFilters, ChannelOptions, ChannelSort } from 'stream-chat';\n\nimport { useActiveChannelsRefContext } from '../../../contexts/activeChannelsRefContext/ActiveChannelsRefContext';\n\nimport { useChatContext } from '../../../contexts/chatContext/ChatContext';\nimport { useIsMountedRef } from '../../../hooks/useIsMountedRef';\n\nimport { getChannelsForFilterSort } from '../../../store/apis/getChannelsForFilterSort';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\nimport { ONE_SECOND_IN_MS } from '../../../utils/date';\nimport { DBSyncManager } from '../../../utils/DBSyncManager';\nimport { MAX_QUERY_CHANNELS_LIMIT } from '../utils';\n\nconst waitSeconds = (seconds: number) =>\n new Promise((resolve) => {\n setTimeout(resolve, seconds * ONE_SECOND_IN_MS);\n });\n\ntype Parameters<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> =\n {\n enableOfflineSupport: boolean;\n filters: ChannelFilters<StreamChatGenerics>;\n options: ChannelOptions;\n setForceUpdate: React.Dispatch<React.SetStateAction<number>>;\n sort: ChannelSort<StreamChatGenerics>;\n };\n\nconst DEFAULT_OPTIONS = {\n message_limit: 10,\n};\n\nconst MAX_NUMBER_OF_RETRIES = 3;\nconst RETRY_INTERVAL_IN_MS = 5000;\n\ntype QueryType = 'queryLocalDB' | 'reload' | 'refresh' | 'loadChannels';\n\nexport type QueryChannels = (queryType?: QueryType, retryCount?: number) => Promise<void>;\n\nexport const usePaginatedChannels = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n enableOfflineSupport,\n filters = {},\n options = DEFAULT_OPTIONS,\n setForceUpdate,\n sort = {},\n}: Parameters<StreamChatGenerics>) => {\n const [channels, setChannels] = useState<Channel<StreamChatGenerics>[] | null>(null);\n const [error, setError] = useState<Error | undefined>(undefined);\n const [staticChannelsActive, setStaticChannelsActive] = useState<boolean>(false);\n const [activeQueryType, setActiveQueryType] = useState<QueryType | null>('queryLocalDB');\n const [hasNextPage, setHasNextPage] = useState<boolean>(false);\n\n const activeChannels = useActiveChannelsRefContext();\n const isMountedRef = useIsMountedRef();\n const { client } = useChatContext<StreamChatGenerics>();\n\n const filtersRef = useRef<typeof filters | null>(null);\n const sortRef = useRef<typeof sort | null>(null);\n const activeRequestId = useRef<number>(0);\n const isQueryingRef = useRef(false);\n const lastRefresh = useRef(Date.now());\n\n const queryChannels: QueryChannels = async (\n queryType: QueryType = 'loadChannels',\n retryCount = 0,\n ): Promise<void> => {\n if (!client || !isMountedRef.current) return;\n\n const hasUpdatedData =\n queryType === 'loadChannels' ||\n queryType === 'refresh' ||\n [\n JSON.stringify(filtersRef.current) !== JSON.stringify(filters),\n JSON.stringify(sortRef.current) !== JSON.stringify(sort),\n ].some(Boolean);\n\n const isQueryStale = () => !isMountedRef || activeRequestId.current !== currentRequestId;\n\n /**\n * We don't need to make another call to query channels if we don't\n * have new data for the query to include\n * */\n if (!hasUpdatedData) {\n if (activeQueryType === null) return;\n }\n\n filtersRef.current = filters;\n sortRef.current = sort;\n isQueryingRef.current = true;\n setError(undefined);\n activeRequestId.current++;\n const currentRequestId = activeRequestId.current;\n setActiveQueryType(queryType);\n\n const newOptions = {\n limit: options?.limit ?? MAX_QUERY_CHANNELS_LIMIT,\n offset:\n queryType === 'loadChannels' && !staticChannelsActive && channels ? channels.length : 0,\n ...options,\n };\n\n try {\n const activeChannelIds: string[] = [];\n for (const cid in client.activeChannels) {\n if (client.activeChannels[cid].id) {\n // @ts-ignore\n activeChannelIds.push(client.activeChannels[cid].id);\n }\n }\n\n // TODO: Think about the implications of this.\n const channelQueryResponse = await client.queryChannels(filters, sort, newOptions, {\n skipInitialization: enableOfflineSupport ? activeChannelIds : activeChannels.current,\n });\n if (isQueryStale() || !isMountedRef.current) {\n return;\n }\n\n const newChannels =\n queryType === 'loadChannels' && !staticChannelsActive && channels\n ? [...channels, ...channelQueryResponse]\n : channelQueryResponse.map((c) => {\n const existingChannel = client.activeChannels[c.cid];\n if (existingChannel) {\n return existingChannel;\n }\n\n return c;\n });\n\n setChannels(newChannels);\n setStaticChannelsActive(false);\n setHasNextPage(channelQueryResponse.length >= newOptions.limit);\n isQueryingRef.current = false;\n } catch (err: unknown) {\n isQueryingRef.current = false;\n await waitSeconds(2);\n\n if (isQueryStale()) {\n return;\n }\n\n // querying.current check is needed in order to make sure the next query call doesnt flick an error\n // state and then succeed (reconnect case)\n if (retryCount === MAX_NUMBER_OF_RETRIES && !isQueryingRef.current) {\n setActiveQueryType(null);\n console.warn(err);\n\n setError(\n new Error(\n `Maximum number of retries reached in queryChannels. Last error message is: ${err}`,\n ),\n );\n return;\n }\n\n return queryChannels(queryType, retryCount + 1);\n }\n\n setActiveQueryType(null);\n };\n\n const refreshList = async () => {\n const now = Date.now();\n // Only allow pull-to-refresh 5 seconds after last successful refresh.\n if (now - lastRefresh.current < RETRY_INTERVAL_IN_MS && error === undefined) {\n return;\n }\n\n lastRefresh.current = Date.now();\n await queryChannels('refresh');\n };\n\n const reloadList = () => queryChannels('reload');\n\n /**\n * Equality check using stringified filters/sort ensure that we don't make un-necessary queryChannels api calls\n * for the scenario:\n *\n * <ChannelList\n * filters={{\n * members: { $in: ['vishal'] }\n * }}\n * ...\n * />\n *\n * Here we have passed filters as inline object, which means on every re-render of\n * parent component, ChannelList will receive new object reference (even though value is same), which\n * in return will trigger useEffect. To avoid this, we can add a value check.\n */\n const filterStr = useMemo(() => JSON.stringify(filters), [filters]);\n const sortStr = useMemo(() => JSON.stringify(sort), [sort]);\n\n useEffect(() => {\n const loadOfflineChannels = () => {\n if (!client?.user?.id) return;\n\n try {\n const channelsFromDB = getChannelsForFilterSort({\n currentUserId: client.user.id,\n filters,\n sort,\n });\n\n if (channelsFromDB) {\n setChannels(\n client.hydrateActiveChannels(channelsFromDB, {\n offlineMode: true,\n }),\n );\n setStaticChannelsActive(true);\n }\n } catch (e) {\n console.warn('Failed to get channels from database: ', e);\n }\n\n setActiveQueryType(null);\n };\n\n let listener: ReturnType<typeof DBSyncManager.onSyncStatusChange>;\n if (enableOfflineSupport) {\n // Any time DB is synced, we need to update the UI with local DB channels first,\n // and then call queryChannels to ensure any new channels are added to UI.\n listener = DBSyncManager.onSyncStatusChange((syncStatus) => {\n if (syncStatus) {\n loadOfflineChannels();\n reloadList();\n }\n });\n // On start, load the channels from local db.\n loadOfflineChannels();\n\n // If db is already synced (sync api and pending api calls), then\n // right away call queryChannels.\n const dbSyncStatus = DBSyncManager.getSyncStatus();\n if (dbSyncStatus) {\n reloadList();\n }\n } else {\n listener = client.on('connection.changed', async (event) => {\n if (event.online) {\n await refreshList();\n setForceUpdate((u) => u + 1);\n }\n });\n\n reloadList();\n }\n\n return () => listener?.unsubscribe?.();\n }, [filterStr, sortStr]);\n\n return {\n channels,\n error,\n hasNextPage,\n loadingChannels:\n activeQueryType === 'queryLocalDB'\n ? true\n : (activeQueryType === 'reload' || activeQueryType === null) && channels === null,\n loadingNextPage: activeQueryType === 'loadChannels',\n loadNextPage: queryChannels,\n refreshing: activeQueryType === 'refresh',\n refreshList,\n reloadList,\n // Although channels can be null, there is no practical case where channels will be null\n // when setChannels is used. setChannels is only recommended to be used for overriding\n // event handler. Thus instead of adding if check for channels === null, its better to\n // simply reassign types here.\n setChannels,\n staticChannelsActive,\n };\n};\n"],"mappings":";;;;;;;;;;AAAA;AAIA;AAEA;AACA;AAEA;AAEA;AACA;AACA;AAEA,IAAMA,WAAW,GAAG,SAAdA,WAAW,CAAIC,OAAe;EAAA,OAClC,IAAIC,OAAO,CAAC,UAACC,OAAO,EAAK;IACvBC,UAAU,CAACD,OAAO,EAAEF,OAAO,GAAGI,sBAAgB,CAAC;EACjD,CAAC,CAAC;AAAA;AAWJ,IAAMC,eAAe,GAAG;EACtBC,aAAa,EAAE;AACjB,CAAC;AAED,IAAMC,qBAAqB,GAAG,CAAC;AAC/B,IAAMC,oBAAoB,GAAG,IAAI;AAM1B,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAoB,OAQK;EAAA,IALpCC,oBAAoB,QAApBA,oBAAoB;IAAA,oBACpBC,OAAO;IAAPA,OAAO,6BAAG,CAAC,CAAC;IAAA,oBACZC,OAAO;IAAPA,OAAO,6BAAGP,eAAe;IACzBQ,cAAc,QAAdA,cAAc;IAAA,iBACdC,IAAI;IAAJA,IAAI,0BAAG,CAAC,CAAC;EAET,gBAAgC,IAAAC,eAAQ,EAAuC,IAAI,CAAC;IAAA;IAA7EC,QAAQ;IAAEC,WAAW;EAC5B,iBAA0B,IAAAF,eAAQ,EAAoBG,SAAS,CAAC;IAAA;IAAzDC,KAAK;IAAEC,QAAQ;EACtB,iBAAwD,IAAAL,eAAQ,EAAU,KAAK,CAAC;IAAA;IAAzEM,oBAAoB;IAAEC,uBAAuB;EACpD,iBAA8C,IAAAP,eAAQ,EAAmB,cAAc,CAAC;IAAA;IA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AAW;IACXC,UAAU,EAAVA,UAAU;IAKVtD,WAAW,EAAXA,WAAW;IACXI,oBAAoB,EAApBA;EACF,CAAC;AACH,CAAC;AAAC"}
@@ -1 +1 @@
1
- {"version":3,"names":["messageActions","blockUser","copyMessage","deleteMessage","editMessage","error","flagMessage","isMyMessage","isThreadMessage","message","messageReactions","ownCapabilities","pinMessage","quotedReply","retry","threadReply","unpinMessage","undefined","actions","push","quoteMessage","sendReply","updateOwnMessage","updateAnyMessage","text","pinned","banChannelMembers","deleteOwnMessage","deleteAnyMessage"],"sources":["messageActions.ts"],"sourcesContent":["import type { MessageContextValue } from '../../../contexts/messageContext/MessageContext';\nimport type { OwnCapabilitiesContextValue } from '../../../contexts/ownCapabilitiesContext/OwnCapabilitiesContext';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\nimport type { MessageActionType } from '../../MessageOverlay/MessageActionListItem';\n\nexport type MessageActionsParams<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n blockUser: MessageActionType;\n deleteMessage: MessageActionType;\n dismissOverlay: () => void;\n editMessage: MessageActionType;\n error: boolean | Error;\n flagMessage: MessageActionType;\n isThreadMessage: boolean;\n messageReactions: boolean;\n muteUser: MessageActionType;\n ownCapabilities: OwnCapabilitiesContextValue;\n pinMessage: MessageActionType;\n quotedReply: MessageActionType;\n retry: MessageActionType;\n threadReply: MessageActionType;\n unpinMessage: MessageActionType;\n copyMessage?: MessageActionType;\n} & Pick<MessageContextValue<StreamChatGenerics>, 'message' | 'isMyMessage'>;\n\nexport type MessageActionsProp<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = (param: MessageActionsParams<StreamChatGenerics>) => MessageActionType[];\n\nexport const messageActions = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n blockUser,\n copyMessage,\n deleteMessage,\n editMessage,\n error,\n flagMessage,\n isMyMessage,\n isThreadMessage,\n message,\n messageReactions,\n ownCapabilities,\n pinMessage,\n quotedReply,\n retry,\n threadReply,\n unpinMessage,\n}: MessageActionsParams<StreamChatGenerics>) => {\n if (messageReactions) {\n return undefined;\n }\n\n const actions: Array<MessageActionType | null> = [];\n\n if (error && isMyMessage) {\n actions.push(retry);\n }\n\n if (ownCapabilities.quoteMessage && !isThreadMessage && !error) {\n actions.push(quotedReply);\n }\n\n if (ownCapabilities.sendReply && !isThreadMessage && !error) {\n actions.push(threadReply);\n }\n\n if (\n (isMyMessage && ownCapabilities.updateOwnMessage) ||\n (!isMyMessage && ownCapabilities.updateAnyMessage)\n ) {\n actions.push(editMessage);\n }\n\n if (copyMessage !== undefined && message.text && !error) {\n actions.push(copyMessage);\n }\n\n if (!isMyMessage && ownCapabilities.flagMessage) {\n actions.push(flagMessage);\n }\n\n if (ownCapabilities.pinMessage && !message.pinned) {\n actions.push(pinMessage);\n }\n\n if (ownCapabilities.pinMessage && message.pinned) {\n actions.push(unpinMessage);\n }\n\n if (!isMyMessage && ownCapabilities.banChannelMembers) {\n actions.push(blockUser);\n }\n\n if (\n (isMyMessage && ownCapabilities.deleteOwnMessage) ||\n (!isMyMessage && ownCapabilities.deleteAnyMessage)\n ) {\n actions.push(deleteMessage);\n }\n\n return actions;\n};\n"],"mappings":";;;;AA8BO,IAAMA,cAAc,GAAG,SAAjBA,cAAc,OAmBqB;EAAA,IAhB9CC,SAAS,QAATA,SAAS;IACTC,WAAW,QAAXA,WAAW;IACXC,aAAa,QAAbA,aAAa;IACbC,WAAW,QAAXA,WAAW;IACXC,KAAK,QAALA,KAAK;IACLC,WAAW,QAAXA,WAAW;IACXC,WAAW,QAAXA,WAAW;IACXC,eAAe,QAAfA,eAAe;IACfC,OAAO,QAAPA,OAAO;IACPC,gBAAgB,QAAhBA,gBAAgB;IAChBC,eAAe,QAAfA,eAAe;IACfC,UAAU,QAAVA,UAAU;IACVC,WAAW,QAAXA,WAAW;IACXC,KAAK,QAALA,KAAK;IACLC,WAAW,QAAXA,WAAW;I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AACpB,WAAW,IAAII,eAAe,CAACiB,gBAAiB,EAClD;IACAV,OAAO,CAACC,IAAI,CAAChB,aAAa,CAAC;EAC7B;EAEA,OAAOe,OAAO;AAChB,CAAC;AAAC"}
1
+ {"version":3,"names":["messageActions","blockUser","copyMessage","deleteMessage","editMessage","error","flagMessage","isMyMessage","isThreadMessage","message","messageReactions","ownCapabilities","pinMessage","quotedReply","retry","threadReply","unpinMessage","undefined","actions","push","quoteMessage","sendReply","updateOwnMessage","updateAnyMessage","text","pinned","banChannelMembers","deleteOwnMessage","deleteAnyMessage"],"sources":["messageActions.ts"],"sourcesContent":["import type { MessageContextValue } from '../../../contexts/messageContext/MessageContext';\nimport type { OwnCapabilitiesContextValue } from '../../../contexts/ownCapabilitiesContext/OwnCapabilitiesContext';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\nimport type { MessageActionType } from '../../MessageOverlay/MessageActionListItem';\n\nexport type MessageActionsParams<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n blockUser: MessageActionType;\n deleteMessage: MessageActionType;\n dismissOverlay: () => void;\n editMessage: MessageActionType;\n error: boolean | Error;\n flagMessage: MessageActionType;\n isThreadMessage: boolean;\n messageReactions: boolean;\n muteUser: MessageActionType;\n ownCapabilities: OwnCapabilitiesContextValue;\n pinMessage: MessageActionType;\n quotedReply: MessageActionType;\n retry: MessageActionType;\n threadReply: MessageActionType;\n unpinMessage: MessageActionType;\n copyMessage?: MessageActionType;\n} & Pick<MessageContextValue<StreamChatGenerics>, 'message' | 'isMyMessage'>;\n\nexport type MessageActionsProp<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = (param: MessageActionsParams<StreamChatGenerics>) => MessageActionType[];\n\nexport const messageActions = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n blockUser,\n copyMessage,\n deleteMessage,\n editMessage,\n error,\n flagMessage,\n isMyMessage,\n isThreadMessage,\n message,\n messageReactions,\n ownCapabilities,\n pinMessage,\n quotedReply,\n retry,\n threadReply,\n unpinMessage,\n}: MessageActionsParams<StreamChatGenerics>) => {\n if (messageReactions) {\n return undefined;\n }\n\n const actions: Array<MessageActionType> = [];\n\n if (error && isMyMessage) {\n actions.push(retry);\n }\n\n if (ownCapabilities.quoteMessage && !isThreadMessage && !error) {\n actions.push(quotedReply);\n }\n\n if (ownCapabilities.sendReply && !isThreadMessage && !error) {\n actions.push(threadReply);\n }\n\n if (\n (isMyMessage && ownCapabilities.updateOwnMessage) ||\n (!isMyMessage && ownCapabilities.updateAnyMessage)\n ) {\n actions.push(editMessage);\n }\n\n if (copyMessage !== undefined && message.text && !error) {\n actions.push(copyMessage);\n }\n\n if (!isMyMessage && ownCapabilities.flagMessage) {\n actions.push(flagMessage);\n }\n\n if (ownCapabilities.pinMessage && !message.pinned) {\n actions.push(pinMessage);\n }\n\n if (ownCapabilities.pinMessage && message.pinned) {\n actions.push(unpinMessage);\n }\n\n if (!isMyMessage && ownCapabilities.banChannelMembers) {\n actions.push(blockUser);\n }\n\n if (\n (isMyMessage && ownCapabilities.deleteOwnMessage) ||\n (!isMyMessage && ownCapabilities.deleteAnyMessage)\n ) {\n actions.push(deleteMessage);\n }\n\n return actions;\n};\n"],"mappings":";;;;AA8BO,IAAMA,cAAc,GAAG,SAAjBA,cAAc,OAmBqB;EAAA,IAhB9CC,SAAS,QAATA,SAAS;IACTC,WAAW,QAAXA,WAAW;IACXC,aAAa,QAAbA,aAAa;IACbC,WAAW,QAAXA,WAAW;IACXC,KAAK,QAALA,KAAK;IACLC,WAAW,QAAXA,WAAW;IACXC,WAAW,QAAXA,WAAW;IACXC,eAAe,QAAfA,eAAe;IACfC,OAAO,QAAPA,OAAO;IACPC,gBAAgB,QAAhBA,gBAAgB;IAChBC,eAAe,QAAfA,eAAe;IACfC,UAAU,QAAVA,UAAU;IACVC,WAAW,QAAXA,WAAW;IACXC,KAAK,QAALA,KAAK;IACLC,WAAW,QAA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B,IAC/C,CAACpB,WAAW,IAAII,eAAe,CAACiB,gBAAiB,EAClD;IACAV,OAAO,CAACC,IAAI,CAAChB,aAAa,CAAC;EAC7B;EAEA,OAAOe,OAAO;AAChB,CAAC;AAAC"}
@@ -1 +1 @@
1
- {"version":3,"names":["ChannelsContext","React","createContext","DEFAULT_BASE_CONTEXT_VALUE","ChannelsProvider","children","value","useChannelsContext","contextValue","useContext","isTestEnvironment","Error","withChannelsContext","Component","WithChannelsContextComponent","props","channelsContext","displayName","getDisplayName"],"sources":["ChannelsContext.tsx"],"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>[] | null;\n /**\n * Custom indicator to use when channel list is empty\n *\n * Default: [EmptyStateIndicator](https://getstream.io/chat/docs/sdk/reactnative/core-components/channel/#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.io/chat/docs/sdk/reactnative/contexts/channels-context/#footerloadingindicator)\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.io/chat/docs/sdk/reactnative/contexts/channels-context/#headererrorindicator)\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.io/chat/docs/sdk/reactnative/contexts/channels-context/#headernetworkdownindicator)\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.io/chat/docs/sdk/reactnative/contexts/channels-context/#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.io/chat/docs/sdk/reactnative/ui-components/channel-preview-messenger/)\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.io/chat/docs/sdk/reactnative/contexts/channels-context/#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"],"mappings":";;;;;;;AAAA;AAqBA;AAEA;AACA;AAA+D;EAAA;AAAA;AAAA;AA4LxD,IAAMA,eAAe,GAAGC,iBAAK,CAACC,aAAa,CAChDC,mDAA0B,CAC3B;AAAC;AAEK,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAgB;EAAA,IAG3BC,QAAQ,QAARA,QAAQ;IACRC,KAAK,QAALA,KAAK;EAAA,OAIL,gCAAC,eAAe,CAAC,QAAQ;IAAC,KAAK,EAAEA,KAAyC;IAAA;IAAA;MAAA;MAAA;MAAA;IAAA;EAAA,GACvED,QAAQ,CACgB;AAAA,CAC5B;AAAC;AAEK,IAAME,kBAAkB,GAAG,SAArBA,kBAAkB,GAExB;EACL,IAAMC,YAAY,GAAG,IAAAC,iBAAU,EAC7BT,eAAe,CACuC;EAExD,IAAIQ,YAAY,KAAKL,mDAA0B,IAAI,CAAC,IAAAO,oCAAiB,GAAE,EAAE;IACvE,MAAM,IAAIC,KAAK,yOAEd;EACH;EAEA,OAAOH,YAAY;AACrB,CAAC;AAAC;AAMK,IAAMI,mBAAmB,GAAG,SAAtBA,mBAAmB,CAI9BC,SAAiC,EACqC;EACtE,IAAMC,4BAA4B,GAAG,SAA/BA,4BAA4B,CAChCC,KAA8D,EAC3D;IACH,IAAMC,eAAe,GAAGT,kBAAkB,EAAsB;IAEhE,OAAO,gCAAC,SAAS,gCAAMQ,KAAK,EAAYC,eAAe;MAAA;MAAA;QAAA;QAAA;QAAA;MAAA;IAAA,GAAI;EAC7D,CAAC;EACDF,4BAA4B,CAACG,WAAW,2BAAyB,IAAAC,8BAAc,EAACL,SAAS,CAAG;EAC5F,OAAOC,4BAA4B;AACrC,CAAC;AAAC"}
1
+ {"version":3,"names":["ChannelsContext","React","createContext","DEFAULT_BASE_CONTEXT_VALUE","ChannelsProvider","children","value","useChannelsContext","contextValue","useContext","isTestEnvironment","Error","withChannelsContext","Component","WithChannelsContextComponent","props","channelsContext","displayName","getDisplayName"],"sources":["ChannelsContext.tsx"],"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>[] | null;\n /**\n * Custom indicator to use when channel list is empty\n *\n * Default: [EmptyStateIndicator](https://getstream.io/chat/docs/sdk/reactnative/core-components/channel/#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.io/chat/docs/sdk/reactnative/contexts/channels-context/#footerloadingindicator)\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.io/chat/docs/sdk/reactnative/contexts/channels-context/#headererrorindicator)\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.io/chat/docs/sdk/reactnative/contexts/channels-context/#headernetworkdownindicator)\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.io/chat/docs/sdk/reactnative/contexts/channels-context/#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;\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.io/chat/docs/sdk/reactnative/ui-components/channel-preview-messenger/)\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.io/chat/docs/sdk/reactnative/contexts/channels-context/#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"],"mappings":";;;;;;;AAAA;AAqBA;AAEA;AACA;AAA+D;EAAA;AAAA;AAAA;AA4LxD,IAAMA,eAAe,GAAGC,iBAAK,CAACC,aAAa,CAChDC,mDAA0B,CAC3B;AAAC;AAEK,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAgB;EAAA,IAG3BC,QAAQ,QAARA,QAAQ;IACRC,KAAK,QAALA,KAAK;EAAA,OAIL,gCAAC,eAAe,CAAC,QAAQ;IAAC,KAAK,EAAEA,KAAyC;IAAA;IAAA;MAAA;MAAA;MAAA;IAAA;EAAA,GACvED,QAAQ,CACgB;AAAA,CAC5B;AAAC;AAEK,IAAME,kBAAkB,GAAG,SAArBA,kBAAkB,GAExB;EACL,IAAMC,YAAY,GAAG,IAAAC,iBAAU,EAC7BT,eAAe,CACuC;EAExD,IAAIQ,YAAY,KAAKL,mDAA0B,IAAI,CAAC,IAAAO,oCAAiB,GAAE,EAAE;IACvE,MAAM,IAAIC,KAAK,yOAEd;EACH;EAEA,OAAOH,YAAY;AACrB,CAAC;AAAC;AAMK,IAAMI,mBAAmB,GAAG,SAAtBA,mBAAmB,CAI9BC,SAAiC,EACqC;EACtE,IAAMC,4BAA4B,GAAG,SAA/BA,4BAA4B,CAChCC,KAA8D,EAC3D;IACH,IAAMC,eAAe,GAAGT,kBAAkB,EAAsB;IAEhE,OAAO,gCAAC,SAAS,gCAAMQ,KAAK,EAAYC,eAAe;MAAA;MAAA;QAAA;QAAA;QAAA;MAAA;IAAA,GAAI;EAC7D,CAAC;EACDF,4BAA4B,CAACG,WAAW,2BAAyB,IAAAC,8BAAc,EAACL,SAAS,CAAG;EAC5F,OAAOC,4BAA4B;AACrC,CAAC;AAAC"}
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.8.0"
2
+ "version": "5.8.1-beta.2"
3
3
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { ChannelsContextValue } from '../../contexts/channelsContext/ChannelsContext';
3
3
  import type { DefaultStreamChatGenerics } from '../../types/types';
4
- export declare type ChannelListMessengerPropsWithContext<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = Omit<ChannelsContextValue<StreamChatGenerics>, 'hasNextPage' | 'HeaderErrorIndicator' | 'HeaderNetworkDownIndicator' | 'maxUnreadCount' | 'numberOfSkeletons' | 'onSelect' | 'Preview' | 'PreviewTitle' | 'PreviewStatus' | 'PreviewAvatar' | 'previewMessage' | 'Skeleton'>;
4
+ export declare type ChannelListMessengerPropsWithContext<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = Omit<ChannelsContextValue<StreamChatGenerics>, 'HeaderErrorIndicator' | 'HeaderNetworkDownIndicator' | 'maxUnreadCount' | 'numberOfSkeletons' | 'onSelect' | 'Preview' | 'PreviewTitle' | 'PreviewStatus' | 'PreviewAvatar' | 'previewMessage' | 'Skeleton'>;
5
5
  export declare type ChannelListMessengerProps<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = Partial<ChannelListMessengerPropsWithContext<StreamChatGenerics>>;
6
6
  /**
7
7
  * This UI component displays the preview list of channels and handles Channel navigation. It
@@ -1,9 +1,10 @@
1
1
  /// <reference types="react" />
2
- import type { Channel } from 'stream-chat';
2
+ import type { Channel, ChannelFilters } from 'stream-chat';
3
3
  import type { DefaultStreamChatGenerics } from '../../../../types/types';
4
4
  declare type Parameters<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = {
5
5
  lockChannelOrder: boolean;
6
6
  setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>;
7
+ filters?: ChannelFilters<StreamChatGenerics>;
7
8
  };
8
- export declare const useNewMessage: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>({ lockChannelOrder, setChannels, }: Parameters<StreamChatGenerics>) => void;
9
+ export declare const useNewMessage: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>({ filters, lockChannelOrder, setChannels, }: Parameters<StreamChatGenerics>) => void;
9
10
  export {};
@@ -1,9 +1,10 @@
1
1
  /// <reference types="react" />
2
- import type { Channel, Event } from 'stream-chat';
2
+ import type { Channel, ChannelFilters, Event } from 'stream-chat';
3
3
  import type { DefaultStreamChatGenerics } from '../../../../types/types';
4
4
  declare type Parameters<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = {
5
5
  setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>;
6
+ filters?: ChannelFilters<StreamChatGenerics>;
6
7
  onMessageNew?: (setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>, event: Event<StreamChatGenerics>) => void;
7
8
  };
8
- export declare const useNewMessageNotification: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>({ onMessageNew, setChannels, }: Parameters<StreamChatGenerics>) => void;
9
+ export declare const useNewMessageNotification: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>({ filters, onMessageNew, setChannels, }: Parameters<StreamChatGenerics>) => void;
9
10
  export {};
@@ -16,9 +16,9 @@ export declare const usePaginatedChannels: <StreamChatGenerics extends DefaultSt
16
16
  hasNextPage: boolean;
17
17
  loadingChannels: boolean;
18
18
  loadingNextPage: boolean;
19
- loadNextPage: QueryChannels | undefined;
19
+ loadNextPage: QueryChannels;
20
20
  refreshing: boolean;
21
- refreshList: () => Promise<void> | undefined;
21
+ refreshList: () => Promise<void>;
22
22
  reloadList: () => Promise<void>;
23
23
  setChannels: import("react").Dispatch<import("react").SetStateAction<Channel<StreamChatGenerics>[] | null>>;
24
24
  staticChannelsActive: boolean;
@@ -21,4 +21,4 @@ export declare type MessageActionsParams<StreamChatGenerics extends DefaultStrea
21
21
  copyMessage?: MessageActionType;
22
22
  } & Pick<MessageContextValue<StreamChatGenerics>, 'message' | 'isMyMessage'>;
23
23
  export declare type MessageActionsProp<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = (param: MessageActionsParams<StreamChatGenerics>) => MessageActionType[];
24
- export declare const messageActions: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>({ blockUser, copyMessage, deleteMessage, editMessage, error, flagMessage, isMyMessage, isThreadMessage, message, messageReactions, ownCapabilities, pinMessage, quotedReply, retry, threadReply, unpinMessage, }: MessageActionsParams<StreamChatGenerics>) => (MessageActionType | null)[] | undefined;
24
+ export declare const messageActions: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>({ blockUser, copyMessage, deleteMessage, editMessage, error, flagMessage, isMyMessage, isThreadMessage, message, messageReactions, ownCapabilities, pinMessage, quotedReply, retry, threadReply, unpinMessage, }: MessageActionsParams<StreamChatGenerics>) => MessageActionType[] | undefined;
@@ -97,7 +97,7 @@ export declare type ChannelsContextValue<StreamChatGenerics extends DefaultStrea
97
97
  /**
98
98
  * Loads the next page of `channels`, which is present as a required prop
99
99
  */
100
- loadNextPage: QueryChannels | undefined;
100
+ loadNextPage: QueryChannels;
101
101
  /**
102
102
  * Max number to display within notification badge. Default: 255 and it cannot be higher than that for now due to backend limitations
103
103
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stream-chat-react-native-core",
3
3
  "description": "The official React Native and Expo components for Stream Chat, a service for building chat applications",
4
- "version": "5.8.0",
4
+ "version": "5.8.1-beta.2",
5
5
  "author": {
6
6
  "company": "Stream.io Inc",
7
7
  "name": "Stream.io Inc"
@@ -215,8 +215,8 @@ export const ChannelList = <
215
215
  ListHeaderComponent,
216
216
  LoadingErrorIndicator = LoadingErrorIndicatorDefault,
217
217
  LoadingIndicator = ChannelListLoadingIndicator,
218
- // https://github.com/facebook/react-native/blob/a7a7970e543959e9db5281914d5f132beb01db8d/Libraries/Lists/VirtualizedList.js#L466
219
- loadMoreThreshold = 2,
218
+ // https://stackoverflow.com/a/60666252/10826415
219
+ loadMoreThreshold = 0.1,
220
220
  lockChannelOrder = false,
221
221
  maxUnreadCount = 255,
222
222
  numberOfSkeletons = 6,
@@ -297,11 +297,13 @@ export const ChannelList = <
297
297
  });
298
298
 
299
299
  useNewMessage({
300
+ filters,
300
301
  lockChannelOrder,
301
302
  setChannels,
302
303
  });
303
304
 
304
305
  useNewMessageNotification({
306
+ filters,
305
307
  onMessageNew,
306
308
  setChannels,
307
309
  });
@@ -21,7 +21,7 @@ export const ChannelListFooterLoadingIndicator: React.FC = () => {
21
21
 
22
22
  return (
23
23
  <View style={[styles.container, container]} testID='channel-list-footer-loading-indicator'>
24
- <Spinner />
24
+ <Spinner height={20} width={20} />
25
25
  </View>
26
26
  );
27
27
  };
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
2
  // RNGR's FlatList ist currently breaking the pull-to-refresh behaviour on Android
3
3
  // See https://github.com/software-mansion/react-native-gesture-handler/issues/598
4
4
  import { FlatList, RefreshControl, StyleSheet, View } from 'react-native';
@@ -26,7 +26,6 @@ export type ChannelListMessengerPropsWithContext<
26
26
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
27
27
  > = Omit<
28
28
  ChannelsContextValue<StreamChatGenerics>,
29
- | 'hasNextPage'
30
29
  | 'HeaderErrorIndicator'
31
30
  | 'HeaderNetworkDownIndicator'
32
31
  | 'maxUnreadCount'
@@ -84,6 +83,7 @@ const ChannelListMessengerWithContext = <
84
83
  >(
85
84
  props: ChannelListMessengerPropsWithContext<StreamChatGenerics>,
86
85
  ) => {
86
+ const onEndReachedCalledDuringCurrentScrollRef = useRef<boolean>(false);
87
87
  const {
88
88
  additionalFlatListProps,
89
89
  channels,
@@ -91,6 +91,7 @@ const ChannelListMessengerWithContext = <
91
91
  error,
92
92
  FooterLoadingIndicator,
93
93
  forceUpdate,
94
+ hasNextPage,
94
95
  ListHeaderComponent,
95
96
  loadingChannels,
96
97
  LoadingErrorIndicator,
@@ -151,14 +152,12 @@ const ChannelListMessengerWithContext = <
151
152
  }
152
153
 
153
154
  const onEndReached = () => {
154
- if (loadNextPage) {
155
+ if (!onEndReachedCalledDuringCurrentScrollRef.current && hasNextPage) {
155
156
  loadNextPage();
157
+ onEndReachedCalledDuringCurrentScrollRef.current = true;
156
158
  }
157
159
  };
158
160
 
159
- const ListFooterComponent = () =>
160
- channels?.length && ListHeaderComponent ? <ListHeaderComponent /> : null;
161
-
162
161
  if (loadingChannels) {
163
162
  return <LoadingIndicator listType='channel' />;
164
163
  }
@@ -182,9 +181,10 @@ const ChannelListMessengerWithContext = <
182
181
  )
183
182
  }
184
183
  ListFooterComponent={loadingNextPage ? <FooterLoadingIndicator /> : undefined}
185
- ListHeaderComponent={ListFooterComponent}
184
+ ListHeaderComponent={ListHeaderComponent}
186
185
  onEndReached={onEndReached}
187
186
  onEndReachedThreshold={loadMoreThreshold}
187
+ onMomentumScrollBegin={() => (onEndReachedCalledDuringCurrentScrollRef.current = false)}
188
188
  ref={setFlatListRef}
189
189
  refreshControl={<RefreshControl onRefresh={refreshList} refreshing={refreshing} />}
190
190
  renderItem={renderItem}
@@ -219,6 +219,7 @@ export const ChannelListMessenger = <
219
219
  error,
220
220
  FooterLoadingIndicator,
221
221
  forceUpdate,
222
+ hasNextPage,
222
223
  ListHeaderComponent,
223
224
  loadingChannels,
224
225
  LoadingErrorIndicator,
@@ -241,6 +242,7 @@ export const ChannelListMessenger = <
241
242
  error,
242
243
  FooterLoadingIndicator,
243
244
  forceUpdate,
245
+ hasNextPage,
244
246
  ListHeaderComponent,
245
247
  loadingChannels,
246
248
  LoadingErrorIndicator,
@@ -1,6 +1,7 @@
1
1
  import { useEffect } from 'react';
2
2
 
3
- import type { Channel, Event } from 'stream-chat';
3
+ import { isEmpty } from 'lodash';
4
+ import type { Channel, ChannelFilters, Event } from 'stream-chat';
4
5
 
5
6
  import { useChatContext } from '../../../../contexts/chatContext/ChatContext';
6
7
 
@@ -11,11 +12,13 @@ type Parameters<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultSt
11
12
  {
12
13
  lockChannelOrder: boolean;
13
14
  setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>;
15
+ filters?: ChannelFilters<StreamChatGenerics>;
14
16
  };
15
17
 
16
18
  export const useNewMessage = <
17
19
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
18
20
  >({
21
+ filters,
19
22
  lockChannelOrder,
20
23
  setChannels,
21
24
  }: Parameters<StreamChatGenerics>) => {
@@ -26,7 +29,16 @@ export const useNewMessage = <
26
29
  setChannels((channels) => {
27
30
  if (!channels) return channels;
28
31
 
29
- if (!lockChannelOrder && event.cid && event.channel_type && event.channel_id) {
32
+ const areFiltersTypeMatchingToEventChannelType =
33
+ isEmpty(filters) || event.channel_type === filters?.type;
34
+
35
+ if (
36
+ !lockChannelOrder &&
37
+ event.cid &&
38
+ event.channel_type &&
39
+ event.channel_id &&
40
+ areFiltersTypeMatchingToEventChannelType
41
+ ) {
30
42
  const targetChannelIndex = channels.findIndex((c) => c.cid === event.cid);
31
43
 
32
44
  if (targetChannelIndex >= 0) {
@@ -1,8 +1,9 @@
1
1
  import { useEffect } from 'react';
2
2
 
3
+ import { isEmpty } from 'lodash';
3
4
  import uniqBy from 'lodash/uniqBy';
4
5
 
5
- import type { Channel, Event } from 'stream-chat';
6
+ import type { Channel, ChannelFilters, Event } from 'stream-chat';
6
7
 
7
8
  import { useChatContext } from '../../../../contexts/chatContext/ChatContext';
8
9
 
@@ -12,6 +13,7 @@ import { getChannel } from '../../utils';
12
13
  type Parameters<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> =
13
14
  {
14
15
  setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>;
16
+ filters?: ChannelFilters<StreamChatGenerics>;
15
17
  onMessageNew?: (
16
18
  setChannels: React.Dispatch<React.SetStateAction<Channel<StreamChatGenerics>[] | null>>,
17
19
  event: Event<StreamChatGenerics>,
@@ -21,6 +23,7 @@ type Parameters<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultSt
21
23
  export const useNewMessageNotification = <
22
24
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
23
25
  >({
26
+ filters,
24
27
  onMessageNew,
25
28
  setChannels,
26
29
  }: Parameters<StreamChatGenerics>) => {
@@ -31,7 +34,10 @@ export const useNewMessageNotification = <
31
34
  if (typeof onMessageNew === 'function') {
32
35
  onMessageNew(setChannels, event);
33
36
  } else {
34
- if (event.channel?.id && event.channel?.type) {
37
+ const areFiltersTypeMatchingToEventChannelType =
38
+ isEmpty(filters) || event.channel?.type === filters?.type;
39
+
40
+ if (event.channel?.id && event.channel?.type && areFiltersTypeMatchingToEventChannelType) {
35
41
  const channel = await getChannel({
36
42
  client,
37
43
  id: event.channel.id,
@@ -47,19 +47,21 @@ export const usePaginatedChannels = <
47
47
  setForceUpdate,
48
48
  sort = {},
49
49
  }: Parameters<StreamChatGenerics>) => {
50
- const { client } = useChatContext<StreamChatGenerics>();
51
50
  const [channels, setChannels] = useState<Channel<StreamChatGenerics>[] | null>(null);
51
+ const [error, setError] = useState<Error | undefined>(undefined);
52
52
  const [staticChannelsActive, setStaticChannelsActive] = useState<boolean>(false);
53
- const activeChannels = useActiveChannelsRefContext();
54
- const [error, setError] = useState<Error>();
55
- const [hasNextPage, setHasNextPage] = useState(true);
56
- const lastRefresh = useRef(Date.now());
57
- const isQueryingRef = useRef(false);
58
53
  const [activeQueryType, setActiveQueryType] = useState<QueryType | null>('queryLocalDB');
54
+ const [hasNextPage, setHasNextPage] = useState<boolean>(false);
55
+
56
+ const activeChannels = useActiveChannelsRefContext();
59
57
  const isMountedRef = useIsMountedRef();
58
+ const { client } = useChatContext<StreamChatGenerics>();
59
+
60
60
  const filtersRef = useRef<typeof filters | null>(null);
61
61
  const sortRef = useRef<typeof sort | null>(null);
62
62
  const activeRequestId = useRef<number>(0);
63
+ const isQueryingRef = useRef(false);
64
+ const lastRefresh = useRef(Date.now());
63
65
 
64
66
  const queryChannels: QueryChannels = async (
65
67
  queryType: QueryType = 'loadChannels',
@@ -132,7 +134,6 @@ export const usePaginatedChannels = <
132
134
  setChannels(newChannels);
133
135
  setStaticChannelsActive(false);
134
136
  setHasNextPage(channelQueryResponse.length >= newOptions.limit);
135
- setError(undefined);
136
137
  isQueryingRef.current = false;
137
138
  } catch (err: unknown) {
138
139
  isQueryingRef.current = false;
@@ -162,9 +163,7 @@ export const usePaginatedChannels = <
162
163
  setActiveQueryType(null);
163
164
  };
164
165
 
165
- const loadNextPage = hasNextPage ? queryChannels : undefined;
166
-
167
- const refreshList = () => {
166
+ const refreshList = async () => {
168
167
  const now = Date.now();
169
168
  // Only allow pull-to-refresh 5 seconds after last successful refresh.
170
169
  if (now - lastRefresh.current < RETRY_INTERVAL_IN_MS && error === undefined) {
@@ -172,7 +171,7 @@ export const usePaginatedChannels = <
172
171
  }
173
172
 
174
173
  lastRefresh.current = Date.now();
175
- return queryChannels('refresh');
174
+ await queryChannels('refresh');
176
175
  };
177
176
 
178
177
  const reloadList = () => queryChannels('reload');
@@ -263,7 +262,7 @@ export const usePaginatedChannels = <
263
262
  ? true
264
263
  : (activeQueryType === 'reload' || activeQueryType === null) && channels === null,
265
264
  loadingNextPage: activeQueryType === 'loadChannels',
266
- loadNextPage,
265
+ loadNextPage: queryChannels,
267
266
  refreshing: activeQueryType === 'refresh',
268
267
  refreshList,
269
268
  reloadList,
@@ -52,7 +52,7 @@ export const messageActions = <
52
52
  return undefined;
53
53
  }
54
54
 
55
- const actions: Array<MessageActionType | null> = [];
55
+ const actions: Array<MessageActionType> = [];
56
56
 
57
57
  if (error && isMyMessage) {
58
58
  actions.push(retry);
@@ -108,7 +108,7 @@ export type ChannelsContextValue<
108
108
  /**
109
109
  * Loads the next page of `channels`, which is present as a required prop
110
110
  */
111
- loadNextPage: QueryChannels | undefined;
111
+ loadNextPage: QueryChannels;
112
112
  /**
113
113
  * Max number to display within notification badge. Default: 255 and it cannot be higher than that for now due to backend limitations
114
114
  */
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.8.0"
2
+ "version": "5.8.1-beta.2"
3
3
  }