Send channel messages as AS bot if sender is unknown

This commit is contained in:
Tulir Asokan
2017-11-30 21:38:55 +02:00
parent eaff8204b8
commit 56ab82cabd
4 changed files with 24 additions and 9 deletions
+7
View File
@@ -34,6 +34,7 @@ class MautrixTelegram {
*/
constructor(config) {
this.config = config
this.channelTelegramSender = new TelegramUser(this, -1)
/**
* MXID -> {@link MatrixUser} cache.
@@ -142,6 +143,9 @@ class MautrixTelegram {
* @returns {Intent} The Matrix puppet intent for the given Telegram user.
*/
getIntentForTelegramUser(id) {
if (id === -1) {
return this.botIntent
}
return this.bridge.getIntentFromLocalpart(this.getUsernameForTelegramUser(id))
}
@@ -282,6 +286,9 @@ class MautrixTelegram {
* @returns {TelegramUser} The TelegramUser object.
*/
async getTelegramUser(id, { createIfNotFound = true } = {}) {
if (id === -1) {
return this.channelTelegramSender
}
// TODO remove this after bugs are fixed
if (isNaN(parseInt(id, 10))) {
const err = new Error("Fatal: non-int Telegram user ID")
+1
View File
@@ -210,6 +210,7 @@ class Portal {
console.error(err.stack)
}
}
const sender = await this.app.getTelegramUser(evt.from)
await sender.intent.sendTyping(this.roomID, false)
+13 -7
View File
@@ -137,13 +137,19 @@ class TelegramPeer {
channel: this.toInputObject(),
})
info = info.chats[0]
const participants = await telegramPOV.client("channels.getParticipants", {
channel: this.toInputObject(),
filter: { _: "channelParticipantsRecent" },
offset: 0,
limit: 1000,
})
users = participants.users
try {
const participants = await telegramPOV.client("channels.getParticipants", {
channel: this.toInputObject(),
filter: { _: "channelParticipantsRecent" },
offset: 0,
limit: 1000,
})
users = participants.users
} catch (err) {
// Getting channel participants apparently requires admin.
// TODO figure out what to do about that ^
users = []
}
break
default:
throw new Error(`Unknown peer type ${this.type}`)
+3 -2
View File
@@ -305,9 +305,11 @@ class TelegramPuppet {
from = update.from_id
break
case "updateNewChannelMessage":
// TODO figure out how channel message signing works
from = -1
case "updateNewMessage":
update = update.message // Message defined at message#90dddc11 in layer 71
from = update.from_id
from = update.from_id || from
to = TelegramPeer.fromTelegramData(update.to_id, update.from_id, this.userID)
break
@@ -317,7 +319,6 @@ class TelegramPuppet {
return
}
console.log(update)
portal = await this.app.getPortalByPeer(to)
if (update._ === "messageService") {