Skip to content

Commit 299d07c

Browse files
Initial commit
1 parent ae79c3e commit 299d07c

5 files changed

Lines changed: 20 additions & 63 deletions

File tree

src/channel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ import type {
2929
CreateDraftResponse,
3030
DeleteMessageOptions,
3131
Event,
32-
EventAPIResponse,
3332
EventHandler,
3433
EventPayload,
3534
EventType,
3635
GetRepliesAPIResponse,
3736
GetRepliesRequest,
3837
LocalMessage,
3938
MarkReadRequest,
39+
MarkReadResponseEvent,
4040
MarkUnreadRequest,
4141
MessagePaginationOptions,
4242
MessageRequest,
@@ -130,7 +130,7 @@ export type CustomDeleteMessageRequestFn = (
130130
export type CustomMarkReadRequestFn = (params: {
131131
channel: Channel;
132132
options?: MarkReadRequest;
133-
}) => Promise<EventAPIResponse | null>;
133+
}) => Promise<{ event: MarkReadResponseEvent } | null>;
134134

135135
export type ChannelInstanceConfig = {
136136
requestHandlers?: {

src/messageDelivery/MessageDeliveryReporter.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ import { Channel } from '../channel';
33
import type { ThreadUserReadState } from '../thread';
44
import { Thread } from '../thread';
55
import type {
6-
EventAPIResponse,
76
LocalMessage,
87
MarkDeliveredRequest,
98
MarkReadRequest,
9+
MarkReadResponse,
1010
StreamAPIError,
1111
StreamResponse,
1212
} from '../types';
1313
import { throttle, userHasReadReceipts } from '../utils';
1414
import { isAPIError, isErrorRetryable } from '../errors';
15-
import type { MarkReadResponse as Gen_MarkReadResponse } from '../gen/models';
1615

1716
const MAX_DELIVERED_MESSAGE_COUNT_IN_PAYLOAD = 100 as const;
1817
const MARK_AS_DELIVERED_BUFFER_TIMEOUT = 1000 as const;
@@ -306,30 +305,20 @@ export class MessageDeliveryReporter {
306305
? { ...options, thread_id: collection.id }
307306
: options;
308307

309-
let result: EventAPIResponse | StreamResponse<Gen_MarkReadResponse> | null = null;
308+
let result: Partial<StreamResponse<MarkReadResponse>> | null = null;
310309

311310
if (isThreadCollection) {
312-
const markReadRequestHandler = collection.configState.getLatestValue()
313-
.requestHandlers?.markReadRequest as
314-
| ((params: {
315-
thread: Thread;
316-
options?: MarkReadRequest;
317-
}) => Promise<EventAPIResponse | null> | void)
318-
| undefined;
311+
const markReadRequestHandler =
312+
collection.configState.getLatestValue().requestHandlers?.markReadRequest;
319313
result = markReadRequestHandler
320314
? ((await markReadRequestHandler({
321315
options: requestOptions,
322316
thread: collection,
323317
})) ?? null)
324318
: await channel.markRead(requestOptions);
325319
} else {
326-
const markReadRequestHandler = channel.configState.getLatestValue().requestHandlers
327-
?.markReadRequest as
328-
| ((params: {
329-
channel: Channel;
330-
options?: MarkReadRequest;
331-
}) => Promise<EventAPIResponse | null> | void)
332-
| undefined;
320+
const markReadRequestHandler =
321+
channel.configState.getLatestValue().requestHandlers?.markReadRequest;
333322
result = markReadRequestHandler
334323
? ((await markReadRequestHandler({ channel, options: requestOptions })) ?? null)
335324
: await channel.markRead(requestOptions);

src/thread.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { StateStore } from './store';
22
import { formatMessage, localMessageToNewMessagePayload } from './utils';
33
import type {
44
DraftResponse,
5-
EventAPIResponse,
65
EventType,
76
LocalMessage,
87
MarkReadRequest,
8+
MarkReadResponseEvent,
99
MessageResponse,
1010
ReadStateResponse,
1111
SortParamRequest,
@@ -67,7 +67,7 @@ const DEFAULT_ITEM_ORDER: SortParamRequest[] = [{ field: 'created_at', direction
6767
export type CustomThreadMarkReadRequestFn = (params: {
6868
thread: Thread;
6969
options?: MarkReadRequest;
70-
}) => Promise<EventAPIResponse | null> | void;
70+
}) => Promise<{ event: MarkReadResponseEvent } | null> | void;
7171

7272
export type ThreadInstanceConfig = {
7373
requestHandlers?: {
@@ -131,7 +131,7 @@ export class Thread extends WithSubscriptions {
131131
participants: threadData.thread_participants,
132132
read: formatReadState(
133133
!threadData.read || threadData.read.length === 0
134-
? getPlaceholderReadResponse(client.userID)
134+
? getPlaceholderReadResponse(client.userId)
135135
: threadData.read,
136136
),
137137
// Use the parent message's reply_count, not the top-level threadData.reply_count. The
@@ -172,7 +172,7 @@ export class Thread extends WithSubscriptions {
172172
isStateStale: false,
173173
parentMessage: formattedParentMessage,
174174
participants: [],
175-
read: formatReadState(getPlaceholderReadResponse(client.userID)),
175+
read: formatReadState(getPlaceholderReadResponse(client.userId)),
176176
replyCount: parentMessage.reply_count ?? 0,
177177
title: '',
178178
updatedAt: parentMessage.updated_at ? new Date(parentMessage.updated_at) : null,
@@ -294,7 +294,7 @@ export class Thread extends WithSubscriptions {
294294
}
295295

296296
get ownUnreadCount() {
297-
return ownUnreadCountSelector(this.client.userID)(this.state.getLatestValue());
297+
return ownUnreadCountSelector(this.client.userId)(this.state.getLatestValue());
298298
}
299299

300300
public activate = () => {
@@ -411,7 +411,7 @@ export class Thread extends WithSubscriptions {
411411
this.state.subscribeWithSelector(
412412
(nextValue) => ({
413413
active: nextValue.active,
414-
unreadMessageCount: ownUnreadCountSelector(this.client.userID)(nextValue),
414+
unreadMessageCount: ownUnreadCountSelector(this.client.userId)(nextValue),
415415
}),
416416
({ active, unreadMessageCount }) => {
417417
if (!active || !unreadMessageCount) return;
@@ -434,8 +434,8 @@ export class Thread extends WithSubscriptions {
434434
const { channel } = this.state.getLatestValue();
435435

436436
if (
437-
!this.client.userID ||
438-
this.client.userID !== event.user?.id ||
437+
!this.client.userId ||
438+
this.client.userId !== event.user?.id ||
439439
event.channel?.cid !== channel.cid
440440
) {
441441
return;
@@ -473,11 +473,11 @@ export class Thread extends WithSubscriptions {
473473

474474
private subscribeNewReplies = () =>
475475
this.client.on('message.new', (event) => {
476-
if (!this.client.userID || event.message?.parent_id !== this.id) {
476+
if (!this.client.userId || event.message?.parent_id !== this.id) {
477477
return;
478478
}
479479

480-
const isOwnMessage = event.message.user?.id === this.client.userID;
480+
const isOwnMessage = event.message.user?.id === this.client.userId;
481481
const { active, read } = this.state.getLatestValue();
482482

483483
this.upsertReplyLocally({
@@ -508,7 +508,7 @@ export class Thread extends WithSubscriptions {
508508
user: event.user,
509509
unreadMessageCount: 0,
510510
};
511-
} else if (active && userId === this.client.userID) {
511+
} else if (active && userId === this.client.userId) {
512512
// Do not increment unread count for the current user in an active thread
513513
} else {
514514
// Increment unread count for all users except the author of the new message

src/types.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,35 +1119,3 @@ export type GiphyVersions = keyof Images;
11191119
export type TranslationLanguage = TranslateMessageRequest['language'];
11201120

11211121
export * from './gen/models';
1122-
1123-
export type EventAPIResponse = APIResponse & {
1124-
event: Event;
1125-
};
1126-
1127-
export type PartializeKeys<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
1128-
1129-
type ErrorResponseDetails = {
1130-
code: number;
1131-
messages: string[];
1132-
};
1133-
1134-
export type APIErrorResponse = {
1135-
duration: string;
1136-
message: string;
1137-
more_info: string;
1138-
StatusCode: number;
1139-
code?: number;
1140-
details?: ErrorResponseDetails;
1141-
};
1142-
1143-
export type DraftMessagePayload = PartializeKeys<
1144-
Omit<DraftMessage, 'mentioned_groups'>,
1145-
'id'
1146-
> & {
1147-
user_id?: string;
1148-
};
1149-
1150-
export type QueryRemindersOptions = Pager & {
1151-
filter?: ReminderFilters;
1152-
sort?: ReminderSort;
1153-
};

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ export const promoteChannel = ({
957957
export const isDate = (value: unknown): value is Date => !!(value as Date).getTime;
958958

959959
export const isLocalMessage = (message: unknown): message is LocalMessage =>
960-
isDate((message as LocalMessage).created_at);
960+
typeof (message as LocalMessage | undefined)?.status === 'string';
961961

962962
export const runDetached = <T>(
963963
callback: Promise<void | T>,

0 commit comments

Comments
 (0)