Skip to content

Commit

Permalink
Adjust tests and package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
arnautov-anton committed Jul 31, 2024
1 parent 167da38 commit 4867084
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"test-types": "node test/typescript/index.js && tsc --esModuleInterop true --noEmit true --strictNullChecks true --noImplicitAny true --strict true test/typescript/*.ts",
"eslint": "eslint '**/*.{js,md,ts}' --max-warnings 0 --ignore-path ./.eslintignore",
"eslint-fix": "npx eslint --fix '**/*.{js,md,ts}' --max-warnings 0 --ignore-path ./.eslintignore",
"test-unit": "NODE_ENV=test mocha --exit --bail --timeout 20000 --require ./babel-register test/unit/*.js",
"test-unit": "NODE_ENV=test mocha --exit --bail --timeout 20000 --require ./babel-register test/unit/*.{js,test.ts}",
"test-coverage": "nyc yarn test-unit",
"test": "yarn test-unit",
"testwatch": "NODE_ENV=test nodemon ./node_modules/.bin/mocha --timeout 20000 --require test-entry.js test/test.js",
Expand Down
15 changes: 9 additions & 6 deletions src/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type QueryRepliesOptions<T extends ExtendableGenerics> = {
sort?: { created_at: AscDesc }[];
} & MessagePaginationOptions & { user?: UserResponse<T>; user_id?: string };

export type ThreadState<T extends ExtendableGenerics> = {
export type ThreadState<T extends ExtendableGenerics = DefaultGenerics> = {
active: boolean;

createdAt: Date;
Expand All @@ -53,10 +53,10 @@ export type ThreadState<T extends ExtendableGenerics> = {
};

const DEFAULT_PAGE_LIMIT = 50;
const DEFAULT_MARK_AS_READ_THROTTLE_DURATION = 1000;
const DEFAULT_CONNECTION_RECOVERY_THROTTLE_DURATION = 1000;
const MAX_QUERY_THREADS_LIMIT = 25;
const DEFAULT_SORT: { created_at: AscDesc }[] = [{ created_at: -1 }];
export const DEFAULT_MARK_AS_READ_THROTTLE_DURATION = 1000;

/**
* Request batching?
Expand Down Expand Up @@ -202,7 +202,8 @@ export class Thread<Scg extends ExtendableGenerics = DefaultGenerics> {
// check whether this instance has subscriptions and is already listening for changes
if (this.unsubscribeFunctions.size) return;

const throttledMarkAsRead = throttle(this.markAsRead, DEFAULT_MARK_AS_READ_THROTTLE_DURATION, {
// TODO: figure out why markAsRead needs to be wrapped like this (for tests to pass)
const throttledMarkAsRead = throttle(() => this.markAsRead(), DEFAULT_MARK_AS_READ_THROTTLE_DURATION, {
leading: true,
trailing: true,
});
Expand Down Expand Up @@ -300,10 +301,12 @@ export class Thread<Scg extends ExtendableGenerics = DefaultGenerics> {
this.upsertReplyLocally({
message: event.message,
// deal with timestampChanged only related to local user (optimistic updates)
timestampChanged: event.message.user?.id === this.client.user?.id,
timestampChanged: event.message.user?.id === currentUserId,
});

if (event.user && event.user.id !== currentUserId) this.incrementOwnUnreadCount();
if (event.message.user?.id !== currentUserId) this.incrementOwnUnreadCount();
// TODO: figure out if event.user is better when it comes to event messages?
// if (event.user && event.user.id !== currentUserId) this.incrementOwnUnreadCount();
}).unsubscribe,
);

Expand Down Expand Up @@ -381,7 +384,7 @@ export class Thread<Scg extends ExtendableGenerics = DefaultGenerics> {
});

const actualIndex =
latestReplies[index].id === message.id ? index : latestReplies[index - 1].id === message.id ? index - 1 : null;
latestReplies[index]?.id === message.id ? index : latestReplies[index - 1]?.id === message.id ? index - 1 : null;

if (actualIndex === null) return;

Expand Down
Loading

0 comments on commit 4867084

Please sign in to comment.