Skip to content

Commit c75be29

Browse files
committed
override doSendMessageRequest
1 parent 9f57d44 commit c75be29

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/components/Channel.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ const Channel = withChatContext(
7575
* Available built-in component (also accepts the same props as): [Attachment](https://getstream.github.io/stream-chat-react-native/#attachment)
7676
* */
7777
Attachment: PropTypes.oneOfType([PropTypes.node, PropTypes.elementType]),
78+
/**
79+
* Override send message request (Advanced usage only)
80+
* */
81+
doSendMessageRequest: PropTypes.func,
7882
};
7983

8084
static defaultProps = {

src/components/ChannelInner.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ export class ChannelInner extends PureComponent {
124124
isOnline: PropTypes.bool,
125125
Message: PropTypes.oneOfType([PropTypes.node, PropTypes.elementType]),
126126
Attachment: PropTypes.oneOfType([PropTypes.node, PropTypes.elementType]),
127+
/** Override send message request (Advanced usage only) */
128+
doSendMessageRequest: PropTypes.func,
127129
};
128130

129131
static defaultProps = {
@@ -380,7 +382,16 @@ export class ChannelInner extends PureComponent {
380382
};
381383

382384
try {
383-
const messageResponse = await this.props.channel.sendMessage(messageData);
385+
let messageResponse;
386+
if (this.props.doSendMessageRequest) {
387+
messageResponse = await this.props.doSendMessageRequest(
388+
this.props.channel.cid,
389+
messageData,
390+
);
391+
} else {
392+
messageResponse = await this.props.channel.sendMessage(messageData);
393+
}
394+
384395
// replace it after send is completed
385396
if (messageResponse.message) {
386397
messageResponse.message.status = 'received';

types/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ export interface ChannelProps extends ChatContextValue {
141141
EmptyStateIndicator?: React.ElementType<EmptyStateIndicatorProps>;
142142
Message?: React.ElementType<MessageUIComponentProps>;
143143
Attachment?: React.ElementType<AttachmentProps>;
144+
/** Function that overrides default sendMessage if chat client */
145+
doSendMessageRequest?(
146+
channelId: string,
147+
message: Client.Message,
148+
): void | Promise<Client.MessageResponse>;
144149
}
145150

146151
export type listType = 'channel' | 'message' | 'default';

0 commit comments

Comments
 (0)