Allow upgrading Telegram groups to supergroups from Matrix
This commit is contained in:
@@ -100,4 +100,5 @@ does not do this automatically.
|
|||||||
* Misc
|
* Misc
|
||||||
* [ ] Use optional bot to relay messages for unauthenticated Matrix users
|
* [ ] Use optional bot to relay messages for unauthenticated Matrix users
|
||||||
* [x] Properly handle upgrading groups to supergroups
|
* [x] Properly handle upgrading groups to supergroups
|
||||||
|
* [x] Allow upgrading group to supergroup from Matrix
|
||||||
* [ ] Handle public channel username changes
|
* [ ] Handle public channel username changes
|
||||||
|
|||||||
+17
-1
@@ -89,7 +89,8 @@ _**Telegram actions**: commands for using the bridge to interact with Telegram._
|
|||||||
**logout** - Log out from Telegram.<br/>
|
**logout** - Log out from Telegram.<br/>
|
||||||
**search** [_-r|--remote_] <_query_> - Search your contacts or the Telegram servers for users.<br/>
|
**search** [_-r|--remote_] <_query_> - Search your contacts or the Telegram servers for users.<br/>
|
||||||
**create** <_group/channel_> [_room ID_] - Create a Telegram chat of the given type for a Matrix room.
|
**create** <_group/channel_> [_room ID_] - Create a Telegram chat of the given type for a Matrix room.
|
||||||
If the room ID is not specified, a chat for the current room is created.
|
If the room ID is not specified, a chat for the current room is created.<br/>
|
||||||
|
**upgrade** - Upgrade a normal Telegram group to a supergroup.
|
||||||
|
|
||||||
_**Temporary commands**: commands that will be replaced with more Matrix-y actions later._<br/>
|
_**Temporary commands**: commands that will be replaced with more Matrix-y actions later._<br/>
|
||||||
**pm** <_id_> - Open a private chat with the given Telegram user ID.
|
**pm** <_id_> - Open a private chat with the given Telegram user ID.
|
||||||
@@ -287,6 +288,21 @@ commands.create = async (sender, args, reply, { app, roomID }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commands.upgrade = async (sender, args, reply, { app, roomID }) => {
|
||||||
|
if (!sender._telegramPuppet) {
|
||||||
|
reply("This command requires you to be logged in.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const portal = await app.getPortalByRoomID(roomID)
|
||||||
|
if (!portal) {
|
||||||
|
reply("This is not a portal room.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
await portal.upgradeTelegramChat(sender.telegramPuppet)
|
||||||
|
}
|
||||||
|
|
||||||
commands.search = async (sender, args, reply, { app }) => {
|
commands.search = async (sender, args, reply, { app }) => {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
reply("**Usage:** `$cmdprefix search [-r|--remote] <query>`")
|
reply("**Usage:** `$cmdprefix search [-r|--remote] <query>`")
|
||||||
|
|||||||
@@ -541,6 +541,16 @@ class Portal {
|
|||||||
await this.save()
|
await this.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async upgradeTelegramChat(telegramPOV) {
|
||||||
|
if (this.peer.type !== "chat") {
|
||||||
|
throw new Error("Can't upgrade non-chat portal.")
|
||||||
|
}
|
||||||
|
const updates = await telegramPOV.client("messages.migrateChat", {
|
||||||
|
chat_id: this.id,
|
||||||
|
})
|
||||||
|
await telegramPOV.handleUpdate(updates)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Matrix room for this portal.
|
* Create a Matrix room for this portal.
|
||||||
*
|
*
|
||||||
|
|||||||
+11
-8
@@ -328,6 +328,7 @@ class TelegramPuppet {
|
|||||||
to = TelegramPeer.fromTelegramData(update.to_id, update.from_id, this.userID)
|
to = TelegramPeer.fromTelegramData(update.to_id, update.from_id, this.userID)
|
||||||
break
|
break
|
||||||
case "updateReadMessages":
|
case "updateReadMessages":
|
||||||
|
case "updateReadHistoryOutbox":
|
||||||
case "updateDeleteMessages":
|
case "updateDeleteMessages":
|
||||||
case "updateRestoreMessages":
|
case "updateRestoreMessages":
|
||||||
this.pts = update.pts
|
this.pts = update.pts
|
||||||
@@ -379,38 +380,40 @@ class TelegramPuppet {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleUpdate(data) {
|
async handleUpdate(data) {
|
||||||
try {
|
try {
|
||||||
switch (data._) {
|
switch (data._) {
|
||||||
case "updateShort":
|
case "updateShort":
|
||||||
this.date = data.date
|
this.date = data.date
|
||||||
this.onUpdate(data.update)
|
await this.onUpdate(data.update)
|
||||||
break
|
break
|
||||||
case "updates":
|
case "updates":
|
||||||
this.date = data.date
|
this.date = data.date
|
||||||
|
const updateHandlers = []
|
||||||
for (const update of data.updates) {
|
for (const update of data.updates) {
|
||||||
this.onUpdate(update)
|
updateHandlers.push(this.onUpdate(update))
|
||||||
}
|
}
|
||||||
|
await Promise.all(updateHandlers)
|
||||||
break
|
break
|
||||||
case "updateShortMessage":
|
case "updateShortMessage":
|
||||||
case "updateShortChatMessage":
|
case "updateShortChatMessage":
|
||||||
this.onUpdate(data)
|
await this.onUpdate(data)
|
||||||
break
|
break
|
||||||
case "updatesTooLong":
|
case "updatesTooLong":
|
||||||
console.log("Handling updatesTooLong")
|
console.log("Handling updatesTooLong")
|
||||||
this.client("updates.getDifference", {
|
const dat = await this.client("updates.getDifference", {
|
||||||
pts: this.pts,
|
pts: this.pts,
|
||||||
date: this.date,
|
date: this.date,
|
||||||
qts: -1,
|
qts: -1,
|
||||||
}).then(dat => console.log("getDifference", dat),
|
})
|
||||||
err => console.error("getDifferenceFail", err))
|
console.log("updatesTooLong data:", dat)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
console.log("Unrecognized update type:", data._)
|
console.log("Unrecognized update type:", data._)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error handling update:", err)
|
console.error("Error handling update:", err)
|
||||||
console.log(err.stack)
|
console.error(err.stack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user