From 9c5a6aa43d7313cb55bdce99feb06f515f4cdcc8 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 8 Jan 2018 11:36:59 +0200 Subject: [PATCH] Handle updatesTooLong properly --- src/app.js | 2 +- src/portal.js | 2 +- src/telegram-puppet.js | 20 +++++++++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/app.js b/src/app.js index 37e78489..687e1182 100644 --- a/src/app.js +++ b/src/app.js @@ -136,7 +136,7 @@ class MautrixTelegram { } warn(...message) { - console.error(chalk.orange(...message)) + console.error(chalk.yellow(...message)) } /** diff --git a/src/portal.js b/src/portal.js index d403ab2c..e4ca5116 100644 --- a/src/portal.js +++ b/src/portal.js @@ -226,7 +226,7 @@ class Portal { // We don't care about user deletions on chats without portals return } - this.app.debug("yellow", "Service message received, creating room for", evt.to.id) + this.app.debug("magenta", "Service message received, creating room for", evt.to.id) await this.createMatrixRoom(evt.source, { invite: [evt.source.matrixUser.userID] }) return } diff --git a/src/telegram-puppet.js b/src/telegram-puppet.js index f3304baf..f0ff6d38 100644 --- a/src/telegram-puppet.js +++ b/src/telegram-puppet.js @@ -410,14 +410,26 @@ class TelegramPuppet { this.app.warn("updatesTooLong received, but we don't have a persistent timestamp :(") break } - this.app.debug("yellow", "Handling updatesTooLong", this.pts, this.date) + this.app.debug("magenta", "Handling updatesTooLong", this.pts, this.date) const dat = await this.client("updates.getDifference", { pts: this.pts, date: this.date, qts: -1, }) - this.app.debug("yellow", `updatesTooLong data: ${JSON.stringify(dat, "", " ")}`) - // TODO use updatesTooLong data? + this.app.debug("magenta", `updates.getDifference: ${JSON.stringify(dat, "", " ")}`) + // TODO use dat.users and dat.chats + this.pts = dat.state.pts + this.date = dat.state.date + for (const message of dat.new_messages) { + this.onUpdate({ + _: "updateNewMessage", + pts: this.pts, + message, + }) + } + for (const update of dat.other_updates) { + this.onUpdate(update) + } break default: this.app.warn("Unrecognized update type:", data._) @@ -437,6 +449,8 @@ class TelegramPuppet { //console.log(statusUpdate) this.app.info("Fetching initial state...") const state = await this.client("updates.getState", {}) + this.pts = state.pts + this.date = state.date this.app.debug("green", "Initial state:", JSON.stringify(state, "", " ")) } catch (err) { console.error("Error getting initial state:", err)