mirror of
https://codeberg.org/emersion/gamja.git
synced 2025-03-29 23:19:41 -04:00
Make Client.roundtripChatHistory return an array of messages
This commit is contained in:
parent
5b0bb43a24
commit
a952742d86
1 changed files with 7 additions and 7 deletions
|
@ -580,7 +580,7 @@ export default class Client extends EventTarget {
|
|||
command: "CHATHISTORY",
|
||||
params,
|
||||
};
|
||||
return this.fetchBatch(msg, "chathistory");
|
||||
return this.fetchBatch(msg, "chathistory").then((batch) => batch.messages);
|
||||
});
|
||||
return this.pendingHistory;
|
||||
}
|
||||
|
@ -599,8 +599,8 @@ export default class Client extends EventTarget {
|
|||
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 >= max };
|
||||
return this.roundtripChatHistory(params).then((messages) => {
|
||||
return { more: messages.length >= max };
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -608,14 +608,14 @@ export default class Client extends EventTarget {
|
|||
fetchHistoryBetween(target, after, before, limit) {
|
||||
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;
|
||||
return this.roundtripChatHistory(params).then((messages) => {
|
||||
limit -= messages.length;
|
||||
if (limit <= 0) {
|
||||
throw new Error("Cannot fetch all chat history: too many messages");
|
||||
}
|
||||
if (batch.messages.length == max) {
|
||||
if (messages.length == max) {
|
||||
// There are still more messages to fetch
|
||||
after.time = batch.messages[batch.messages.length - 1].tags.time;
|
||||
after.time = messages[messages.length - 1].tags.time;
|
||||
return this.fetchHistoryBetween(target, after, before, limit);
|
||||
}
|
||||
return null;
|
||||
|
|
Loading…
Add table
Reference in a new issue