Fix some message duplication that was probably caused by telegram-mtproto

This commit is contained in:
Tulir Asokan
2018-01-08 12:27:37 +02:00
parent 9c5a6aa43d
commit f84f32ee10
3 changed files with 27 additions and 5 deletions
+8
View File
@@ -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))
}
}
+4 -1
View File
@@ -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)
+15 -4
View File
@@ -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,