~emersion/gamja

a952742d86c7690046826c601f1a597d3267e905 — Simon Ser 10 days ago 5b0bb43
Make Client.roundtripChatHistory return an array of messages
1 files changed, 7 insertions(+), 7 deletions(-)

M lib/client.js
M lib/client.js => lib/client.js +7 -7
@@ 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;