Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ai-docs/ai-migration-v9-to-v10.md
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,11 @@ Highlights that hit integrator code:
annotation so `client.on('x', cb)` narrows automatically.
- **Method signatures collapsed to single objects** — `channel.sendReaction({ id, reaction, ... })`,
`deleteReaction({ id, type })`, `sendMessage({ message, ... })`, `queryChannels(request)`;
`client.uploadImage_(uri, name, type)` for RN image upload (the object-form `uploadImage` is
web/server-shaped); the `client` constructor is 1–2 args; `client.listeners` is a `Map`;
`client.uploadImage({ file: { uri, name, type } })` for RN image upload — the `file` field takes
a browser `File`/`Blob` or an RN `{ uri, name, type }` descriptor, so the MIME type still has to
be explicit, it just lives on the descriptor now; the same shape applies to `client.uploadFile`
and `channel.uploadFile` / `channel.uploadImage` (which replace `channel.sendFile` /
`sendImage`); the `client` constructor is 1–2 args; `client.listeners` is a `Map`;
`createAbortControllerForNextRequest` moved to `client.api`.
- **Sort is `SortParamRequest[]`** — `{ last_message_at: -1 }` → `[{ field: 'last_message_at', direction: -1 }]`.

Expand Down
25 changes: 11 additions & 14 deletions package/src/hooks/actions/__tests__/useChannelActions.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-underscore-dangle -- the LLC's positional RN image-upload helper is `uploadImage_` */
import React, { PropsWithChildren } from 'react';

import { act, renderHook } from '@testing-library/react-native';
Expand Down Expand Up @@ -58,7 +57,7 @@ const createClient = () => ({
muteUser: jest.fn(),
unblockUser: jest.fn(),
unmuteUser: jest.fn(),
uploadImage_: jest.fn().mockResolvedValue({ file: 'https://cdn.example.com/uploaded.png' }),
uploadImage: jest.fn().mockResolvedValue({ file: 'https://cdn.example.com/uploaded.png' }),
userID: 'current-user-id',
});

Expand Down Expand Up @@ -537,11 +536,9 @@ describe('useChannelActions', () => {
await result.current.updateImage(imageFile);
});

expect(client.uploadImage_).toHaveBeenCalledWith(
'file:///tmp/avatar.png',
'avatar.png',
'image/png',
);
expect(client.uploadImage).toHaveBeenCalledWith({
file: { name: 'avatar.png', type: 'image/png', uri: 'file:///tmp/avatar.png' },
});
expect(channel.updatePartial).toHaveBeenCalledWith({
set: { image: 'https://cdn.example.com/uploaded.png' },
});
Expand All @@ -558,7 +555,7 @@ describe('useChannelActions', () => {
});
});

it('uses doFileUploadRequest instead of client.uploadImage_ when provided', async () => {
it('uses doFileUploadRequest instead of client.uploadImage when provided', async () => {
const client = createClient();
const channel = createChannel(client);
const doFileUploadRequest = jest
Expand All @@ -573,7 +570,7 @@ describe('useChannelActions', () => {
});

expect(doFileUploadRequest).toHaveBeenCalledWith(imageFile);
expect(client.uploadImage_).not.toHaveBeenCalled();
expect(client.uploadImage).not.toHaveBeenCalled();
expect(channel.updatePartial).toHaveBeenCalledWith({
set: { image: 'https://cdn.custom.com/avatar.png' },
});
Expand All @@ -582,7 +579,7 @@ describe('useChannelActions', () => {
it('notifies and skips channel.updatePartial when uploadImage rejects', async () => {
const error = new Error('upload failed');
const client = createClient();
client.uploadImage_.mockRejectedValueOnce(error);
client.uploadImage.mockRejectedValueOnce(error);
const channel = createChannel(client);
const { result } = renderHook(() => useChannelActions(channel), {
wrapper: createWrapper(client),
Expand Down Expand Up @@ -620,7 +617,7 @@ describe('useChannelActions', () => {
await result.current.updateImage(imageFile);
});

expect(client.uploadImage_).toHaveBeenCalledTimes(1);
expect(client.uploadImage).toHaveBeenCalledTimes(1);
expect(client.notifications.add).toHaveBeenCalledWith({
message: 'Failed to update channel image',
options: {
Expand All @@ -646,7 +643,7 @@ describe('useChannelActions', () => {
await result.current.updateImage(null);
});

expect(client.uploadImage_).not.toHaveBeenCalled();
expect(client.uploadImage).not.toHaveBeenCalled();
expect(channel.updatePartial).toHaveBeenCalledWith({ unset: ['image'] });
expect(client.notifications.add).toHaveBeenCalledWith({
message: 'Channel image updated',
Expand Down Expand Up @@ -674,7 +671,7 @@ describe('useChannelActions', () => {
await result.current.updateImage(null);
});

expect(client.uploadImage_).not.toHaveBeenCalled();
expect(client.uploadImage).not.toHaveBeenCalled();
expect(client.notifications.add).toHaveBeenCalledWith({
message: 'Failed to update channel image',
options: {
Expand Down Expand Up @@ -722,7 +719,7 @@ describe('useChannelActions', () => {
});
expect(onSuccess).toHaveBeenCalledTimes(1);

client.uploadImage_.mockRejectedValueOnce(new Error('nope'));
client.uploadImage.mockRejectedValueOnce(new Error('nope'));
await act(async () => {
await result.current.updateImage(imageFile, { onSuccess });
});
Expand Down
5 changes: 3 additions & 2 deletions package/src/hooks/actions/useChannelActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,9 @@ export const useChannelActions = (channel: Channel) => {
} else {
const { file } = doFileUploadRequest
? await doFileUploadRequest(image)
: // eslint-disable-next-line no-underscore-dangle -- LLC's positional RN image-upload helper
await client.uploadImage_(image.uri, image.name, image.type);
: await client.uploadImage({
file: { name: image.name, type: image.type, uri: image.uri },
});
await channel.updatePartial({ set: { image: file } });
}
addNotification({
Expand Down
Loading