Skip to content
Merged
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
8 changes: 4 additions & 4 deletions package/src/__tests__/offline-support/optimistic-update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Channel = ChannelRaw as unknown as React.ComponentType<
>;

// Tests reach into internal / private StreamChat + LLC Channel APIs (sync manager, legacy
// `wsConnection`, `_deleteMessage`, `_sendReaction`, `_sendMessage`). Helpers narrow at the
// `wsConnection`, and the HTTP methods a replay calls). Helpers narrow at the
// call sites without sprinkling `any` everywhere.
type TestPendingTask = { id: number; type: string; payload: unknown };
type TestSyncManager = {
Expand Down Expand Up @@ -1218,8 +1218,8 @@ export const OptimisticUpdates = () => {
expect(pendingTasksRows.length).toBe(2);
});

const deleteMessageSpy = jest.spyOn(chatClient, '_deleteMessage').mockImplementation();
const sendReactionSpy = jest.spyOn(channel, '_sendReaction').mockImplementation();
const deleteMessageSpy = jest.spyOn(chatClient, 'deleteMessage').mockImplementation();
const sendReactionSpy = jest.spyOn(chatClient, 'sendReaction').mockImplementation();

act(() => dispatchConnectionChangedEvent(chatClient, true));

Expand Down Expand Up @@ -1279,7 +1279,7 @@ export const OptimisticUpdates = () => {
expect(pendingTasksRows.length).toBe(1);
});

const sendMessageSpy = jest.spyOn(channel, '_sendMessage').mockImplementation();
const sendMessageSpy = jest.spyOn(channel, 'sendMessage').mockImplementation();

act(() => dispatchConnectionChangedEvent(chatClient, true));

Expand Down
4 changes: 2 additions & 2 deletions package/src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
// instantly, then it awaits any attachment uploads still in flight and POSTs — through a
// `sendMessageRequest` registered via `client.config.set(...)`, if any. It throws on failure, which the MessageInput send flow
// catches to surface a notification.
await (threadInstance ?? channel).sendMessageWithLocalUpdate({
await (threadInstance ?? channel).messageOperations.send({
localMessage,
message: messageToSend,
options,
Expand All @@ -710,7 +710,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
const target = threadInstance?.messagePaginator.getItem(localMessage.id)
? threadInstance
: channel;
await target.updateMessageWithLocalUpdate({ localMessage, options });
await target.messageOperations.update({ localMessage, options });
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('useMessageOperations.deleteMessage', () => {
}) as unknown as LocalMessage;

it('removes a failed send locally, without a server delete', async () => {
const serverDelete = jest.spyOn(channel, 'deleteMessageWithLocalUpdate').mockResolvedValue();
const serverDelete = jest.spyOn(channel.messageOperations, 'delete').mockResolvedValue();
const removeItem = jest.spyOn(channel.messagePaginator, 'removeItem');
const { result } = render();

Expand All @@ -54,7 +54,7 @@ describe('useMessageOperations.deleteMessage', () => {
});

it('deletes a message whose edit failed on the server, since the server has it', async () => {
const serverDelete = jest.spyOn(channel, 'deleteMessageWithLocalUpdate').mockResolvedValue();
const serverDelete = jest.spyOn(channel.messageOperations, 'delete').mockResolvedValue();
const { result } = render();

await act(() =>
Expand Down
10 changes: 5 additions & 5 deletions package/src/components/Message/hooks/useMessageOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type MessageOperations = {
/**
* Message operations (delete/remove/retry/react/update) resolved from the channel and — when a
* thread is open — the thread instance. These are thin wrappers over the stream-chat message
* operations engine (`*WithLocalUpdate`, `messagePaginator.ingestItem/removeItem`), which owns the
* operations engine (`messageOperations.*`, `messagePaginator.ingestItem/removeItem`), which owns the
* optimistic lifecycle, offline-DB persistence and paginator ingest. Previously these lived on the
* MessagesContext; they now resolve per-message (mirroring stream-chat-react, which has no shared
* action context) so the operations stay co-located with the LLC state they drive.
Expand Down Expand Up @@ -68,7 +68,7 @@ export const useMessageOperations = (): MessageOperations => {

const retrySendMessage: MessageOperations['retrySendMessage'] = useStableCallback(
async (localMessage) => {
await (threadInstance ?? channel).retrySendMessageWithLocalUpdate({ localMessage });
await (threadInstance ?? channel).messageOperations.retry({ localMessage });
},
);

Expand All @@ -85,7 +85,7 @@ export const useMessageOperations = (): MessageOperations => {
// channel message's reaction into the thread paginator while a (channel-wide) thread is open.
const target = threadInstance?.messagePaginator.getItem(messageId) ? threadInstance : channel;

await target.addReactionWithLocalUpdate({
await target.messageOperations.addReaction({
messageId,
options: { enforce_unique: enforceUniqueReaction },
reaction: { type },
Expand All @@ -101,7 +101,7 @@ export const useMessageOperations = (): MessageOperations => {

const target = threadInstance?.messagePaginator.getItem(messageId) ? threadInstance : channel;

await target.deleteReactionWithLocalUpdate({ messageId, type });
await target.messageOperations.deleteReaction({ messageId, type });
},
);

Expand Down Expand Up @@ -137,7 +137,7 @@ export const useMessageOperations = (): MessageOperations => {
const target = threadInstance?.messagePaginator.getItem(message.id)
? threadInstance
: channel;
await target.deleteMessageWithLocalUpdate({
await target.messageOperations.delete({
localMessage: message,
options,
});
Expand Down
6 changes: 3 additions & 3 deletions package/src/store/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Channel, StreamChat } from 'stream-chat';
import type { StreamChat } from 'stream-chat';

import type { Schema } from './schema';

Expand Down Expand Up @@ -33,15 +33,15 @@ export type PendingTask = {
id?: number;
} & (
| {
payload: Parameters<Channel['sendReaction']>;
payload: Parameters<StreamChat['sendReaction']>;
type: PendingTaskTypes['sendReaction'];
}
| {
payload: Parameters<StreamChat['deleteMessage']>;
type: PendingTaskTypes['deleteMessage'];
}
| {
payload: Parameters<Channel['deleteReaction']>;
payload: Parameters<StreamChat['deleteReaction']>;
type: PendingTaskTypes['deleteReaction'];
}
);
Loading