fix: set offset correctly on thread message view (#5609)

This commit is contained in:
Gleidson Daniel Silva 2024-03-13 10:29:25 -03:00 committed by GitHub
parent b5cef460f5
commit afe50aed7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 4 deletions

View File

@ -48,6 +48,7 @@ interface IThreadMessagesViewState {
currentFilter: Filter; currentFilter: Filter;
isSearching: boolean; isSearching: boolean;
searchText: string; searchText: string;
offset: number;
} }
interface IThreadMessagesViewProps extends IBaseScreen<ChatsStackParamList, 'ThreadMessagesView'> { interface IThreadMessagesViewProps extends IBaseScreen<ChatsStackParamList, 'ThreadMessagesView'> {
@ -85,7 +86,8 @@ class ThreadMessagesView extends React.Component<IThreadMessagesViewProps, IThre
showFilterDropdown: false, showFilterDropdown: false,
currentFilter: Filter.All, currentFilter: Filter.All,
isSearching: false, isSearching: false,
searchText: '' searchText: '',
offset: 0
}; };
this.setHeader(); this.setHeader();
this.initSubscription(); this.initSubscription();
@ -308,7 +310,7 @@ class ThreadMessagesView extends React.Component<IThreadMessagesViewProps, IThre
// eslint-disable-next-line react/sort-comp // eslint-disable-next-line react/sort-comp
load = debounce(async (lastThreadSync: Date) => { load = debounce(async (lastThreadSync: Date) => {
const { loading, end, messages, searchText } = this.state; const { loading, end, searchText, offset } = this.state;
if (end || loading || !this.mounted) { if (end || loading || !this.mounted) {
return; return;
} }
@ -319,14 +321,15 @@ class ThreadMessagesView extends React.Component<IThreadMessagesViewProps, IThre
const result = await Services.getThreadsList({ const result = await Services.getThreadsList({
rid: this.rid, rid: this.rid,
count: API_FETCH_COUNT, count: API_FETCH_COUNT,
offset: messages.length, offset,
text: searchText text: searchText
}); });
if (result.success) { if (result.success) {
this.updateThreads({ update: result.threads, lastThreadSync }); this.updateThreads({ update: result.threads, lastThreadSync });
this.setState({ this.setState({
loading: false, loading: false,
end: result.count < API_FETCH_COUNT end: result.count < API_FETCH_COUNT,
offset: offset + API_FETCH_COUNT
}); });
} }
} catch (e) { } catch (e) {