Skip to content

Commit

Permalink
thread-load-more-bug (#627)
Browse files Browse the repository at this point in the history
* error handling for thread load more

* fix types

* update changelog

Co-authored-by: Dan Carbonell <dan@getstream.io>
  • Loading branch information
DanC5 and Dan Carbonell authored Dec 11, 2020
1 parent 87b8ec5 commit 55ee5e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [3.3.2](https://github.com/GetStream/stream-chat-react/releases/tag/v3.3.2) 2020-12-11

## Fix

- Add error handling for `loadMoreThread` API request [#627](https://github.com/GetStream/stream-chat-react/pull/627)

## [3.3.1](https://github.com/GetStream/stream-chat-react/releases/tag/v3.3.1) 2020-12-9

## Fix
Expand Down
21 changes: 13 additions & 8 deletions src/components/Channel/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,20 +488,25 @@ const ChannelInner = ({
dispatch({ type: 'closeThread' });
return;
}

const oldMessages = channel.state.threads[parentID] || [];
const oldestMessageID = oldMessages[0]?.id;
const limit = 50;
const queryResponse = await channel.getReplies(parentID, {
limit,
id_lt: oldestMessageID,
});

const threadHasMoreMessages = queryResponse.messages.length === limit;
try {
const queryResponse = await channel.getReplies(parentID, {
limit,
id_lt: oldestMessageID,
});

const newThreadMessages = channel.state.threads[parentID] || [];
const threadHasMoreMessages = queryResponse.messages.length === limit;
const newThreadMessages = channel.state.threads[parentID] || [];

// next set loadingMore to false so we can start asking for more data...
loadMoreThreadFinished(threadHasMoreMessages, newThreadMessages);
// next set loadingMore to false so we can start asking for more data...
loadMoreThreadFinished(threadHasMoreMessages, newThreadMessages);
} catch (e) {
loadMoreThreadFinished(false, oldMessages);
}
}, [channel, loadMoreThreadFinished, state.thread, state.threadLoadingMore]);

const closeThread = useCallback((e) => {
Expand Down

0 comments on commit 55ee5e7

Please sign in to comment.