Use ISUPPORT CHATHISTORY to discover max page size

This commit is contained in:
Simon Ser 2021-05-11 16:10:50 +02:00
parent 305ffb569c
commit f122e44e9b
2 changed files with 16 additions and 6 deletions

View file

@ -904,7 +904,7 @@ export default class App extends Component {
// Avoids sending multiple CHATHISTORY commands in parallel
this.endOfHistory.set(buf.id, true);
client.fetchHistoryBefore(buf.name, before).then((result) => {
client.fetchHistoryBefore(buf.name, before, 100).then((result) => {
this.endOfHistory.set(buf.id, !result.more);
});
}

View file

@ -13,7 +13,6 @@ const permanentCaps = [
];
const RECONNECT_DELAY_SEC = 10;
const CHATHISTORY_PAGE_SIZE = 100;
export default class Client extends EventTarget {
static Status = {
@ -419,17 +418,28 @@ export default class Client extends EventTarget {
return this.pendingHistory;
}
chatHistoryPageSize() {
if (this.isupport.has("CHATHISTORY")) {
var pageSize = parseInt(this.isupport.get("CHATHISTORY"), 10);
if (pageSize > 0) {
return pageSize;
}
}
return 100;
}
/* Fetch one page of history before the given date. */
fetchHistoryBefore(target, before) {
var params = ["BEFORE", target, "timestamp=" + before, CHATHISTORY_PAGE_SIZE];
fetchHistoryBefore(target, before, limit) {
var max = Math.min(limit, this.chatHistoryPageSize());
var params = ["BEFORE", target, "timestamp=" + before, max];
return this.roundtripChatHistory(params).then((batch) => {
return { more: batch.messages.length >= CHATHISTORY_PAGE_SIZE };
return { more: batch.messages.length >= max };
});
}
/* Fetch history in ascending order. */
fetchHistoryBetween(target, after, before, limit) {
var max = Math.min(limit, CHATHISTORY_PAGE_SIZE);
var max = Math.min(limit, this.chatHistoryPageSize());
var params = ["AFTER", target, "timestamp=" + after.time, max];
return this.roundtripChatHistory(params).then((batch) => {
limit -= batch.messages.length;