Skip to content

Commit 13d295a

Browse files
authored
feat: add delivery_events channel configuration parameter (#1639)
1 parent 2bc5eef commit 13d295a

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

src/client.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4749,17 +4749,14 @@ export class StreamChat {
47494749
}
47504750

47514751
/**
4752-
* Send the mark delivered event for this user
4752+
* Mark the channels delivered for the given messages and the user
47534753
*
47544754
* @param {MarkDeliveredOptions} data
47554755
* @return {Promise<EventAPIResponse | void>} Description
47564756
*/
47574757
async markChannelsDelivered(data: MarkDeliveredOptions) {
47584758
if (!data?.latest_delivered_messages?.length) return;
4759-
return await this.post<EventAPIResponse>(
4760-
this.baseURL + '/channels/delivered',
4761-
data ?? {},
4762-
);
4759+
return await this.post<EventAPIResponse>(this.baseURL + '/channels/delivered', data);
47634760
}
47644761

47654762
syncDeliveredCandidates(collections: Channel[]) {

src/messageDelivery/MessageDeliveryReporter.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export class MessageDeliveryReporter {
5454
return this.deliveryReportCandidates.size > 0;
5555
}
5656

57+
private static hasPermissionToReportDeliveryFor(collection: Channel | Thread) {
58+
if (isChannel(collection)) return !!collection.getConfig()?.delivery_events;
59+
if (isThread(collection)) return !!collection.channel.getConfig()?.delivery_events;
60+
}
61+
5762
/**
5863
* Build latest_delivered_messages payload from an arbitrary buffer (deliveryReportCandidates / nextDeliveryReportCandidates)
5964
*/
@@ -142,8 +147,7 @@ export class MessageDeliveryReporter {
142147
* @param collection
143148
*/
144149
private trackDeliveredCandidate(collection: Channel | Thread) {
145-
if (isChannel(collection) && !collection.getConfig()?.read_events) return;
146-
if (isThread(collection) && !collection.channel.getConfig()?.read_events) return;
150+
if (!MessageDeliveryReporter.hasPermissionToReportDeliveryFor(collection)) return;
147151
const candidate = this.getNextDeliveryReportCandidate(collection);
148152
if (!candidate?.key) return;
149153
const buffer = this.markDeliveredRequestInFlight

src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export type AppSettingsAPIResponse = APIResponse & {
9595
connect_events?: boolean;
9696
created_at?: string;
9797
custom_events?: boolean;
98+
delivery_events?: boolean;
9899
mark_messages_pending?: boolean;
99100
max_message_length?: number;
100101
message_retention?: string;
@@ -1015,6 +1016,7 @@ export type CreateChannelOptions = {
10151016
connect_events?: boolean;
10161017
connection_id?: string;
10171018
custom_events?: boolean;
1019+
delivery_events?: boolean;
10181020
grants?: Record<string, string[]>;
10191021
mark_messages_pending?: boolean;
10201022
max_message_length?: number;
@@ -1120,6 +1122,7 @@ export type UpdateChannelTypeRequest =
11201122
commands?: CommandVariants[];
11211123
connect_events?: boolean;
11221124
custom_events?: boolean;
1125+
delivery_events?: boolean;
11231126
grants?: Record<string, string[]>;
11241127
mark_messages_pending?: boolean;
11251128
mutes?: boolean;
@@ -1151,6 +1154,7 @@ export type UpdateChannelTypeResponse = {
11511154
connect_events: boolean;
11521155
created_at: string;
11531156
custom_events: boolean;
1157+
delivery_events: boolean;
11541158
duration: string;
11551159
grants: Record<string, string[]>;
11561160
mark_messages_pending: boolean;
@@ -1188,6 +1192,7 @@ export type GetChannelTypeResponse = {
11881192
connect_events: boolean;
11891193
created_at: string;
11901194
custom_events: boolean;
1195+
delivery_events: boolean;
11911196
duration: string;
11921197
grants: Record<string, string[]>;
11931198
mark_messages_pending: boolean;
@@ -2384,6 +2389,7 @@ export type ChannelConfigFields = {
23842389
blocklist_behavior?: ChannelConfigAutomodBehavior;
23852390
connect_events?: boolean;
23862391
custom_events?: boolean;
2392+
delivery_events?: boolean;
23872393
mark_messages_pending?: boolean;
23882394
max_message_length?: number;
23892395
message_retention?: string;

test/unit/messageDelivery/MessageDeliveryReporter.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ describe('MessageDeliveryReporter', () => {
2828
channel.initialized = true;
2929
client.configs[channel.cid] = {
3030
created_at: '',
31-
read_events: true,
31+
delivery_events: true,
32+
read_events: false,
3233
reminders: false,
3334
updated_at: '',
3435
};
@@ -82,7 +83,8 @@ describe('MessageDeliveryReporter', () => {
8283
channels.forEach((ch) => {
8384
client.configs[ch.cid] = {
8485
created_at: '',
85-
read_events: true,
86+
delivery_events: true,
87+
read_events: false,
8688
reminders: false,
8789
updated_at: '',
8890
};
@@ -130,6 +132,7 @@ describe('MessageDeliveryReporter', () => {
130132
it('does nothing when read events are disabled in channel config', async () => {
131133
client.configs[channel.cid] = {
132134
created_at: '',
135+
delivery_events: false,
133136
read_events: false,
134137
reminders: false,
135138
updated_at: '',
@@ -228,14 +231,16 @@ describe('MessageDeliveryReporter', () => {
228231

229232
client.configs[ch1.cid] = {
230233
created_at: '',
231-
read_events: true,
234+
delivery_events: true,
235+
read_events: false,
232236
reminders: false,
233237
updated_at: '',
234238
};
235239

236240
client.configs[ch2.cid] = {
237241
created_at: '',
238-
read_events: true,
242+
delivery_events: true,
243+
read_events: false,
239244
reminders: false,
240245
updated_at: '',
241246
};

0 commit comments

Comments
 (0)