Compare commits
2 commits
13376179d6
...
6c9391dfa5
Author | SHA1 | Date | |
---|---|---|---|
6c9391dfa5 | |||
424245eefc |
4 changed files with 26 additions and 36 deletions
|
@ -4,7 +4,6 @@ import type {
|
||||||
} from '../../utils/index.js'
|
} from '../../utils/index.js'
|
||||||
import type { BaseTelegramClient } from '../base.js'
|
import type { BaseTelegramClient } from '../base.js'
|
||||||
|
|
||||||
import type { CurrentUserInfo } from '../storage/service/current-user.js'
|
|
||||||
import { AsyncLock, ConditionVariable, Deque, timers, unknownToError } from '@fuman/utils'
|
import { AsyncLock, ConditionVariable, Deque, timers, unknownToError } from '@fuman/utils'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import Long from 'long'
|
import Long from 'long'
|
||||||
|
@ -152,7 +151,6 @@ export class UpdatesManager {
|
||||||
// eslint-disable-next-line ts/no-unsafe-function-type
|
// eslint-disable-next-line ts/no-unsafe-function-type
|
||||||
private _channelPtsLimit: Extract<UpdatesManagerParams['channelPtsLimit'], Function>
|
private _channelPtsLimit: Extract<UpdatesManagerParams['channelPtsLimit'], Function>
|
||||||
|
|
||||||
auth?: CurrentUserInfo | null // todo: do we need a local copy?
|
|
||||||
keepAliveInterval?: timers.Interval
|
keepAliveInterval?: timers.Interval
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -181,7 +179,7 @@ export class UpdatesManager {
|
||||||
this._channelPtsLimit = () => limit
|
this._channelPtsLimit = () => limit
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this._channelPtsLimit = () => (this.auth?.isBot ? 100000 : 100)
|
this._channelPtsLimit = () => (this.client.storage.self.getCached()?.isBot ? 100000 : 100)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,8 +191,7 @@ export class UpdatesManager {
|
||||||
this.stopLoop()
|
this.stopLoop()
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyLoggedIn(self: CurrentUserInfo): void {
|
notifyLoggedIn(): void {
|
||||||
this.auth = self
|
|
||||||
this.startLoop().catch(err => this.client.onError.emit(unknownToError(err)))
|
this.startLoop().catch(err => this.client.onError.emit(unknownToError(err)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1267,7 +1264,7 @@ export class UpdatesManager {
|
||||||
// }
|
// }
|
||||||
break
|
break
|
||||||
case 'updateDeleteChannelMessages':
|
case 'updateDeleteChannelMessages':
|
||||||
if (!this.auth?.isBot) {
|
if (!client.storage.self.getCached()?.isBot) {
|
||||||
await client.storage.refMsgs.delete(toggleChannelIdMark(upd.channelId), upd.messages)
|
await client.storage.refMsgs.delete(toggleChannelIdMark(upd.channelId), upd.messages)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
@ -1275,14 +1272,14 @@ export class UpdatesManager {
|
||||||
case 'updateEditMessage':
|
case 'updateEditMessage':
|
||||||
case 'updateNewChannelMessage':
|
case 'updateNewChannelMessage':
|
||||||
case 'updateEditChannelMessage':
|
case 'updateEditChannelMessage':
|
||||||
if (!this.auth?.isBot) {
|
if (!client.storage.self.getCached()?.isBot) {
|
||||||
await this._storeMessageReferences(upd.message)
|
await this._storeMessageReferences(upd.message)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if (missing?.size) {
|
if (missing?.size) {
|
||||||
if (this.auth?.isBot) {
|
if (client.storage.self.getCached()?.isBot) {
|
||||||
this.log.warn(
|
this.log.warn(
|
||||||
'missing peers (%J) after getDifference for %s (pts = %d, cid = %d)',
|
'missing peers (%J) after getDifference for %s (pts = %d, cid = %d)',
|
||||||
missing,
|
missing,
|
||||||
|
@ -1513,6 +1510,11 @@ export class UpdatesManager {
|
||||||
}
|
}
|
||||||
case 'updateShortMessage': {
|
case 'updateShortMessage': {
|
||||||
log.debug('received updateShortMessage')
|
log.debug('received updateShortMessage')
|
||||||
|
const self = client.storage.self.getCached()
|
||||||
|
if (!self) {
|
||||||
|
log.warn('received updateShortMessage without auth')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
const message: tl.RawMessage = {
|
const message: tl.RawMessage = {
|
||||||
_: 'message',
|
_: 'message',
|
||||||
|
@ -1523,7 +1525,7 @@ export class UpdatesManager {
|
||||||
id: upd.id,
|
id: upd.id,
|
||||||
fromId: {
|
fromId: {
|
||||||
_: 'peerUser',
|
_: 'peerUser',
|
||||||
userId: upd.out ? this.auth!.userId : upd.userId,
|
userId: upd.out ? self.userId : upd.userId,
|
||||||
},
|
},
|
||||||
peerId: {
|
peerId: {
|
||||||
_: 'peerUser',
|
_: 'peerUser',
|
||||||
|
|
|
@ -13,6 +13,6 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mtcute/tl-runtime": "workspace:^",
|
"@mtcute/tl-runtime": "workspace:^",
|
||||||
"crc-32": "1.2.0"
|
"crc": "4.3.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import type { TlEntry } from './types.js'
|
import type { TlEntry } from './types.js'
|
||||||
|
|
||||||
import CRC32 from 'crc-32'
|
import crc32 from 'crc/calculators/crc32'
|
||||||
import { writeTlEntryToString } from './stringify.js'
|
import { writeTlEntryToString } from './stringify.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,5 +11,5 @@ import { writeTlEntryToString } from './stringify.js'
|
||||||
export function computeConstructorIdFromEntry(entry: TlEntry): number {
|
export function computeConstructorIdFromEntry(entry: TlEntry): number {
|
||||||
const str = writeTlEntryToString(entry, true)
|
const str = writeTlEntryToString(entry, true)
|
||||||
|
|
||||||
return CRC32.str(str) >>> 0
|
return crc32(new TextEncoder().encode(str)) >>> 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -478,9 +478,9 @@ importers:
|
||||||
'@mtcute/tl-runtime':
|
'@mtcute/tl-runtime':
|
||||||
specifier: workspace:^
|
specifier: workspace:^
|
||||||
version: link:../tl-runtime
|
version: link:../tl-runtime
|
||||||
crc-32:
|
crc:
|
||||||
specifier: 1.2.0
|
specifier: 4.3.2
|
||||||
version: 1.2.0
|
version: 4.3.2
|
||||||
|
|
||||||
packages/wasm:
|
packages/wasm:
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
@ -2046,10 +2046,14 @@ packages:
|
||||||
core-util-is@1.0.3:
|
core-util-is@1.0.3:
|
||||||
resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
|
resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
|
||||||
|
|
||||||
crc-32@1.2.0:
|
crc@4.3.2:
|
||||||
resolution: {integrity: sha512-1uBwHxF+Y/4yF5G48fwnKq6QsIXheor3ZLPT80yGBV1oEUwpPojlEhQbWKVw1VwcTQyMGHK1/XMmTjmlsmTTGA==}
|
resolution: {integrity: sha512-uGDHf4KLLh2zsHa8D8hIQ1H/HtFQhyHrc0uhHBcoKGol/Xnb+MPYfUMw7cvON6ze/GUESTudKayDcJC5HnJv1A==}
|
||||||
engines: {node: '>=0.8'}
|
engines: {node: '>=12'}
|
||||||
hasBin: true
|
peerDependencies:
|
||||||
|
buffer: '>=6.0.3'
|
||||||
|
peerDependenciesMeta:
|
||||||
|
buffer:
|
||||||
|
optional: true
|
||||||
|
|
||||||
create-ecdh@4.0.4:
|
create-ecdh@4.0.4:
|
||||||
resolution: {integrity: sha512-mf+TCx8wWc9VpuxfP2ht0iSISLZnt0JgWlrOKZiNqyUZWnjIaCIVNQArMHnCZKfEYRg6IM7A+NeJoN8gf/Ws0A==}
|
resolution: {integrity: sha512-mf+TCx8wWc9VpuxfP2ht0iSISLZnt0JgWlrOKZiNqyUZWnjIaCIVNQArMHnCZKfEYRg6IM7A+NeJoN8gf/Ws0A==}
|
||||||
|
@ -2493,10 +2497,6 @@ packages:
|
||||||
resolution: {integrity: sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==}
|
resolution: {integrity: sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==}
|
||||||
engines: {node: '>=16.17'}
|
engines: {node: '>=16.17'}
|
||||||
|
|
||||||
exit-on-epipe@1.0.1:
|
|
||||||
resolution: {integrity: sha512-h2z5mrROTxce56S+pnvAV890uu7ls7f1kEvVGJbw1OlFH3/mlJ5bkXu0KRyW94v37zzHPiUd55iLn3DA7TjWpw==}
|
|
||||||
engines: {node: '>=0.8'}
|
|
||||||
|
|
||||||
expand-template@2.0.3:
|
expand-template@2.0.3:
|
||||||
resolution: {integrity: sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==}
|
resolution: {integrity: sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
|
@ -3462,11 +3462,6 @@ packages:
|
||||||
resolution: {integrity: sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==}
|
resolution: {integrity: sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==}
|
||||||
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
|
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
|
||||||
|
|
||||||
printj@1.1.2:
|
|
||||||
resolution: {integrity: sha512-zA2SmoLaxZyArQTOPj5LXecR+RagfPSU5Kw1qP+jkWeNlrq+eJZyY2oS68SU1Z/7/myXM4lo9716laOFAVStCQ==}
|
|
||||||
engines: {node: '>=0.8'}
|
|
||||||
hasBin: true
|
|
||||||
|
|
||||||
process-nextick-args@2.0.1:
|
process-nextick-args@2.0.1:
|
||||||
resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==}
|
resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==}
|
||||||
|
|
||||||
|
@ -5757,10 +5752,7 @@ snapshots:
|
||||||
|
|
||||||
core-util-is@1.0.3: {}
|
core-util-is@1.0.3: {}
|
||||||
|
|
||||||
crc-32@1.2.0:
|
crc@4.3.2: {}
|
||||||
dependencies:
|
|
||||||
exit-on-epipe: 1.0.1
|
|
||||||
printj: 1.1.2
|
|
||||||
|
|
||||||
create-ecdh@4.0.4:
|
create-ecdh@4.0.4:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -6396,8 +6388,6 @@ snapshots:
|
||||||
signal-exit: 4.1.0
|
signal-exit: 4.1.0
|
||||||
strip-final-newline: 3.0.0
|
strip-final-newline: 3.0.0
|
||||||
|
|
||||||
exit-on-epipe@1.0.1: {}
|
|
||||||
|
|
||||||
expand-template@2.0.3: {}
|
expand-template@2.0.3: {}
|
||||||
|
|
||||||
external-editor@3.1.0:
|
external-editor@3.1.0:
|
||||||
|
@ -7585,8 +7575,6 @@ snapshots:
|
||||||
ansi-styles: 5.2.0
|
ansi-styles: 5.2.0
|
||||||
react-is: 17.0.2
|
react-is: 17.0.2
|
||||||
|
|
||||||
printj@1.1.2: {}
|
|
||||||
|
|
||||||
process-nextick-args@2.0.1: {}
|
process-nextick-args@2.0.1: {}
|
||||||
|
|
||||||
process@0.11.10: {}
|
process@0.11.10: {}
|
||||||
|
|
Loading…
Reference in a new issue