Skip to content

Commit

Permalink
feat: added 'pending' property to message (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede authored Jul 3, 2023
1 parent 4611742 commit 6209380
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 37 deletions.
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()) {
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', () => {
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 6209380

Please sign in to comment.