Skip to content
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
7 changes: 2 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4749,17 +4749,14 @@ export class StreamChat {
}

/**
* Send the mark delivered event for this user
* Mark the channels delivered for the given messages and the user
*
* @param {MarkDeliveredOptions} data
* @return {Promise<EventAPIResponse | void>} Description
*/
async markChannelsDelivered(data: MarkDeliveredOptions) {
if (!data?.latest_delivered_messages?.length) return;
return await this.post<EventAPIResponse>(
this.baseURL + '/channels/delivered',
data ?? {},
);
return await this.post<EventAPIResponse>(this.baseURL + '/channels/delivered', data);
}

syncDeliveredCandidates(collections: Channel[]) {
Expand Down
8 changes: 6 additions & 2 deletions src/messageDelivery/MessageDeliveryReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export class MessageDeliveryReporter {
return this.deliveryReportCandidates.size > 0;
}

private static hasPermissionToReportDeliveryFor(collection: Channel | Thread) {
if (isChannel(collection)) return !!collection.getConfig()?.delivery_events;
if (isThread(collection)) return !!collection.channel.getConfig()?.delivery_events;
}

/**
* Build latest_delivered_messages payload from an arbitrary buffer (deliveryReportCandidates / nextDeliveryReportCandidates)
*/
Expand Down Expand Up @@ -142,8 +147,7 @@ export class MessageDeliveryReporter {
* @param collection
*/
private trackDeliveredCandidate(collection: Channel | Thread) {
if (isChannel(collection) && !collection.getConfig()?.read_events) return;
if (isThread(collection) && !collection.channel.getConfig()?.read_events) return;
if (!MessageDeliveryReporter.hasPermissionToReportDeliveryFor(collection)) return;
const candidate = this.getNextDeliveryReportCandidate(collection);
if (!candidate?.key) return;
const buffer = this.markDeliveredRequestInFlight
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export type AppSettingsAPIResponse = APIResponse & {
connect_events?: boolean;
created_at?: string;
custom_events?: boolean;
delivery_events?: boolean;
mark_messages_pending?: boolean;
max_message_length?: number;
message_retention?: string;
Expand Down Expand Up @@ -1015,6 +1016,7 @@ export type CreateChannelOptions = {
connect_events?: boolean;
connection_id?: string;
custom_events?: boolean;
delivery_events?: boolean;
grants?: Record<string, string[]>;
mark_messages_pending?: boolean;
max_message_length?: number;
Expand Down Expand Up @@ -1120,6 +1122,7 @@ export type UpdateChannelTypeRequest =
commands?: CommandVariants[];
connect_events?: boolean;
custom_events?: boolean;
delivery_events?: boolean;
grants?: Record<string, string[]>;
mark_messages_pending?: boolean;
mutes?: boolean;
Expand Down Expand Up @@ -1151,6 +1154,7 @@ export type UpdateChannelTypeResponse = {
connect_events: boolean;
created_at: string;
custom_events: boolean;
delivery_events: boolean;
duration: string;
grants: Record<string, string[]>;
mark_messages_pending: boolean;
Expand Down Expand Up @@ -1188,6 +1192,7 @@ export type GetChannelTypeResponse = {
connect_events: boolean;
created_at: string;
custom_events: boolean;
delivery_events: boolean;
duration: string;
grants: Record<string, string[]>;
mark_messages_pending: boolean;
Expand Down Expand Up @@ -2384,6 +2389,7 @@ export type ChannelConfigFields = {
blocklist_behavior?: ChannelConfigAutomodBehavior;
connect_events?: boolean;
custom_events?: boolean;
delivery_events?: boolean;
mark_messages_pending?: boolean;
max_message_length?: number;
message_retention?: string;
Expand Down
13 changes: 9 additions & 4 deletions test/unit/messageDelivery/MessageDeliveryReporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ describe('MessageDeliveryReporter', () => {
channel.initialized = true;
client.configs[channel.cid] = {
created_at: '',
read_events: true,
delivery_events: true,
read_events: false,
reminders: false,
updated_at: '',
};
Expand Down Expand Up @@ -82,7 +83,8 @@ describe('MessageDeliveryReporter', () => {
channels.forEach((ch) => {
client.configs[ch.cid] = {
created_at: '',
read_events: true,
delivery_events: true,
read_events: false,
reminders: false,
updated_at: '',
};
Expand Down Expand Up @@ -130,6 +132,7 @@ describe('MessageDeliveryReporter', () => {
it('does nothing when read events are disabled in channel config', async () => {
client.configs[channel.cid] = {
created_at: '',
delivery_events: false,
read_events: false,
reminders: false,
updated_at: '',
Expand Down Expand Up @@ -228,14 +231,16 @@ describe('MessageDeliveryReporter', () => {

client.configs[ch1.cid] = {
created_at: '',
read_events: true,
delivery_events: true,
read_events: false,
reminders: false,
updated_at: '',
};

client.configs[ch2.cid] = {
created_at: '',
read_events: true,
delivery_events: true,
read_events: false,
reminders: false,
updated_at: '',
};
Expand Down