stream-chat-react-native-core 5.4.1-beta.1 → 5.4.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/lib/commonjs/components/MessageList/MessageList.js +59 -40
- package/lib/commonjs/components/MessageList/MessageList.js.map +1 -1
- package/lib/commonjs/components/MessageList/hooks/useMessageList.js +4 -3
- package/lib/commonjs/components/MessageList/hooks/useMessageList.js.map +1 -1
- package/lib/commonjs/mock-builders/generator/message.js +1 -1
- package/lib/commonjs/mock-builders/generator/message.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/MessageList/MessageList.js +59 -40
- package/lib/module/components/MessageList/MessageList.js.map +1 -1
- package/lib/module/components/MessageList/hooks/useMessageList.js +4 -3
- package/lib/module/components/MessageList/hooks/useMessageList.js.map +1 -1
- package/lib/module/mock-builders/generator/message.js +1 -1
- package/lib/module/mock-builders/generator/message.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/MessageList/__tests__/useMessageList.test.d.ts +1 -0
- package/lib/typescript/components/MessageList/hooks/useMessageList.d.ts +0 -1
- package/package.json +1 -1
- package/src/components/MessageList/MessageList.tsx +21 -20
- package/src/components/MessageList/__tests__/useMessageList.test.tsx +67 -0
- package/src/components/MessageList/hooks/useMessageList.ts +4 -7
- package/src/mock-builders/generator/message.js +1 -1
- package/src/version.json +1 -1
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useMessageList = exports.isMessageWithStylesReadByAndDateSeparator = void 0;
|
|
7
7
|
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
|
|
8
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
11
|
|
|
10
12
|
var _ChannelContext = require("../../../contexts/channelContext/ChannelContext");
|
|
@@ -30,8 +32,7 @@ var isMessageWithStylesReadByAndDateSeparator = function isMessageWithStylesRead
|
|
|
30
32
|
exports.isMessageWithStylesReadByAndDateSeparator = isMessageWithStylesReadByAndDateSeparator;
|
|
31
33
|
|
|
32
34
|
var useMessageList = function useMessageList(params) {
|
|
33
|
-
var
|
|
34
|
-
noGroupByUser = params.noGroupByUser,
|
|
35
|
+
var noGroupByUser = params.noGroupByUser,
|
|
35
36
|
threadList = params.threadList;
|
|
36
37
|
|
|
37
38
|
var _useChatContext = (0, _ChatContext.useChatContext)(),
|
|
@@ -93,7 +94,7 @@ var useMessageList = function useMessageList(params) {
|
|
|
93
94
|
readBy: msg.id ? readData[msg.id] || false : false
|
|
94
95
|
});
|
|
95
96
|
});
|
|
96
|
-
return
|
|
97
|
+
return (0, _toConsumableArray2["default"])(messagesWithStylesReadByAndDateSeparator).reverse();
|
|
97
98
|
};
|
|
98
99
|
|
|
99
100
|
exports.useMessageList = useMessageList;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useMessageList.ts"],"names":["isMessageWithStylesReadByAndDateSeparator","message","readBy","undefined","useMessageList","params","
|
|
1
|
+
{"version":3,"sources":["useMessageList.ts"],"names":["isMessageWithStylesReadByAndDateSeparator","message","readBy","undefined","useMessageList","params","noGroupByUser","threadList","client","hideDateSeparators","maxTimeBetweenGroupedMessages","read","deletedMessagesVisibilityType","getMessagesGroupStyles","getGroupStyles","messages","threadMessages","messageList","readList","dateSeparators","userId","userID","messageGroupStyles","readData","messagesWithStylesReadByAndDateSeparator","filter","msg","isMessageTypeDeleted","type","user","id","map","dateSeparator","groupStyles","reverse"],"mappings":";;;;;;;;;;;AAEA;;AAIA;;AACA;;AAIA;;AACA;;AAEA;;AACA;;AACA;;AAyBO,IAAMA,yCAAyC,GAAG,SAA5CA,yCAA4C,CAGvDC,OAHuD;AAAA,SAKtDA,OAAD,CAA0EC,MAA1E,KAAqFC,SAL9B;AAAA,CAAlD;;;;AAOA,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAG5BC,MAH4B,EAIzB;AACH,MAAQC,aAAR,GAAsCD,MAAtC,CAAQC,aAAR;AAAA,MAAuBC,UAAvB,GAAsCF,MAAtC,CAAuBE,UAAvB;;AACA,wBAAmB,kCAAnB;AAAA,MAAQC,MAAR,mBAAQA,MAAR;;AACA,2BACE,wCADF;AAAA,MAAQC,kBAAR,sBAAQA,kBAAR;AAAA,MAA4BC,6BAA5B,sBAA4BA,6BAA5B;AAAA,MAA2DC,IAA3D,sBAA2DA,IAA3D;;AAEA,4BACE,0CADF;AAAA,MAAQC,6BAAR,uBAAQA,6BAAR;AAAA,kDAAuCC,sBAAvC;AAAA,MAAuCA,sBAAvC,sCAAgEC,8BAAhE;;AAEA,8BAAqB,kEAArB;AAAA,MAAQC,QAAR,yBAAQA,QAAR;;AACA,0BAA2B,sCAA3B;AAAA,MAAQC,cAAR,qBAAQA,cAAR;;AAEA,MAAMC,WAAW,GAAGV,UAAU,GAAGS,cAAH,GAAoBD,QAAlD;AACA,MAAMG,QAAqE,GAAGX,UAAU,GACpFJ,SADoF,GAEpFQ,IAFJ;AAIA,MAAMQ,cAAc,GAAG,0CAAsC;AAC3DP,IAAAA,6BAA6B,EAA7BA,6BAD2D;AAE3DH,IAAAA,kBAAkB,EAAlBA,kBAF2D;AAG3DM,IAAAA,QAAQ,EAAEE,WAHiD;AAI3DG,IAAAA,MAAM,EAAEZ,MAAM,CAACa;AAJ4C,GAAtC,CAAvB;AAOA,MAAMC,kBAAkB,GAAGT,sBAAsB,CAAqB;AACpEM,IAAAA,cAAc,EAAdA,cADoE;AAEpEV,IAAAA,kBAAkB,EAAlBA,kBAFoE;AAGpEC,IAAAA,6BAA6B,EAA7BA,6BAHoE;AAIpEK,IAAAA,QAAQ,EAAEE,WAJ0D;AAKpEX,IAAAA,aAAa,EAAbA,aALoE;AAMpEc,IAAAA,MAAM,EAAEZ,MAAM,CAACa;AANqD,GAArB,CAAjD;AASA,MAAME,QAAQ,GAAG,kCAAcf,MAAM,CAACa,MAArB,EAA6BJ,WAA7B,EAA0CC,QAA1C,CAAjB;AAEA,MAAMM,wCAAwC,GAAGP,WAAW,CACzDQ,MAD8C,CACvC,UAACC,GAAD,EAAS;AACf,QAAMC,oBAAoB,GAAGD,GAAG,CAACE,IAAJ,KAAa,SAA1C;;AACA,QAAIhB,6BAA6B,KAAK,QAAtC,EAAgD;AAAA;;AAC9C,aAAO,CAACe,oBAAD,IAAyB,cAAAD,GAAG,CAACG,IAAJ,+BAAUC,EAAV,MAAiBtB,MAAM,CAACa,MAAxD;AACD,KAFD,MAEO,IAAIT,6BAA6B,KAAK,UAAtC,EAAkD;AAAA;;AACvD,aAAO,CAACe,oBAAD,IAAyB,eAAAD,GAAG,CAACG,IAAJ,gCAAUC,EAAV,MAAiBtB,MAAM,CAACa,MAAxD;AACD,KAFM,MAEA,IAAIT,6BAA6B,KAAK,OAAtC,EAA+C;AACpD,aAAO,CAACe,oBAAR;AACD,KAFM,MAEA;AACL,aAAOD,GAAP;AACD;AACF,GAZ8C,EAa9CK,GAb8C,CAa1C,UAACL,GAAD;AAAA,yCACAA,GADA;AAEHM,MAAAA,aAAa,EAAEb,cAAc,CAACO,GAAG,CAACI,EAAL,CAAd,IAA0B3B,SAFtC;AAGH8B,MAAAA,WAAW,EAAEX,kBAAkB,CAACI,GAAG,CAACI,EAAL,CAAlB,IAA8B,CAAC,QAAD,CAHxC;AAIH5B,MAAAA,MAAM,EAAEwB,GAAG,CAACI,EAAJ,GAASP,QAAQ,CAACG,GAAG,CAACI,EAAL,CAAR,IAAoB,KAA7B,GAAqC;AAJ1C;AAAA,GAb0C,CAAjD;AAoBA,SAAO,oCACFN,wCADE,EAELU,OAFK,EAAP;AAGD,CA5DM","sourcesContent":["import type { ChannelState, MessageResponse } from 'stream-chat';\n\nimport {\n ChannelContextValue,\n useChannelContext,\n} from '../../../contexts/channelContext/ChannelContext';\nimport { useChatContext } from '../../../contexts/chatContext/ChatContext';\nimport {\n DeletedMessagesVisibilityType,\n useMessagesContext,\n} from '../../../contexts/messagesContext/MessagesContext';\nimport { usePaginatedMessageListContext } from '../../../contexts/paginatedMessageListContext/PaginatedMessageListContext';\nimport { useThreadContext } from '../../../contexts/threadContext/ThreadContext';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\nimport { getDateSeparators } from '../utils/getDateSeparators';\nimport { getGroupStyles } from '../utils/getGroupStyles';\nimport { getReadStates } from '../utils/getReadStates';\n\nexport type UseMessageListParams = {\n deletedMessagesVisibilityType?: DeletedMessagesVisibilityType;\n noGroupByUser?: boolean;\n threadList?: boolean;\n};\n\nexport type GroupType = string;\n\nexport type MessagesWithStylesReadByAndDateSeparator<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = MessageResponse<StreamChatGenerics> & {\n groupStyles: GroupType[];\n readBy: boolean | number;\n dateSeparator?: Date;\n};\n\nexport type MessageType<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> =\n | ReturnType<ChannelState<StreamChatGenerics>['formatMessage']>\n | MessagesWithStylesReadByAndDateSeparator<StreamChatGenerics>;\n\n// Type guards to check MessageType\nexport const isMessageWithStylesReadByAndDateSeparator = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n message: MessageType<StreamChatGenerics>,\n): message is MessagesWithStylesReadByAndDateSeparator<StreamChatGenerics> =>\n (message as MessagesWithStylesReadByAndDateSeparator<StreamChatGenerics>).readBy !== undefined;\n\nexport const useMessageList = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n params: UseMessageListParams,\n) => {\n const { noGroupByUser, threadList } = params;\n const { client } = useChatContext<StreamChatGenerics>();\n const { hideDateSeparators, maxTimeBetweenGroupedMessages, read } =\n useChannelContext<StreamChatGenerics>();\n const { deletedMessagesVisibilityType, getMessagesGroupStyles = getGroupStyles } =\n useMessagesContext<StreamChatGenerics>();\n const { messages } = usePaginatedMessageListContext<StreamChatGenerics>();\n const { threadMessages } = useThreadContext<StreamChatGenerics>();\n\n const messageList = threadList ? threadMessages : messages;\n const readList: ChannelContextValue<StreamChatGenerics>['read'] | undefined = threadList\n ? undefined\n : read;\n\n const dateSeparators = getDateSeparators<StreamChatGenerics>({\n deletedMessagesVisibilityType,\n hideDateSeparators,\n messages: messageList,\n userId: client.userID,\n });\n\n const messageGroupStyles = getMessagesGroupStyles<StreamChatGenerics>({\n dateSeparators,\n hideDateSeparators,\n maxTimeBetweenGroupedMessages,\n messages: messageList,\n noGroupByUser,\n userId: client.userID,\n });\n\n const readData = getReadStates(client.userID, messageList, readList);\n\n const messagesWithStylesReadByAndDateSeparator = messageList\n .filter((msg) => {\n const isMessageTypeDeleted = msg.type === 'deleted';\n if (deletedMessagesVisibilityType === 'sender') {\n return !isMessageTypeDeleted || msg.user?.id === client.userID;\n } else if (deletedMessagesVisibilityType === 'receiver') {\n return !isMessageTypeDeleted || msg.user?.id !== client.userID;\n } else if (deletedMessagesVisibilityType === 'never') {\n return !isMessageTypeDeleted;\n } else {\n return msg;\n }\n })\n .map((msg) => ({\n ...msg,\n dateSeparator: dateSeparators[msg.id] || undefined,\n groupStyles: messageGroupStyles[msg.id] || ['single'],\n readBy: msg.id ? readData[msg.id] || false : false,\n }));\n\n return [\n ...messagesWithStylesReadByAndDateSeparator,\n ].reverse() as MessageType<StreamChatGenerics>[];\n};\n"]}
|
|
@@ -16,7 +16,7 @@ var generateMessage = function generateMessage() {
|
|
|
16
16
|
var timestamp = options.timestamp || new Date(new Date().getTime() - Math.floor(Math.random() * 100000));
|
|
17
17
|
return (0, _extends2["default"])({
|
|
18
18
|
attachments: [],
|
|
19
|
-
created_at: timestamp
|
|
19
|
+
created_at: timestamp,
|
|
20
20
|
html: '<p>regular</p>',
|
|
21
21
|
id: (0, _uuid.v4)(),
|
|
22
22
|
text: (0, _uuid.v4)(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["message.js"],"names":["generateMessage","options","timestamp","Date","getTime","Math","floor","random","attachments","created_at","
|
|
1
|
+
{"version":3,"sources":["message.js"],"names":["generateMessage","options","timestamp","Date","getTime","Math","floor","random","attachments","created_at","html","id","text","type","updated_at","toString","user","StreamReactNativeNamespace","generateStaticMessage","seed","date"],"mappings":";;;;;;;;;AAAA;;AAEA;;AAEO,IAAMA,eAAe,GAAG,SAAlBA,eAAkB,GAAkB;AAAA,MAAjBC,OAAiB,uEAAP,EAAO;AAC/C,MAAMC,SAAS,GACbD,OAAO,CAACC,SAAR,IAAqB,IAAIC,IAAJ,CAAS,IAAIA,IAAJ,GAAWC,OAAX,KAAuBC,IAAI,CAACC,KAAL,CAAWD,IAAI,CAACE,MAAL,KAAgB,MAA3B,CAAhC,CADvB;AAGA;AACEC,IAAAA,WAAW,EAAE,EADf;AAEEC,IAAAA,UAAU,EAAEP,SAFd;AAGEQ,IAAAA,IAAI,EAAE,gBAHR;AAIEC,IAAAA,EAAE,EAAE,eAJN;AAKEC,IAAAA,IAAI,EAAE,eALR;AAMEC,IAAAA,IAAI,EAAE,SANR;AAOEC,IAAAA,UAAU,EAAEZ,SAAS,CAACa,QAAV,EAPd;AAQEC,IAAAA,IAAI,EAAE;AARR,KASKf,OATL;AAWD,CAfM;;;AAiBP,IAAMgB,0BAA0B,GAAG,sCAAnC;;AACO,IAAMC,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,IAAD,EAAOlB,OAAP,EAAgBmB,IAAhB;AAAA,SACnCpB,eAAe;AACbS,IAAAA,UAAU,EAAEW,IAAI,IAAI,6BADP;AAEbT,IAAAA,EAAE,EAAE,cAAOQ,IAAP,EAAaF,0BAAb,CAFS;AAGbL,IAAAA,IAAI,EAAEO,IAHO;AAIbL,IAAAA,UAAU,EAAEM,IAAI,IAAI;AAJP,KAKVnB,OALU,EADoB;AAAA,CAA9B","sourcesContent":["import { v4 as uuidv4, v5 as uuidv5 } from 'uuid';\n\nimport { generateUser } from './user';\n\nexport const generateMessage = (options = {}) => {\n const timestamp =\n options.timestamp || new Date(new Date().getTime() - Math.floor(Math.random() * 100000));\n\n return {\n attachments: [],\n created_at: timestamp,\n html: '<p>regular</p>',\n id: uuidv4(),\n text: uuidv4(),\n type: 'regular',\n updated_at: timestamp.toString(),\n user: generateUser(),\n ...options,\n };\n};\n\nconst StreamReactNativeNamespace = '9b244ee4-7d69-4d7b-ae23-cf89e9f7b035';\nexport const generateStaticMessage = (seed, options, date) =>\n generateMessage({\n created_at: date || '2020-04-27T13:39:49.331742Z',\n id: uuidv5(seed, StreamReactNativeNamespace),\n text: seed,\n updated_at: date || '2020-04-27T13:39:49.331742Z',\n ...options,\n });\n"]}
|
package/lib/module/version.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -3,7 +3,6 @@ import { DeletedMessagesVisibilityType } from '../../../contexts/messagesContext
|
|
|
3
3
|
import type { DefaultStreamChatGenerics } from '../../../types/types';
|
|
4
4
|
export declare type UseMessageListParams = {
|
|
5
5
|
deletedMessagesVisibilityType?: DeletedMessagesVisibilityType;
|
|
6
|
-
inverted?: boolean;
|
|
7
6
|
noGroupByUser?: boolean;
|
|
8
7
|
threadList?: boolean;
|
|
9
8
|
};
|
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.4.
|
|
4
|
+
"version": "5.4.2-beta.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"company": "Stream.io Inc",
|
|
7
7
|
"name": "Stream.io Inc"
|
|
@@ -92,13 +92,12 @@ const keyExtractor = <
|
|
|
92
92
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
93
93
|
>(
|
|
94
94
|
item: MessageType<StreamChatGenerics>,
|
|
95
|
-
) =>
|
|
96
|
-
item.id
|
|
97
|
-
(item.created_at
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
: Date.now().toString());
|
|
95
|
+
) => {
|
|
96
|
+
if (item.id) return item.id;
|
|
97
|
+
if (item.created_at)
|
|
98
|
+
return typeof item.created_at === 'string' ? item.created_at : item.created_at.toISOString();
|
|
99
|
+
return Date.now().toString();
|
|
100
|
+
};
|
|
102
101
|
|
|
103
102
|
const flatListViewabilityConfig = {
|
|
104
103
|
viewAreaCoveragePercentThreshold: 1,
|
|
@@ -294,7 +293,6 @@ const MessageListWithContext = <
|
|
|
294
293
|
);
|
|
295
294
|
|
|
296
295
|
const messageList = useMessageList<StreamChatGenerics>({
|
|
297
|
-
inverted,
|
|
298
296
|
noGroupByUser,
|
|
299
297
|
threadList,
|
|
300
298
|
});
|
|
@@ -911,12 +909,13 @@ const MessageListWithContext = <
|
|
|
911
909
|
stickyHeaderDate?.getFullYear() === new Date().getFullYear() ? 'MMM D' : 'MMM D, YYYY';
|
|
912
910
|
const tStickyHeaderDate =
|
|
913
911
|
stickyHeaderDate && !hideStickyDateHeader ? tDateTimeParser(stickyHeaderDate) : null;
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
912
|
+
|
|
913
|
+
const stickyHeaderDateString = useMemo(() => {
|
|
914
|
+
if (tStickyHeaderDate === null || hideStickyDateHeader) return null;
|
|
915
|
+
if (isDayOrMoment(tStickyHeaderDate)) return tStickyHeaderDate.format(stickyHeaderFormatDate);
|
|
916
|
+
|
|
917
|
+
return new Date(tStickyHeaderDate).toDateString();
|
|
918
|
+
}, [tStickyHeaderDate, stickyHeaderFormatDate, hideStickyDateHeader]);
|
|
920
919
|
|
|
921
920
|
const dismissImagePicker = () => {
|
|
922
921
|
if (!hasMoved && selectedPicker) {
|
|
@@ -964,6 +963,13 @@ const MessageListWithContext = <
|
|
|
964
963
|
);
|
|
965
964
|
}
|
|
966
965
|
|
|
966
|
+
const StickyHeaderComponent = () => {
|
|
967
|
+
if (!stickyHeaderDateString) return null;
|
|
968
|
+
if (StickyHeader) return <StickyHeader dateString={stickyHeaderDateString} />;
|
|
969
|
+
if (messageListLengthAfterUpdate) return <DateHeader dateString={stickyHeaderDateString} />;
|
|
970
|
+
return null;
|
|
971
|
+
};
|
|
972
|
+
|
|
967
973
|
return (
|
|
968
974
|
<View
|
|
969
975
|
style={[styles.container, { backgroundColor: white_snow }, container]}
|
|
@@ -1002,12 +1008,7 @@ const MessageListWithContext = <
|
|
|
1002
1008
|
{!loading && (
|
|
1003
1009
|
<>
|
|
1004
1010
|
<View style={styles.stickyHeader}>
|
|
1005
|
-
|
|
1006
|
-
(StickyHeader ? (
|
|
1007
|
-
<StickyHeader dateString={stickyHeaderDateToRender} />
|
|
1008
|
-
) : messageListLengthAfterUpdate ? (
|
|
1009
|
-
<DateHeader dateString={stickyHeaderDateToRender} />
|
|
1010
|
-
) : null)}
|
|
1011
|
+
<StickyHeaderComponent />
|
|
1011
1012
|
</View>
|
|
1012
1013
|
{!disableTypingIndicator && TypingIndicator && (
|
|
1013
1014
|
<TypingIndicatorContainer>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
|
|
3
|
+
import { renderHook } from '@testing-library/react-hooks';
|
|
4
|
+
import type { DefaultStreamChatGenerics } from 'src/types/types';
|
|
5
|
+
import type { DefaultGenerics, StreamChat } from 'stream-chat';
|
|
6
|
+
|
|
7
|
+
import { useCreatePaginatedMessageListContext } from '../../../components/Channel/hooks/useCreatePaginatedMessageListContext';
|
|
8
|
+
import {
|
|
9
|
+
ChatContext,
|
|
10
|
+
ChatContextValue,
|
|
11
|
+
PaginatedMessageListContextValue,
|
|
12
|
+
PaginatedMessageListProvider,
|
|
13
|
+
} from '../../../contexts';
|
|
14
|
+
|
|
15
|
+
import { generateMessage } from '../../../mock-builders/generator/message';
|
|
16
|
+
import { generateUser } from '../../../mock-builders/generator/user';
|
|
17
|
+
import { getTestClientWithUser } from '../../../mock-builders/mock';
|
|
18
|
+
import { useMessageList } from '../hooks/useMessageList';
|
|
19
|
+
|
|
20
|
+
jest.mock('react-native-fs', () => ({}));
|
|
21
|
+
|
|
22
|
+
const clientUser = generateUser();
|
|
23
|
+
let chatClient: StreamChat<DefaultGenerics> | StreamChat<DefaultStreamChatGenerics>;
|
|
24
|
+
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
chatClient = await getTestClientWithUser(clientUser);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const messages = new Array(10)
|
|
30
|
+
.fill(undefined)
|
|
31
|
+
.map((_: undefined, id: number) => generateMessage({ id }));
|
|
32
|
+
|
|
33
|
+
const Providers: FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
34
|
+
const messageListContext = useCreatePaginatedMessageListContext({
|
|
35
|
+
messages,
|
|
36
|
+
} as unknown as PaginatedMessageListContextValue);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<ChatContext.Provider
|
|
40
|
+
value={
|
|
41
|
+
{
|
|
42
|
+
auto_translation_enabled: true,
|
|
43
|
+
client: chatClient,
|
|
44
|
+
} as unknown as ChatContextValue
|
|
45
|
+
}
|
|
46
|
+
>
|
|
47
|
+
<PaginatedMessageListProvider value={messageListContext}>
|
|
48
|
+
{children}
|
|
49
|
+
</PaginatedMessageListProvider>
|
|
50
|
+
</ChatContext.Provider>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
describe('useMessageList', () => {
|
|
55
|
+
it('should always return a list of reversed messages', () => {
|
|
56
|
+
const { result } = renderHook(
|
|
57
|
+
() =>
|
|
58
|
+
useMessageList({
|
|
59
|
+
noGroupByUser: true,
|
|
60
|
+
threadList: false,
|
|
61
|
+
}),
|
|
62
|
+
{ wrapper: Providers },
|
|
63
|
+
);
|
|
64
|
+
const reversedMessages = messages.reverse();
|
|
65
|
+
expect(result.current.map(({ id }) => id)).toEqual(reversedMessages.map(({ id }) => id));
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -18,7 +18,6 @@ import { getReadStates } from '../utils/getReadStates';
|
|
|
18
18
|
|
|
19
19
|
export type UseMessageListParams = {
|
|
20
20
|
deletedMessagesVisibilityType?: DeletedMessagesVisibilityType;
|
|
21
|
-
inverted?: boolean;
|
|
22
21
|
noGroupByUser?: boolean;
|
|
23
22
|
threadList?: boolean;
|
|
24
23
|
};
|
|
@@ -52,7 +51,7 @@ export const useMessageList = <
|
|
|
52
51
|
>(
|
|
53
52
|
params: UseMessageListParams,
|
|
54
53
|
) => {
|
|
55
|
-
const {
|
|
54
|
+
const { noGroupByUser, threadList } = params;
|
|
56
55
|
const { client } = useChatContext<StreamChatGenerics>();
|
|
57
56
|
const { hideDateSeparators, maxTimeBetweenGroupedMessages, read } =
|
|
58
57
|
useChannelContext<StreamChatGenerics>();
|
|
@@ -104,9 +103,7 @@ export const useMessageList = <
|
|
|
104
103
|
readBy: msg.id ? readData[msg.id] || false : false,
|
|
105
104
|
}));
|
|
106
105
|
|
|
107
|
-
return
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
: messagesWithStylesReadByAndDateSeparator
|
|
111
|
-
) as MessageType<StreamChatGenerics>[];
|
|
106
|
+
return [
|
|
107
|
+
...messagesWithStylesReadByAndDateSeparator,
|
|
108
|
+
].reverse() as MessageType<StreamChatGenerics>[];
|
|
112
109
|
};
|
package/src/version.json
CHANGED