Skip to content

Commit 858610c

Browse files
committed
feat: add preSendMessageRequest
1 parent 47063ca commit 858610c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,20 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
432432
messageData: StreamMessage,
433433
options?: SendMessageOptions,
434434
) => Promise<SendMessageAPIResponse>;
435+
436+
/**
437+
* A method invoked just after the first optimistic update of a new message,
438+
* but before any other HTTP requests happen. Can be used to do extra work
439+
* (such as creating a channel, or editing a message) before the local message
440+
* is sent.
441+
* @param channelId
442+
* @param messageData Message object
443+
*/
444+
preSendMessageRequest?: (options: {
445+
localMessage: LocalMessage;
446+
message: StreamMessage;
447+
options?: SendMessageOptions;
448+
}) => Promise<SendMessageAPIResponse>;
435449
/**
436450
* Overrides the Stream default update message request (Advanced usage only)
437451
* @param channelId
@@ -569,6 +583,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
569583
doFileUploadRequest,
570584
doMarkReadRequest,
571585
doSendMessageRequest,
586+
preSendMessageRequest,
572587
doUpdateMessageRequest,
573588
EmptyStateIndicator = EmptyStateIndicatorDefault,
574589
enableMessageGroupingByUser = true,
@@ -1454,6 +1469,9 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
14541469
{ method: 'upsertMessages' },
14551470
);
14561471

1472+
if (preSendMessageRequest) {
1473+
await preSendMessageRequest({ localMessage, message, options });
1474+
}
14571475
await sendMessageRequest({ localMessage, message, options });
14581476
},
14591477
);

0 commit comments

Comments
 (0)