diff --git a/components/app.js b/components/app.js index ce8ab24..deca901 100644 --- a/components/app.js +++ b/components/app.js @@ -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); }); } diff --git a/lib/client.js b/lib/client.js index 8eb6073..1751a81 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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;