Code additions/edits
This commit is contained in:
+1
-1
@@ -104,7 +104,7 @@ class MatrixUser {
|
||||
}
|
||||
for (const [index, contact] of Object.entries(contacts.users)) {
|
||||
const telegramUser = await this.app.getTelegramUser(contact.id)
|
||||
await telegramUser.updateInfo(this.telegramPuppet, contact)
|
||||
await telegramUser.updateInfo(this.telegramPuppet, contact, true)
|
||||
contacts.users[index] = telegramUser
|
||||
}
|
||||
this.contacts = contacts.users
|
||||
|
||||
+5
-1
@@ -107,7 +107,11 @@ class Portal {
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
return this.peer.updateInfo(dialog) || changed
|
||||
changed = this.peer.updateInfo(dialog) || changed
|
||||
if (changed) {
|
||||
this.save()
|
||||
}
|
||||
return changed
|
||||
}
|
||||
|
||||
toEntry() {
|
||||
|
||||
@@ -79,9 +79,6 @@ class TelegramPeer {
|
||||
this.title = dialog.title
|
||||
changed = true
|
||||
}
|
||||
if (changed) {
|
||||
this.save()
|
||||
}
|
||||
return changed
|
||||
}
|
||||
|
||||
|
||||
+16
-6
@@ -202,19 +202,29 @@ class TelegramPuppet {
|
||||
return result
|
||||
}
|
||||
|
||||
handleMessage(message) {
|
||||
async handleMessage(message) {
|
||||
console.log(
|
||||
`Received message from ${message.from.id} to ${message.to.type.replace("user", "1-1 chat")}${message.to.type === "user" ? "" : " " + message.to.id}: ${message.text}`)
|
||||
}
|
||||
|
||||
onUpdate(update) {
|
||||
async onUpdate(update) {
|
||||
if (!update) {
|
||||
console.log("Oh noes! Empty update")
|
||||
return
|
||||
}
|
||||
switch(update._) {
|
||||
case "updateUserStatus":
|
||||
console.log(update.user_id, "is now", update.status._.substr("userStatus".length))
|
||||
const user = await this.app.getTelegramUser(update.user_id)
|
||||
let status
|
||||
switch(update.status._) {
|
||||
case "userStatusOnline":
|
||||
status = "online"
|
||||
break
|
||||
case "userStatusOffline":
|
||||
default:
|
||||
status = "offline"
|
||||
}
|
||||
user.intent.getClient().setPresence({presence: status})
|
||||
break
|
||||
case "updateUserTyping":
|
||||
console.log(update.user_id, "is typing in a 1-1 chat")
|
||||
@@ -223,14 +233,14 @@ class TelegramPuppet {
|
||||
console.log(update.user_id, "is typing in", update.chat_id)
|
||||
break
|
||||
case "updateShortMessage":
|
||||
this.handleMessage({
|
||||
await this.handleMessage({
|
||||
from: this.app.getTelegramUser(update.user_id),
|
||||
to: new TelegramPeer("user", update.user_id),
|
||||
text: update.message,
|
||||
})
|
||||
break
|
||||
case "updateShortChatMessage":
|
||||
this.handleMessage({
|
||||
await this.handleMessage({
|
||||
from: this.app.getTelegramUser(update.user_id),
|
||||
to: new TelegramPeer("chat", update.chat_id),
|
||||
text: update.message,
|
||||
@@ -238,7 +248,7 @@ class TelegramPuppet {
|
||||
break
|
||||
case "updateNewMessage":
|
||||
update = update.message // Message defined at message#90dddc11 in layer 71
|
||||
this.handleMessage({
|
||||
await this.handleMessage({
|
||||
from: update.from_id,
|
||||
to: TelegramPeer.fromTelegramData(update.to_id),
|
||||
text: update.message,
|
||||
|
||||
@@ -67,7 +67,7 @@ class TelegramUser {
|
||||
}
|
||||
}
|
||||
|
||||
async updateInfo(telegramPOV, user) {
|
||||
async updateInfo(telegramPOV, user, dontUpdateAvatar) {
|
||||
let changed = false
|
||||
if (this.firstName !== user.first_name) {
|
||||
this.firstName = user.first_name
|
||||
@@ -81,9 +81,6 @@ class TelegramUser {
|
||||
this.username = user.username
|
||||
changed = true
|
||||
}
|
||||
if (await this.updateAvatarImageFrom(telegramPOV, user)) {
|
||||
changed = true
|
||||
}
|
||||
if (telegramPOV && this.accessHashes.get(telegramPOV.userID) !== user.access_hash) {
|
||||
this.accessHashes.set(telegramPOV.userID, user.access_hash)
|
||||
changed = true
|
||||
@@ -96,6 +93,9 @@ class TelegramUser {
|
||||
this.app.config.bridge.displayname_template.replace("${DISPLAYNAME}", this.getDisplayName()))
|
||||
console.log((await this.intent.getProfileInfo(this.mxid, "displayname")).displayname)
|
||||
}
|
||||
if (!dontUpdateAvatar && this.updateAvatarImageFrom(telegramPOV, user)) {
|
||||
changed = true
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
this.save()
|
||||
|
||||
Reference in New Issue
Block a user