Handle private messages to other people from other clients slightly better

This commit is contained in:
Tulir Asokan
2017-12-10 14:12:05 +02:00
parent 5378749624
commit 781aab1c2c
3 changed files with 11 additions and 7 deletions
+2 -2
View File
@@ -13,7 +13,7 @@
"colors": "1.1.x",
"commander": "2.12.x",
"escape-html": "1.0.x",
"file-type": "^7.3.0",
"file-type": "7.4.x",
"marked": "0.3.x",
"matrix-appservice-bridge": "1.x.x",
"matrix-js-sdk": "0.x.x",
@@ -24,7 +24,7 @@
"yamljs": "0.3.x"
},
"devDependencies": {
"eslint": "4.12.x",
"eslint": "4.13.x",
"eslint-config-airbnb-base": "12.1.x",
"eslint-plugin-import": "2.8.x",
"jsdoc": "3.5.x"
+6 -2
View File
@@ -42,10 +42,14 @@ class TelegramPeer {
case "peerChat":
return new TelegramPeer("chat", peer.chat_id)
case "peerUser":
return new TelegramPeer("user", sender, {
const args = {
accessHash: peer.access_hash,
receiverID,
})
}
if (sender === receiverID && peer.user_id !== receiverID) {
return new TelegramPeer("user", peer.user_id, args)
}
return new TelegramPeer("user", sender, args)
case "peerChannel":
return new TelegramPeer("channel", peer.channel_id, {
accessHash: peer.access_hash,
+3 -3
View File
@@ -14,11 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
const telegram = require("telegram-mtproto")
const { nextRandomInt } = require("telegram-mtproto/lib/bin")
const fileType = require("file-type")
const pkg = require("../package.json")
const TelegramPeer = require("./telegram-peer")
/**
* @module telegram-puppet
*/
@@ -254,7 +254,7 @@ class TelegramPuppet {
peer: peer.toInputPeer(),
message,
entities,
random_id: ~~(Math.random() * (1 << 30)),
random_id: [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)],
}
if (!payload.entities) {
// Everything breaks if we send undefined things :/
@@ -271,7 +271,7 @@ class TelegramPuppet {
const result = await this.client("messages.sendMedia", {
peer: peer.toInputPeer(),
media,
random_id: ~~(Math.random() * (1 << 30)),
random_id: [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)],
})
// TODO use result? (maybe the ID)
return result