diff --git a/src/app.js b/src/app.js index 687e1182..944c635a 100644 --- a/src/app.js +++ b/src/app.js @@ -121,12 +121,20 @@ class MautrixTelegram { debug(color, ...message) { if (this.config.appservice.debug) { + if (!chalk[color]) { + message.unshift(`[Invalid color: ${color}]`) + color = "bgRed" + } console.log(chalk[color](...message)) } } debugErr(color, ...message) { if (this.config.appservice.debug) { + if (!chalk[color]) { + message.unshift(`[Invalid color: ${color}]`) + color = "bgRed" + } console.error(chalk[color](...message)) } } diff --git a/src/portal.js b/src/portal.js index e4ca5116..03516e3c 100644 --- a/src/portal.js +++ b/src/portal.js @@ -334,7 +334,8 @@ class Portal { * Handle a Telegram service message event. * * @param {Object} evt The custom event object. - * @param {number} evt.from The ID of the Telegram user who caused the service message. + * @param {number} evt.from The ID of the Telegram user who sent the message. + * @param {number} evt.fwdFrom The ID of the Telegram user who originally sent the message. * @param {TelegramPeer} evt.to The peer to which the message was sent. * @param {TelegramPuppet} evt.source The source where this event was captured. * @param {string} evt.text The text in the message. @@ -375,6 +376,8 @@ class Portal { } } + // TODO display forwards (evt.fwdFrom) + if (evt.text && evt.text.length > 0) { if (evt.entities) { evt.html = formatter.telegramToMatrix(evt.text, evt.entities, this.app) diff --git a/src/telegram-puppet.js b/src/telegram-puppet.js index f0ff6d38..96233308 100644 --- a/src/telegram-puppet.js +++ b/src/telegram-puppet.js @@ -99,6 +99,7 @@ class TelegramPuppet { this.pts = 0 this.date = 0 + this.lastID = 0 this.puppetStorage = { get: async (key) => { @@ -320,7 +321,7 @@ class TelegramPuppet { from = update.from_id break case "updateNewChannelMessage": - // TODO figure out how channel message signing works + // TODO use message.post_author from = -1 case "updateNewMessage": this.pts = update.pts @@ -330,24 +331,33 @@ class TelegramPuppet { break case "updateReadMessages": case "updateReadHistoryOutbox": + case "updateReadHistoryInbox": case "updateDeleteMessages": case "updateRestoreMessages": + // TODO we probably want to handle those five updates properly this.pts = update.pts - break + return default: // Unknown update type - console.log(`Update of unknown type ${update._} received:\n${JSON.stringify(update, "", " ")}`) + this.app.warn(`Update of unknown type ${update._} received: ${JSON.stringify(update, "", " ")}`) return } if (!to) { // This shouldn't happen - console.warn("No target found for update", update) + this.app.warn("No target found for update", update) return } if (update._ === "messageService" && update.action._ === "messageActionChannelMigrateFrom") { return } + if (update.id) { + if (update.id <= this.lastID) { + this.app.debug(`Received old/duplicate message with ID ${update.id} (latest ID: ${this.lastID})`) + return + } + this.lastID = update.id + } portal = await this.app.getPortalByPeer(to) if (update._ === "messageService") { @@ -362,6 +372,7 @@ class TelegramPuppet { await portal.handleTelegramMessage({ from, to, + fwdFrom: update.fwd_from ? update.fwd_from.from_id : 0, source: this, text: update.message, entities: update.entities,