mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-11-14 19:05:01 -05:00
Use ISUPPORT CHATHISTORY to discover max page size
This commit is contained in:
parent
305ffb569c
commit
f122e44e9b
2 changed files with 16 additions and 6 deletions
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue