Skip to content

Commit b32dde9

Browse files
authored
Merge pull request #8 from ably/chat-js-0.11
chore: bump chat-js to 0.11
2 parents a110705 + 5fc99f0 commit b32dde9

File tree

10 files changed

+42
-54
lines changed

10 files changed

+42
-54
lines changed

package-lock.json

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"prepare": "npm run build",
2828
"lint": "eslint 'src/**/*.{ts,tsx}'",
2929
"lint:fix": "eslint 'src/**/*.{ts,tsx}' --fix",
30-
"format": "prettier --write 'src/**/*.{ts,tsx,css}'",
30+
"format": "prettier --list-different --write 'src/**/*.{ts,tsx,css}'",
3131
"format:check": "prettier --check 'src/**/*.{ts,tsx,css}'",
3232
"storybook": "storybook dev -p 6006",
3333
"build-storybook": "storybook build",
@@ -52,7 +52,7 @@
5252
"clsx": "^2.1.1"
5353
},
5454
"peerDependencies": {
55-
"@ably/chat": "^0.10.0",
55+
"@ably/chat": "^0.11.0",
5656
"react": "^18.0.0 || ^19.0.0",
5757
"react-dom": "^18.0.0 || ^19.0.0"
5858
},

src/app/app.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,7 @@ export const App = ({ initialRoomNames, width = '70vw', height = '70vh' }: AppPr
126126
<main className="flex-1 overflow-hidden">
127127
{/* Render the active chat window if a room is selected, otherwise show empty state */}
128128
{activeRoom ? (
129-
<ChatRoomProvider
130-
key={activeRoom}
131-
name={activeRoom}
132-
attach={false}
133-
release={false}
134-
options={DEFAULT_ROOM_OPTIONS}
135-
>
129+
<ChatRoomProvider key={activeRoom} name={activeRoom} options={DEFAULT_ROOM_OPTIONS}>
136130
<ChatWindow
137131
roomName={activeRoom}
138132
customHeaderContent={<RoomInfo />}

src/components/molecules/chat-window.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,7 @@ export const ChatWindow = ({
270270
className,
271271
onError,
272272
}: ChatWindowProps) => {
273-
const {
274-
deleteMessage,
275-
update: updateMessageRemote,
276-
sendReaction,
277-
deleteReaction,
278-
} = useMessages();
273+
const { deleteMessage, updateMessage, sendReaction, deleteReaction } = useMessages();
279274

280275
const {
281276
activeMessages,
@@ -298,7 +293,7 @@ export const ChatWindow = ({
298293
(msg: Message, newText: string) => {
299294
const updated = msg.copy({ text: newText, metadata: msg.metadata, headers: msg.headers });
300295

301-
updateMessageRemote(msg.serial, updated)
296+
updateMessage(msg.serial, updated)
302297
.then(handleRESTMessageUpdate)
303298
.catch((error: unknown) => {
304299
if (onError?.onMessageUpdateError) {
@@ -308,7 +303,7 @@ export const ChatWindow = ({
308303
}
309304
});
310305
},
311-
[updateMessageRemote, handleRESTMessageUpdate, onError]
306+
[updateMessage, handleRESTMessageUpdate, onError]
312307
);
313308

314309
const handleMessageDelete = useCallback(

src/components/molecules/message-input.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ export const MessageInput = ({
144144
const [emojiPickerPosition, setEmojiPickerPosition] = useState({ top: 0, left: 0 });
145145
const inputRef = useRef<HTMLTextAreaElement>(null);
146146
const { keystroke, stop } = useTyping();
147-
const { send } = useMessages();
147+
const { sendMessage } = useMessages();
148148

149149
/**
150150
* Handles sending the message, clearing the input, and stopping typing indicators
151151
*/
152152
const handleSend = useCallback(() => {
153153
const trimmedMessage = messageRef.current.trim();
154154
if (trimmedMessage) {
155-
send({ text: trimmedMessage })
155+
sendMessage({ text: trimmedMessage })
156156
.then((sentMessage) => {
157157
onSent?.(sentMessage);
158158
setMessage('');
@@ -171,7 +171,7 @@ export const MessageInput = ({
171171
}
172172
});
173173
}
174-
}, [send, stop, onSent, onSendError, enableTyping]);
174+
}, [sendMessage, stop, onSent, onSendError, enableTyping]);
175175

176176
/**
177177
* Handles changes to the input field

src/components/molecules/room-reaction.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export const RoomReaction = ({
188188

189189
const throttledHandleIncomingReaction = useThrottle(handleIncomingReaction, 200);
190190

191-
const { send } = useRoomReactions({
191+
const { sendRoomReaction } = useRoomReactions({
192192
listener: throttledHandleIncomingReaction,
193193
});
194194

@@ -219,22 +219,22 @@ export const RoomReaction = ({
219219
*
220220
* @param emoji - The emoji reaction to send to the room
221221
*/
222-
const sendRoomReaction = useCallback(
222+
const sendReactionToRoom = useCallback(
223223
(emoji: string): void => {
224-
send({ name: emoji }).catch((error: unknown) => {
224+
sendRoomReaction({ name: emoji }).catch((error: unknown) => {
225225
if (onError?.onSendRoomReactionError) {
226226
onError.onSendRoomReactionError(error as ErrorInfo, emoji);
227227
} else {
228228
console.error('Failed to send room reaction:', error);
229229
}
230230
});
231231
},
232-
[send, onError]
232+
[sendRoomReaction, onError]
233233
);
234234

235235
// Create throttled version of the send function to avoid excessive network calls
236236
// Limits to maximum 1 reaction per 200ms while preserving immediate visual feedback
237-
const throttledSendReaction = useThrottle(sendRoomReaction, 200);
237+
const throttledSendReaction = useThrottle(sendReactionToRoom, 200);
238238

239239
/**
240240
* Handles sending a room reaction with immediate visual feedback and throttled network call.

src/test/components/molecules/chat-window.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ import { ChatWindowFooterProps } from '../../../components/molecules/chat-window
1212
import { ChatWindowHeaderProps } from '../../../components/molecules/chat-window-header.tsx';
1313
import { MessageInputProps } from '../../../components/molecules/message-input.tsx';
1414

15-
const mockSend = vi.fn().mockResolvedValue({});
15+
const mockSendMessage = vi.fn().mockResolvedValue({});
1616
const mockDeleteMessage = vi.fn().mockResolvedValue({});
17-
const mockUpdate = vi.fn().mockResolvedValue({});
17+
const mockUpdateMessage = vi.fn().mockResolvedValue({});
1818
const mockSendReaction = vi.fn().mockResolvedValue({});
1919
const mockDeleteReaction = vi.fn().mockResolvedValue({});
2020

2121
// Mock the Ably Chat hooks
2222
vi.mock('@ably/chat/react', () => ({
2323
useChatClient: () => ({ clientId: 'test-user' }),
2424
useMessages: (): Partial<UseMessagesResponse> => ({
25-
send: mockSend,
25+
sendMessage: mockSendMessage,
2626
deleteMessage: mockDeleteMessage,
27-
update: mockUpdate,
27+
updateMessage: mockUpdateMessage,
2828
sendReaction: mockSendReaction,
2929
deleteReaction: mockDeleteReaction,
3030
}),
@@ -283,7 +283,7 @@ describe('ChatWindow', () => {
283283
fireEvent.click(screen.getByTestId('edit-message-button'));
284284

285285
// Check if the update function was called
286-
expect(mockUpdate).toHaveBeenCalled();
286+
expect(mockUpdateMessage).toHaveBeenCalled();
287287
});
288288

289289
it('deletes a message when delete button is clicked', () => {
@@ -352,7 +352,7 @@ describe('ChatWindow', () => {
352352

353353
describe('Error Handling', () => {
354354
it('calls onMessageUpdateError when message editing fails', async () => {
355-
mockUpdate.mockRejectedValueOnce(new ErrorInfo('Edit failed', 50000, 500));
355+
mockUpdateMessage.mockRejectedValueOnce(new ErrorInfo('Edit failed', 50000, 500));
356356

357357
let errorInfo: ErrorInfo | undefined;
358358

@@ -461,7 +461,7 @@ describe('ChatWindow', () => {
461461

462462
it('falls back to console.error when no error handlers are provided', async () => {
463463
const consoleSpy = vi.spyOn(console, 'error');
464-
mockUpdate.mockRejectedValueOnce(new Error('Edit failed'));
464+
mockUpdateMessage.mockRejectedValueOnce(new Error('Edit failed'));
465465

466466
render(<ChatWindow roomName="general" />);
467467

src/test/components/molecules/message-input.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { EmojiPickerProps } from '../../../components/molecules/emoji-picker.tsx
1010
import { MessageInput } from '../../../components/molecules/message-input.tsx';
1111

1212
// Mocks the useTyping hook
13-
const mockSend = vi.fn().mockResolvedValue({});
13+
const mockSendMessage = vi.fn().mockResolvedValue({});
1414
const mockDeleteMessage = vi.fn().mockResolvedValue({});
15-
const mockUpdate = vi.fn().mockResolvedValue({});
15+
const mockUpdateMessage = vi.fn().mockResolvedValue({});
1616
const mockSendReaction = vi.fn().mockResolvedValue({});
1717
const mockDeleteReaction = vi.fn().mockResolvedValue({});
1818

@@ -22,9 +22,9 @@ vi.mock('@ably/chat/react', () => ({
2222
stop: vi.fn().mockReturnValue(Promise.resolve()),
2323
}),
2424
useMessages: (): Partial<UseMessagesResponse> => ({
25-
send: mockSend,
25+
sendMessage: mockSendMessage,
2626
deleteMessage: mockDeleteMessage,
27-
update: mockUpdate,
27+
updateMessage: mockUpdateMessage,
2828
sendReaction: mockSendReaction,
2929
deleteReaction: mockDeleteReaction,
3030
}),
@@ -185,7 +185,7 @@ describe('MessageInput', () => {
185185
fireEvent.keyDown(input, { key: 'Enter' });
186186

187187
await waitFor(() => {
188-
expect(mockSend).toHaveBeenCalledWith({ text: 'Hello, world!' });
188+
expect(mockSendMessage).toHaveBeenCalledWith({ text: 'Hello, world!' });
189189
expect(input).toHaveValue('');
190190
});
191191
});

src/test/components/molecules/room-reaction.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ vi.mock('@ably/chat/react', () => ({
1313
useRoomReactions: vi.fn().mockReturnValue({
1414
roomStatus: RoomStatus.Attached,
1515
connectionStatus: ConnectionStatus.Connected,
16-
send: vi.fn().mockResolvedValue({}),
16+
sendRoomReaction: vi.fn().mockResolvedValue({}),
1717
} as Partial<UseRoomReactionsResponse>),
1818
}));
1919

@@ -99,7 +99,7 @@ Object.defineProperty(navigator, 'vibrate', {
9999
});
100100

101101
describe('RoomReaction', () => {
102-
const mockSend = vi.fn().mockResolvedValue({});
102+
const mockSendRoomReaction = vi.fn().mockResolvedValue({});
103103

104104
beforeEach(() => {
105105
vi.clearAllMocks();
@@ -133,15 +133,15 @@ describe('RoomReaction', () => {
133133
(useRoomReactions as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
134134
roomStatus: RoomStatus.Attached,
135135
connectionStatus: ConnectionStatus.Connected,
136-
send: mockSend,
136+
sendRoomReaction: mockSendRoomReaction,
137137
});
138138

139139
render(<RoomReaction />);
140140

141141
// Click the reaction button
142142
fireEvent.click(screen.getByRole('button'));
143143

144-
expect(mockSend).toHaveBeenCalledWith({ name: '👍' });
144+
expect(mockSendRoomReaction).toHaveBeenCalledWith({ name: '👍' });
145145

146146
// Check if emoji burst is shown
147147
expect(screen.getByTestId('emoji-burst')).toBeInTheDocument();
@@ -188,7 +188,7 @@ describe('RoomReaction', () => {
188188
(useRoomReactions as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
189189
roomStatus: RoomStatus.Attached,
190190
connectionStatus: ConnectionStatus.Connected,
191-
send: mockSend,
191+
sendRoomReaction: mockSendRoomReaction,
192192
});
193193

194194
render(<RoomReaction />);
@@ -206,7 +206,7 @@ describe('RoomReaction', () => {
206206
expect(screen.queryByTestId('emoji-wheel')).not.toBeInTheDocument();
207207

208208
// Check if the selected emoji was sent
209-
expect(mockSend).toHaveBeenCalledWith({ name: '❤️' });
209+
expect(mockSendRoomReaction).toHaveBeenCalledWith({ name: '❤️' });
210210

211211
// Check if emoji burst is shown with the selected emoji
212212
expect(screen.getByTestId('emoji-burst')).toBeInTheDocument();
@@ -279,7 +279,7 @@ describe('RoomReaction', () => {
279279
return {
280280
roomStatus: RoomStatus.Attached,
281281
connectionStatus: ConnectionStatus.Connected,
282-
send: mockSend,
282+
sendRoomReaction: mockSendRoomReaction,
283283
};
284284
}
285285
);
@@ -322,7 +322,7 @@ describe('RoomReaction', () => {
322322
return {
323323
roomStatus: RoomStatus.Attached,
324324
connectionStatus: ConnectionStatus.Connected,
325-
send: mockSend,
325+
sendRoomReaction: mockSendRoomReaction,
326326
};
327327
}
328328
);
@@ -436,7 +436,7 @@ describe('RoomReaction', () => {
436436
(useRoomReactions as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
437437
roomStatus: RoomStatus.Attached,
438438
connectionStatus: ConnectionStatus.Connected,
439-
send: mockSendFailure,
439+
sendRoomReaction: mockSendFailure,
440440
});
441441

442442
render(<RoomReaction onError={{ onSendRoomReactionError: mockOnSendRoomReactionError }} />);
@@ -462,7 +462,7 @@ describe('RoomReaction', () => {
462462
(useRoomReactions as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
463463
roomStatus: RoomStatus.Attached,
464464
connectionStatus: ConnectionStatus.Connected,
465-
send: mockSendFailure,
465+
sendRoomReaction: mockSendFailure,
466466
});
467467

468468
render(<RoomReaction />);

src/test/hooks/use-message-window.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ const createMockPaginatedResult = (
116116
const createMockUseMessagesResponse = (
117117
overrides: Partial<UseMessagesResponse> = {}
118118
): UseMessagesResponse => ({
119-
send: vi.fn(),
120-
update: vi.fn(),
119+
sendMessage: vi.fn(),
120+
updateMessage: vi.fn(),
121121
history: vi.fn(),
122122
deleteMessage: vi.fn(),
123123
sendReaction: vi.fn(),

0 commit comments

Comments
 (0)