Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ import type {
CreateDraftResponse,
DeleteMessageOptions,
Event,
EventAPIResponse,
EventHandler,
EventPayload,
EventType,
GetRepliesAPIResponse,
GetRepliesRequest,
LocalMessage,
MarkReadRequest,
MarkReadResponseEvent,
MarkUnreadRequest,
MessagePaginationOptions,
MessageRequest,
Expand Down Expand Up @@ -133,7 +133,7 @@ export type CustomDeleteMessageRequestFn = (
export type CustomMarkReadRequestFn = (params: {
channel: Channel;
options?: MarkReadRequest;
}) => Promise<EventAPIResponse | null>;
}) => Promise<{ event: MarkReadResponseEvent } | null>;

export type ChannelInstanceConfig = {
requestHandlers?: {
Expand Down
23 changes: 6 additions & 17 deletions src/messageDelivery/MessageDeliveryReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import { Channel } from '../channel';
import type { ThreadUserReadState } from '../thread';
import { Thread } from '../thread';
import type {
EventAPIResponse,
LocalMessage,
MarkDeliveredRequest,
MarkReadRequest,
MarkReadResponse,
StreamAPIError,
StreamResponse,
} from '../types';
import { throttle, userHasReadReceipts } from '../utils';
import { isAPIError, isErrorRetryable } from '../errors';
import type { MarkReadResponse as Gen_MarkReadResponse } from '../gen/models';

const MAX_DELIVERED_MESSAGE_COUNT_IN_PAYLOAD = 100 as const;
const MARK_AS_DELIVERED_BUFFER_TIMEOUT = 1000 as const;
Expand Down Expand Up @@ -306,30 +305,20 @@ export class MessageDeliveryReporter {
? { ...options, thread_id: collection.id }
: options;

let result: EventAPIResponse | StreamResponse<Gen_MarkReadResponse> | null = null;
let result: Partial<StreamResponse<MarkReadResponse>> | null = null;

if (isThreadCollection) {
const markReadRequestHandler = collection.configState.getLatestValue()
.requestHandlers?.markReadRequest as
| ((params: {
thread: Thread;
options?: MarkReadRequest;
}) => Promise<EventAPIResponse | null> | void)
| undefined;
const markReadRequestHandler =
collection.configState.getLatestValue().requestHandlers?.markReadRequest;
result = markReadRequestHandler
? ((await markReadRequestHandler({
options: requestOptions,
thread: collection,
})) ?? null)
: await channel.markRead(requestOptions);
} else {
const markReadRequestHandler = channel.configState.getLatestValue().requestHandlers
?.markReadRequest as
| ((params: {
channel: Channel;
options?: MarkReadRequest;
}) => Promise<EventAPIResponse | null> | void)
| undefined;
const markReadRequestHandler =
channel.configState.getLatestValue().requestHandlers?.markReadRequest;
result = markReadRequestHandler
? ((await markReadRequestHandler({ channel, options: requestOptions })) ?? null)
: await channel.markRead(requestOptions);
Expand Down
12 changes: 6 additions & 6 deletions src/pagination/paginators/ReminderPaginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
PaginatorOptions,
} from './BasePaginator';
import type {
QueryRemindersOptions,
QueryRemindersRequest,
ReminderFilters,
ReminderResponseData,
ReminderSort,
Expand All @@ -25,7 +25,7 @@ const DEFAULT_SORT: ReminderSort = [{ direction: 1, field: 'created_at' }];

export class ReminderPaginator extends BasePaginator<
ReminderResponseData,
QueryRemindersOptions
QueryRemindersRequest
> {
private client: StreamChat;
protected _filters: ReminderFilters | undefined;
Expand All @@ -52,7 +52,7 @@ export class ReminderPaginator extends BasePaginator<

constructor(
client: StreamChat,
options?: PaginatorOptions<ReminderResponseData, QueryRemindersOptions>,
options?: PaginatorOptions<ReminderResponseData, QueryRemindersRequest>,
) {
super({
initialCursor: ZERO_PAGE_CURSOR,
Expand Down Expand Up @@ -83,8 +83,8 @@ export class ReminderPaginator extends BasePaginator<
protected getNextQueryShape({
direction,
}: Required<
Pick<PaginationQueryParams<QueryRemindersOptions>, 'direction'>
>): QueryRemindersOptions {
Pick<PaginationQueryParams<QueryRemindersRequest>, 'direction'>
>): QueryRemindersRequest {
const cursor = this.cursor?.[direction];
return {
filter: this.filters,
Expand All @@ -96,7 +96,7 @@ export class ReminderPaginator extends BasePaginator<

query = async ({
queryShape,
}: PaginationQueryParams<QueryRemindersOptions>): Promise<
}: PaginationQueryParams<QueryRemindersRequest>): Promise<
PaginationQueryReturnValue<ReminderResponseData>
> => {
const { reminders: items, next, prev } = await this.client.queryReminders(queryShape);
Expand Down
22 changes: 11 additions & 11 deletions src/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
import { applyReactionLocally } from './entityStore';
import type {
DraftResponse,
EventAPIResponse,
EventType,
LocalMessage,
MarkReadRequest,
MarkReadResponseEvent,
MessageResponse,
ReactionRequest,
ReadStateResponse,
Expand Down Expand Up @@ -75,7 +75,7 @@ const DEFAULT_ITEM_ORDER: SortParamRequest[] = [{ field: 'created_at', direction
export type CustomThreadMarkReadRequestFn = (params: {
thread: Thread;
options?: MarkReadRequest;
}) => Promise<EventAPIResponse | null> | void;
}) => Promise<{ event: MarkReadResponseEvent } | null> | void;

export type ThreadInstanceConfig = {
requestHandlers?: {
Expand Down Expand Up @@ -139,7 +139,7 @@ export class Thread extends WithSubscriptions {
participants: threadData.thread_participants,
read: formatReadState(
!threadData.read || threadData.read.length === 0
? getPlaceholderReadResponse(client.userID)
? getPlaceholderReadResponse(client.userId)
: threadData.read,
),
// Use the parent message's reply_count, not the top-level threadData.reply_count. The
Expand Down Expand Up @@ -180,7 +180,7 @@ export class Thread extends WithSubscriptions {
isStateStale: false,
parentMessage: formattedParentMessage,
participants: [],
read: formatReadState(getPlaceholderReadResponse(client.userID)),
read: formatReadState(getPlaceholderReadResponse(client.userId)),
replyCount: parentMessage.reply_count ?? 0,
title: '',
updatedAt: parentMessage.updated_at ? new Date(parentMessage.updated_at) : null,
Expand Down Expand Up @@ -305,7 +305,7 @@ export class Thread extends WithSubscriptions {
}

get ownUnreadCount() {
return ownUnreadCountSelector(this.client.userID)(this.state.getLatestValue());
return ownUnreadCountSelector(this.client.userId)(this.state.getLatestValue());
}

public activate = () => {
Expand Down Expand Up @@ -429,7 +429,7 @@ export class Thread extends WithSubscriptions {
this.state.subscribeWithSelector(
(nextValue) => ({
active: nextValue.active,
unreadMessageCount: ownUnreadCountSelector(this.client.userID)(nextValue),
unreadMessageCount: ownUnreadCountSelector(this.client.userId)(nextValue),
}),
({ active, unreadMessageCount }) => {
if (!active || !unreadMessageCount) return;
Expand All @@ -452,8 +452,8 @@ export class Thread extends WithSubscriptions {
const { channel } = this.state.getLatestValue();

if (
!this.client.userID ||
this.client.userID !== event.user?.id ||
!this.client.userId ||
this.client.userId !== event.user?.id ||
event.channel?.cid !== channel.cid
) {
return;
Expand Down Expand Up @@ -491,11 +491,11 @@ export class Thread extends WithSubscriptions {

private subscribeNewReplies = () =>
this.client.on('message.new', (event) => {
if (!this.client.userID || event.message?.parent_id !== this.id) {
if (!this.client.userId || event.message?.parent_id !== this.id) {
return;
}

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

this.upsertReplyLocally({
Expand Down Expand Up @@ -526,7 +526,7 @@ export class Thread extends WithSubscriptions {
user: event.user,
unreadMessageCount: 0,
};
} else if (active && userId === this.client.userID) {
} else if (active && userId === this.client.userId) {
// Do not increment unread count for the current user in an active thread
} else {
// Increment unread count for all users except the author of the new message
Expand Down
32 changes: 0 additions & 32 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1107,35 +1107,3 @@ export type GiphyVersions = keyof Images;
export type TranslationLanguage = TranslateMessageRequest['language'];

export * from './gen/models';

export type EventAPIResponse = APIResponse & {
event: Event;
};

export type PartializeKeys<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;

type ErrorResponseDetails = {
code: number;
messages: string[];
};

export type APIErrorResponse = {
duration: string;
message: string;
more_info: string;
StatusCode: number;
code?: number;
details?: ErrorResponseDetails;
};

export type DraftMessagePayload = PartializeKeys<
Omit<DraftMessage, 'mentioned_groups'>,
'id'
> & {
user_id?: string;
};

export type QueryRemindersOptions = Pager & {
filter?: ReminderFilters;
sort?: ReminderSort;
};
Comment on lines -1110 to -1141

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replaced all of these with generated equivalents.

2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ export const generateChannelTempCid = (channelType: string, members: string[]) =
export const isDate = (value: unknown): value is Date => !!(value as Date).getTime;

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Important one to check, @isekovanic and @MartinCupela.


export const runDetached = <T>(
callback: Promise<void | T>,
Expand Down