Skip to content

Commit

Permalink
feat: return default message set pagination if not available
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupela committed Aug 7, 2024
1 parent f9431b2 commit eec3cd7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/channel_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
UserResponse,
} from './types';
import { addToMessageList } from './utils';
import {DEFAULT_MESSAGE_SET_PAGINATION} from "./constants";

type ChannelReadStatus<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = Record<
string,
Expand Down Expand Up @@ -106,7 +107,7 @@ export class ChannelState<StreamChatGenerics extends ExtendableGenerics = Defaul
}

get messagePagination() {
return this.messageSets.find((s) => s.isCurrent)?.pagination || {};
return this.messageSets.find((s) => s.isCurrent)?.pagination || DEFAULT_MESSAGE_SET_PAGINATION;
}

/**
Expand Down Expand Up @@ -719,7 +720,7 @@ export class ChannelState<StreamChatGenerics extends ExtendableGenerics = Defaul

initMessages() {
this.messageSets = [
{ messages: [], isLatest: true, isCurrent: true, pagination: { hasNext: true, hasPrev: true } },
{ messages: [], isLatest: true, isCurrent: true, pagination: DEFAULT_MESSAGE_SET_PAGINATION },
];
}

Expand Down Expand Up @@ -828,7 +829,7 @@ export class ChannelState<StreamChatGenerics extends ExtendableGenerics = Defaul
messages: [],
isCurrent: false,
isLatest: false,
pagination: { hasNext: true, hasPrev: true },
pagination: DEFAULT_MESSAGE_SET_PAGINATION,
});
targetMessageSetIndex = this.messageSets.length - 1;
}
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE = 25;
export const DEFAULT_QUERY_CHANNEL_MESSAGE_LIST_PAGE_SIZE = 100;

export const DEFAULT_MESSAGE_SET_PAGINATION = { hasNext: true, hasPrev: true };

0 comments on commit eec3cd7

Please sign in to comment.