Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disallow pending message feature on client side #1127

Merged
merged 2 commits into from
May 25, 2023
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
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);
});
});