-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add channel messages pagination indicators #1332
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
87c951a
feat: add channel messages pagination indicators
MartinCupela a7e63d7
style: apply prettier rules
MartinCupela 6759d2a
feat: keep message pagination enabled by default
MartinCupela f9431b2
test: add tests for messageSetPagination
MartinCupela eec3cd7
feat: return default message set pagination if not available
MartinCupela a16f267
test: return default message set pagination if not available
MartinCupela a6d9a10
feat: update message set pagination indicators with any pagination op…
MartinCupela 90082b4
fix: page mid point is calculated as Math.floor
MartinCupela 9dfea3e
feat: update messageSet pagination on merge
MartinCupela 146f070
Merge branch 'master' into feat/messages-pagination-indicators
MartinCupela 1e1c610
feat: use client logger to log pagination state error
MartinCupela 1b63fda
Merge branch 'master' into feat/messages-pagination-indicators
MartinCupela File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import { | |
isFunction, | ||
isOnline, | ||
isOwnUserBaseProperty, | ||
messageSetPagination, | ||
normalizeQuerySort, | ||
randomId, | ||
retryInterval, | ||
|
@@ -207,6 +208,7 @@ import { | |
import { InsightMetrics, postInsights } from './insights'; | ||
import { Thread } from './thread'; | ||
import { Moderation } from './moderation'; | ||
import { DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE } from './constants'; | ||
|
||
function isString(x: unknown): x is string { | ||
return typeof x === 'string' || x instanceof String; | ||
|
@@ -1601,7 +1603,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG | |
}, | ||
}); | ||
|
||
return this.hydrateActiveChannels(data.channels, stateOptions); | ||
return this.hydrateActiveChannels(data.channels, stateOptions, options); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spaghetti code architecture forced me to do this. |
||
} | ||
|
||
/** | ||
|
@@ -1638,26 +1640,38 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG | |
hydrateActiveChannels( | ||
channelsFromApi: ChannelAPIResponse<StreamChatGenerics>[] = [], | ||
stateOptions: ChannelStateOptions = {}, | ||
queryChannelsOptions?: ChannelOptions, | ||
) { | ||
const { skipInitialization, offlineMode = false } = stateOptions; | ||
|
||
for (const channelState of channelsFromApi) { | ||
this._addChannelConfig(channelState.channel); | ||
} | ||
|
||
const channels: Channel<StreamChatGenerics>[] = []; | ||
|
||
for (const channelState of channelsFromApi) { | ||
this._addChannelConfig(channelState.channel); | ||
const c = this.channel(channelState.channel.type, channelState.channel.id); | ||
c.data = channelState.channel; | ||
c.offlineMode = offlineMode; | ||
c.initialized = !offlineMode; | ||
|
||
let updatedMessagesSet; | ||
if (skipInitialization === undefined) { | ||
c._initializeState(channelState, 'latest'); | ||
const { messageSet } = c._initializeState(channelState, 'latest'); | ||
updatedMessagesSet = messageSet; | ||
} else if (!skipInitialization.includes(channelState.channel.id)) { | ||
c.state.clearMessages(); | ||
c._initializeState(channelState, 'latest'); | ||
const { messageSet } = c._initializeState(channelState, 'latest'); | ||
updatedMessagesSet = messageSet; | ||
} | ||
|
||
if (updatedMessagesSet) { | ||
updatedMessagesSet.pagination = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pagination indicators are calculated once the requested page is merged into the parent message set. |
||
...updatedMessagesSet.pagination, | ||
...messageSetPagination({ | ||
parentSet: updatedMessagesSet, | ||
requestedPageSize: queryChannelsOptions?.message_limit || DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE, | ||
returnedPage: channelState.messages, | ||
logger: this.logger, | ||
}), | ||
}; | ||
} | ||
|
||
channels.push(c); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merging pagination objects when merging message sets.