mirror of
https://github.com/zhigang1992/mtcute.git
synced 2026-01-12 22:49:02 +08:00
fix(core)!: never return access_hash=0 for bots
This commit is contained in:
@@ -140,7 +140,7 @@ describe('resolvePeer', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should return with zero hash for bots if not in storage', async () => {
|
||||
it.skip('should return with zero hash for bots if not in storage', async () => {
|
||||
const client = StubTelegramClient.offline()
|
||||
|
||||
await client.storage.self.storeFrom(createStub('user', {
|
||||
@@ -227,7 +227,7 @@ describe('resolvePeer', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should return with zero hash for bots if not in storage', async () => {
|
||||
it.skip('should return with zero hash for bots if not in storage', async () => {
|
||||
const client = StubTelegramClient.offline()
|
||||
|
||||
await client.storage.self.storeFrom(createStub('user', {
|
||||
|
||||
@@ -157,30 +157,38 @@ export async function resolvePeer(
|
||||
throw new MtPeerNotFoundError(`Could not find a peer by ${peerId}`)
|
||||
}
|
||||
|
||||
// in some cases, the server allows bots to use access_hash=0.
|
||||
// if it's not the case, we'll get an `PEER_ID_INVALID` error anyways
|
||||
const [peerType, bareId] = parseMarkedPeerId(peerId)
|
||||
|
||||
if (peerType === 'chat' || client.storage.self.getCached(true)?.isBot) {
|
||||
// bots can use access_hash=0 in most of the cases
|
||||
switch (peerType) {
|
||||
case 'user':
|
||||
return {
|
||||
_: 'inputPeerUser',
|
||||
userId: bareId,
|
||||
accessHash: Long.ZERO,
|
||||
}
|
||||
case 'chat':
|
||||
return {
|
||||
_: 'inputPeerChat',
|
||||
chatId: bareId,
|
||||
}
|
||||
case 'channel':
|
||||
return {
|
||||
_: 'inputPeerChannel',
|
||||
channelId: bareId,
|
||||
accessHash: Long.ZERO,
|
||||
}
|
||||
// in some cases, the server allows bots to use access_hash=0.
|
||||
// however in some cases it fails with PEER_ID_INVALID/CHANNEL_INVALID,
|
||||
// and currently we don't have a way to gracefully handle those, so just resolve them right away
|
||||
// (todo: handle those errors)
|
||||
// if (peerType === 'chat' || client.storage.self.getCached(true)?.isBot) {
|
||||
// // bots can use access_hash=0 in most of the cases
|
||||
// switch (peerType) {
|
||||
// case 'user':
|
||||
// return {
|
||||
// _: 'inputPeerUser',
|
||||
// userId: bareId,
|
||||
// accessHash: Long.ZERO,
|
||||
// }
|
||||
// case 'chat':
|
||||
// return {
|
||||
// _: 'inputPeerChat',
|
||||
// chatId: bareId,
|
||||
// }
|
||||
// case 'channel':
|
||||
// return {
|
||||
// _: 'inputPeerChannel',
|
||||
// channelId: bareId,
|
||||
// accessHash: Long.ZERO,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if (peerType === 'chat') {
|
||||
return {
|
||||
_: 'inputPeerChat',
|
||||
chatId: bareId,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user