diff --git a/lib/client.js b/lib/client.js index aabc695..982160b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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;