Handle avatar and chat title changes
This commit is contained in:
@@ -38,7 +38,7 @@ A Telegram chat will be created once the bridge is stable enough.
|
|||||||
* [ ] Pinning messages
|
* [ ] Pinning messages
|
||||||
* [ ] Power level
|
* [ ] Power level
|
||||||
* [ ] Membership actions (invite, kick, join, leave)
|
* [ ] Membership actions (invite, kick, join, leave)
|
||||||
* [ ] Group/channel name/description changes
|
* [ ] Room metadata changes
|
||||||
* Telegram → Matrix
|
* Telegram → Matrix
|
||||||
* [x] Plaintext messages
|
* [x] Plaintext messages
|
||||||
* [x] Formatted messages
|
* [x] Formatted messages
|
||||||
@@ -54,8 +54,8 @@ A Telegram chat will be created once the bridge is stable enough.
|
|||||||
* [ ] Pinning messages
|
* [ ] Pinning messages
|
||||||
* [ ] Admin status
|
* [ ] Admin status
|
||||||
* [x] Membership actions (invite, kick, join, leave)
|
* [x] Membership actions (invite, kick, join, leave)
|
||||||
* [ ] Group/channel name/description changes
|
* [x] Chat metadata changes
|
||||||
* [x] Initial group/channel name/description
|
* [x] Initial chat metadata
|
||||||
* [ ] Message edits
|
* [ ] Message edits
|
||||||
* Initiating chats
|
* Initiating chats
|
||||||
* [x] Automatic portal creation for groups/channels at startup
|
* [x] Automatic portal creation for groups/channels at startup
|
||||||
|
|||||||
+27
-4
@@ -93,12 +93,13 @@ class Portal {
|
|||||||
return uploaded
|
return uploaded
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateAvatar(telegramPOV, chat) {
|
async updateAvatar(telegramPOV, photo) {
|
||||||
if (!chat.photo || this.peer.type === "user") {
|
if (!photo || !photo.location || this.peer.type === "user") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const photo = chat.photo.photo_big
|
photo = photo.location
|
||||||
|
|
||||||
if (this.photo && this.avatarURL &&
|
if (this.photo && this.avatarURL &&
|
||||||
this.photo.dc_id === photo.dc_id &&
|
this.photo.dc_id === photo.dc_id &&
|
||||||
this.photo.volume_id === photo.volume_id &&
|
this.photo.volume_id === photo.volume_id &&
|
||||||
@@ -171,6 +172,26 @@ class Portal {
|
|||||||
telegramUser = await this.app.getTelegramUser(evt.action.user_id)
|
telegramUser = await this.app.getTelegramUser(evt.action.user_id)
|
||||||
telegramUser.intent.leave(this.roomID)
|
telegramUser.intent.leave(this.roomID)
|
||||||
break
|
break
|
||||||
|
case "messageActionChatEditPhoto":
|
||||||
|
const sizes = evt.action.photo.sizes
|
||||||
|
let largestSize = sizes[0]
|
||||||
|
let largestSizePixels = largestSize.w * largestSize.h
|
||||||
|
for (const size of sizes) {
|
||||||
|
const pixels = size.w * size.h
|
||||||
|
if (pixels > largestSizePixels) {
|
||||||
|
largestSizePixels = pixels
|
||||||
|
largestSize = size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO once permissions are synced, make the avatar change event come from the user who changed the avatar
|
||||||
|
await this.updateAvatar(evt.source, largestSize)
|
||||||
|
break
|
||||||
|
case "messageActionChatEditTitle":
|
||||||
|
this.peer.title = evt.action.title
|
||||||
|
await this.save()
|
||||||
|
const intent = await this.getMainIntent()
|
||||||
|
await intent.setRoomName(this.roomID, this.peer.title)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
console.log("Unhandled service message of type", evt.action._)
|
console.log("Unhandled service message of type", evt.action._)
|
||||||
console.log(evt.action)
|
console.log(evt.action)
|
||||||
@@ -363,7 +384,9 @@ class Portal {
|
|||||||
if (this.peer.type !== "user") {
|
if (this.peer.type !== "user") {
|
||||||
try {
|
try {
|
||||||
await this.syncTelegramUsers(telegramPOV, users)
|
await this.syncTelegramUsers(telegramPOV, users)
|
||||||
await this.updateAvatar(telegramPOV, info)
|
if (info.photo && info.photo.photo_big) {
|
||||||
|
await this.updateAvatar(telegramPOV, info.photo.photo_big)
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
if (err instanceof Error) {
|
if (err instanceof Error) {
|
||||||
|
|||||||
@@ -324,6 +324,7 @@ class TelegramPuppet {
|
|||||||
await portal.handleTelegramServiceMessage({
|
await portal.handleTelegramServiceMessage({
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
|
source: this,
|
||||||
action: update.action,
|
action: update.action,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user