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

feat: added 'pending' property to message #1137

Merged
merged 1 commit into from
Jul 3, 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
8 changes: 3 additions & 5 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
* @param {Message<StreamChatGenerics>} message The Message object
* @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
* @param {boolean} [options.skip_push] Skip sending push notifications
* @param {boolean} [options.is_pending_message] Make this message pending
* @param {boolean} [options.is_pending_message] DEPRECATED, please use `pending` instead.
* @param {boolean} [options.pending] Make this message pending
* @param {Record<string,string>} [options.pending_message_metadata] Metadata for the pending message
* @param {boolean} [options.force_moderation] Apply force moderation for server-side requests
*
Expand All @@ -173,15 +174,12 @@ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGene
force_moderation?: boolean;
is_pending_message?: boolean;
keep_channel_hidden?: boolean;
pending?: boolean;
pending_message_metadata?: Record<string, string>;
skip_enrich_url?: boolean;
skip_push?: boolean;
},
) {
if (options?.is_pending_message !== undefined && !this._client._isUsingServerAuth()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check has been moved to backend.

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
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type AppSettingsAPIResponse<StreamChatGenerics extends ExtendableGenerics
connect_events?: boolean;
created_at?: string;
custom_events?: boolean;
mark_messages_pending?: boolean;
max_message_length?: number;
message_retention?: string;
mutes?: boolean;
Expand Down Expand Up @@ -778,6 +779,7 @@ export type CreateChannelOptions<StreamChatGenerics extends ExtendableGenerics =
connection_id?: string;
custom_events?: boolean;
grants?: Record<string, string[]>;
mark_messages_pending?: boolean;
max_message_length?: number;
message_retention?: string;
mutes?: boolean;
Expand Down Expand Up @@ -1687,6 +1689,7 @@ export type ChannelConfigFields = {
blocklist_behavior?: ChannelConfigAutomodBehavior;
connect_events?: boolean;
custom_events?: boolean;
mark_messages_pending?: boolean;
max_message_length?: number;
message_retention?: string;
mutes?: boolean;
Expand Down
32 changes: 0 additions & 32 deletions test/unit/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,35 +844,3 @@ describe('Channel _initializeState', () => {
expect(Object.keys(channel.state.members)).deep.to.be.equal(['alice']);
});
});

describe('pending message', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unit test didn't make sense anymore since entire credential check has been moved to backend.

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);
});
});