Skip to content

Commit

Permalink
fix: disallow pending message feature on client side (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede authored May 25, 2023
1 parent 311c38d commit 7b60e47
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
skip_push?: boolean;
},
) {
if (options?.is_pending_message !== undefined && !this._client._isUsingServerAuth()) {
throw new Error('Setting is_pending_message on client side is not supported');
}

const sendMessageResponse = await this.getClient().post<SendMessageAPIResponse<StreamChatGenerics>>(
this._channelURL() + '/message',
{
Expand Down
32 changes: 32 additions & 0 deletions test/unit/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,3 +758,35 @@ describe('Channel _initializeState', () => {
expect(Object.keys(channel.state.members)).deep.to.be.equal(['alice']);
});
});

describe('pending message', () => {
it('should not allow setting is_pending_message from client side', async () => {
const client = await getClientWithUser();
const channel = client.channel('messaging', uuidv4());
try {
await channel.sendMessage(
{ text: 'hi' },
{
is_pending_message: true,
},
);
} catch (e) {
expect(e.message).to.be.equal('Setting is_pending_message on client side is not supported');
}

const serverClient = new StreamChat('apiKey', 'secret');
serverClient.post = () =>
new Promise((resolve) => {
resolve(true);
});
const serverChannel = serverClient.channel('messaging', uuidv4());
const response = await serverChannel.sendMessage(
{ text: 'hi' },
{
is_pending_message: true,
},
);

expect(response).to.be.equal(true);
});
});

0 comments on commit 7b60e47

Please sign in to comment.