Fix some message duplication that was probably caused by telegram-mtproto
This commit is contained in:
@@ -121,12 +121,20 @@ class MautrixTelegram {
|
|||||||
|
|
||||||
debug(color, ...message) {
|
debug(color, ...message) {
|
||||||
if (this.config.appservice.debug) {
|
if (this.config.appservice.debug) {
|
||||||
|
if (!chalk[color]) {
|
||||||
|
message.unshift(`[Invalid color: ${color}]`)
|
||||||
|
color = "bgRed"
|
||||||
|
}
|
||||||
console.log(chalk[color](...message))
|
console.log(chalk[color](...message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debugErr(color, ...message) {
|
debugErr(color, ...message) {
|
||||||
if (this.config.appservice.debug) {
|
if (this.config.appservice.debug) {
|
||||||
|
if (!chalk[color]) {
|
||||||
|
message.unshift(`[Invalid color: ${color}]`)
|
||||||
|
color = "bgRed"
|
||||||
|
}
|
||||||
console.error(chalk[color](...message))
|
console.error(chalk[color](...message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -334,7 +334,8 @@ class Portal {
|
|||||||
* Handle a Telegram service message event.
|
* Handle a Telegram service message event.
|
||||||
*
|
*
|
||||||
* @param {Object} evt The custom event object.
|
* @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 {TelegramPeer} evt.to The peer to which the message was sent.
|
||||||
* @param {TelegramPuppet} evt.source The source where this event was captured.
|
* @param {TelegramPuppet} evt.source The source where this event was captured.
|
||||||
* @param {string} evt.text The text in the message.
|
* @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.text && evt.text.length > 0) {
|
||||||
if (evt.entities) {
|
if (evt.entities) {
|
||||||
evt.html = formatter.telegramToMatrix(evt.text, evt.entities, this.app)
|
evt.html = formatter.telegramToMatrix(evt.text, evt.entities, this.app)
|
||||||
|
|||||||
+15
-4
@@ -99,6 +99,7 @@ class TelegramPuppet {
|
|||||||
|
|
||||||
this.pts = 0
|
this.pts = 0
|
||||||
this.date = 0
|
this.date = 0
|
||||||
|
this.lastID = 0
|
||||||
|
|
||||||
this.puppetStorage = {
|
this.puppetStorage = {
|
||||||
get: async (key) => {
|
get: async (key) => {
|
||||||
@@ -320,7 +321,7 @@ class TelegramPuppet {
|
|||||||
from = update.from_id
|
from = update.from_id
|
||||||
break
|
break
|
||||||
case "updateNewChannelMessage":
|
case "updateNewChannelMessage":
|
||||||
// TODO figure out how channel message signing works
|
// TODO use message.post_author
|
||||||
from = -1
|
from = -1
|
||||||
case "updateNewMessage":
|
case "updateNewMessage":
|
||||||
this.pts = update.pts
|
this.pts = update.pts
|
||||||
@@ -330,24 +331,33 @@ class TelegramPuppet {
|
|||||||
break
|
break
|
||||||
case "updateReadMessages":
|
case "updateReadMessages":
|
||||||
case "updateReadHistoryOutbox":
|
case "updateReadHistoryOutbox":
|
||||||
|
case "updateReadHistoryInbox":
|
||||||
case "updateDeleteMessages":
|
case "updateDeleteMessages":
|
||||||
case "updateRestoreMessages":
|
case "updateRestoreMessages":
|
||||||
|
// TODO we probably want to handle those five updates properly
|
||||||
this.pts = update.pts
|
this.pts = update.pts
|
||||||
break
|
return
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Unknown update type
|
// 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
|
return
|
||||||
}
|
}
|
||||||
if (!to) {
|
if (!to) {
|
||||||
// This shouldn't happen
|
// This shouldn't happen
|
||||||
console.warn("No target found for update", update)
|
this.app.warn("No target found for update", update)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (update._ === "messageService" && update.action._ === "messageActionChannelMigrateFrom") {
|
if (update._ === "messageService" && update.action._ === "messageActionChannelMigrateFrom") {
|
||||||
return
|
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)
|
portal = await this.app.getPortalByPeer(to)
|
||||||
if (update._ === "messageService") {
|
if (update._ === "messageService") {
|
||||||
@@ -362,6 +372,7 @@ class TelegramPuppet {
|
|||||||
await portal.handleTelegramMessage({
|
await portal.handleTelegramMessage({
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
|
fwdFrom: update.fwd_from ? update.fwd_from.from_id : 0,
|
||||||
source: this,
|
source: this,
|
||||||
text: update.message,
|
text: update.message,
|
||||||
entities: update.entities,
|
entities: update.entities,
|
||||||
|
|||||||
Reference in New Issue
Block a user