Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit a0f505f

Browse files
authored
Merge pull request #79 from pubnub/fix/ui-1537
fix(lib): fix infinite scrolling on MessageList not working when limit is set over 25
2 parents 2af4a52 + 84e931e commit a0f505f

File tree

9 files changed

+42
-19
lines changed

9 files changed

+42
-19
lines changed

.pubnub.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
---
22
name: pubnub-react-chat-components
3-
version: v0.14.0
3+
version: v0.15.0
44
scm: github.com/pubnub/react-chat-components
55
schema: 1
66
files:
77
- lib/dist/index.js
88
- lib/dist/index.es.js
99
changelog:
10+
- date: 2022-11-09
11+
version: v0.15.0
12+
changes:
13+
- type: bug
14+
text: "MessageList - infinite scrolling breaks if history limit is set over 25."
1015
- date: 2022-10-18
1116
version: v0.14.0
1217
changes:
@@ -37,12 +42,9 @@ changelog:
3742
version: v0.10.0
3843
changes:
3944
- type: fix
40-
text:
41-
"MessageInput - user metadata not attached to File messages with senderInfo option
42-
enabled."
45+
text: "MessageInput - user metadata not attached to File messages with senderInfo option enabled."
4346
- type: fix
44-
text:
45-
"Channel/MemberList - disable default flex shrinking of some UI elements (e.g. avatars)."
47+
text: "Channel/MemberList - disable default flex shrinking of some UI elements (e.g. avatars)."
4648
- changes:
4749
- text: Channel/MemberList - added option for custom sorting
4850
type: feature

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pubnub/common-chat-components",
3-
"version": "0.14.0",
3+
"version": "0.15.0",
44
"main": "src/index.ts",
55
"license": "MIT",
66
"scripts": {

packages/common/src/message-list/message-list.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
MessageEnvelope,
88
EmojiPickerElementProps,
99
FileAttachment,
10+
ProperFetchMessagesResponse,
1011
} from "../types";
1112
import { usePrevious } from "../helpers";
1213
import {
@@ -29,7 +30,7 @@ export interface MessageRendererProps {
2930

3031
export interface CommonMessageListProps {
3132
children?: ReactNode;
32-
/** Option to fetch past messages from storage and display them on a channel. Set a number from "0" to "100". Defaults to "0" to fetch no messages from storage. */
33+
/** Set this option to a non-zero value to enable fetching messages from the History API. This feature uses the infinite scrolling pattern and takes a maximum value of 25. */
3334
fetchMessages?: number;
3435
/** Option to enable rendering reactions that were added to messages. Make sure to also set up reactionsPicker when this option is enabled. */
3536
enableReactions?: boolean;
@@ -45,7 +46,7 @@ export interface CommonMessageListProps {
4546
bubbleRenderer?: (props: MessageRendererProps) => JSX.Element;
4647
/** Option to provide a custom file renderer to change how images and other files are shown. */
4748
fileRenderer?: (file: FileAttachment) => JSX.Element;
48-
/** Option to render only selected messages. */
49+
/** This option only works when you use either `messageRenderer` or `bubbleRenderer`. It allows you to apply one of the custom renderers only to the messages selected by the filter. */
4950
filter?: (message: MessageEnvelope) => boolean;
5051
}
5152

@@ -131,15 +132,19 @@ export const useMessageListCore = (props: CommonMessageListProps) => {
131132
start: (messages?.[0]?.timetoken as number) || undefined,
132133
includeMessageActions: true,
133134
};
134-
const response = await retry(() => pubnub.fetchMessages(options));
135+
const response = (await retry(() =>
136+
pubnub.fetchMessages(options)
137+
)) as ProperFetchMessagesResponse;
135138
const newMessages = (response?.channels[channel] || []).map((m) =>
136139
m.messageType === 4 ? fetchFileUrl(m) : m
137140
) as MessageEnvelope[];
138141
const allMessages = [...messages, ...newMessages].sort(
139142
(a, b) => (a.timetoken as number) - (b.timetoken as number)
140143
);
141144
setMessages(allMessages);
142-
setPaginationEnd(!allMessages.length || newMessages.length !== props.fetchMessages);
145+
setPaginationEnd(
146+
!response.more && (!allMessages.length || newMessages.length !== props.fetchMessages)
147+
);
143148
} catch (e) {
144149
onError(e);
145150
} finally {

packages/common/src/types.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { UUIDMetadataObject, ChannelMetadataObject, ObjectCustom } from "pubnub";
1+
import {
2+
UUIDMetadataObject,
3+
ChannelMetadataObject,
4+
ObjectCustom,
5+
FetchMessagesResponse,
6+
} from "pubnub";
27

38
export type Themes = "light" | "dark" | "support" | "support-dark" | "event" | "event-dark";
49

@@ -83,3 +88,14 @@ export interface RetryOptions {
8388
timeout: number;
8489
exponentialFactor: number;
8590
}
91+
92+
export interface ProperFetchMessagesResponse extends FetchMessagesResponse {
93+
error: boolean;
94+
error_message: string;
95+
status: number;
96+
more?: {
97+
max: number;
98+
start: string;
99+
url: string;
100+
};
101+
}

packages/react-native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pubnub/react-native-chat-components",
3-
"version": "0.14.0",
3+
"version": "0.15.0",
44
"description": "PubNub Chat Components is a development kit of React Native components that aims to help you to easily build Chat applications using PubNub infrastructure. It removes the complexicity of picking an adequate Chat engine, learning its APIs and dealing with its low-level internals. As the same time it allows you to create apps of various use cases, with different functionalities and customizable looks.",
55
"author": "PubNub <[email protected]>",
66
"main": "dist/index.js",

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pubnub/react-chat-components",
3-
"version": "0.14.0",
3+
"version": "0.15.0",
44
"description": "PubNub Chat Components is a development kit of React components that aims to help you to easily build Chat applications using PubNub infrastructure. It removes the complexicity of picking an adequate Chat engine, learning its APIs and dealing with its low-level internals. As the same time it allows you to create apps of various use cases, with different functionalities and customizable looks.",
55
"author": "PubNub <[email protected]>",
66
"main": "dist/index.js",

packages/react/test/message-list.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("Message List", () => {
3434
render(<MessageList welcomeMessages={message} />);
3535

3636
expect(screen.getByText("Welcome")).toBeVisible();
37-
expect(screen.getByText("11:25 AM")).toBeVisible();
37+
expect(screen.getByText(/11:25/)).toBeVisible();
3838
});
3939

4040
test("renders messages with custom message renderer", async () => {
@@ -52,7 +52,7 @@ describe("Message List", () => {
5252
);
5353

5454
expect(screen.getByText("Custom Welcome")).toBeVisible();
55-
expect(screen.queryByText("11:25 AM")).not.toBeInTheDocument();
55+
expect(screen.queryByText(/11:25/)).not.toBeInTheDocument();
5656
});
5757

5858
test("renders messages with custom bubble renderer", async () => {
@@ -70,7 +70,7 @@ describe("Message List", () => {
7070
);
7171

7272
expect(screen.getByText("Custom Welcome")).toBeVisible();
73-
expect(screen.getByText("11:25 AM")).toBeVisible();
73+
expect(screen.getByText(/11:25/)).toBeVisible();
7474
});
7575

7676
test("renders extra actions", async () => {

samples/react-native/mobile-chat/screens/chat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function ChatScreen(): JSX.Element {
1616
behavior={Platform.OS === "ios" ? "padding" : undefined}
1717
>
1818
<MessageList
19-
fetchMessages={20}
19+
fetchMessages={25}
2020
// extraActionsRenderer={(msg) => <Button title="EA" onPress={() => console.log(msg)} />}
2121
// filter={(msg) => msg.message.text === "3"}
2222
// messageRenderer={(env) => <Text>{env.message.message.text}</Text>}

samples/react/group-chat/src/moderated-chat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export default function ModeratedChat(): JSX.Element {
299299
) : (
300300
<>
301301
<MessageList
302-
fetchMessages={20}
302+
fetchMessages={25}
303303
enableReactions={!isUserMuted}
304304
reactionsPicker={
305305
isUserMuted ? undefined : <Picker data={pickerData} theme={theme} />

0 commit comments

Comments
 (0)