Compare commits

..

No commits in common. "6c9391dfa5dd14c550788d9f12dabe9afc6ccbac" and "13376179d6944f8042b5fc0abf07f559f4c413de" have entirely different histories.

4 changed files with 36 additions and 26 deletions

View file

@ -4,6 +4,7 @@ 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'
@ -151,6 +152,7 @@ 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(
@ -179,7 +181,7 @@ export class UpdatesManager {
this._channelPtsLimit = () => limit this._channelPtsLimit = () => limit
} }
} else { } else {
this._channelPtsLimit = () => (this.client.storage.self.getCached()?.isBot ? 100000 : 100) this._channelPtsLimit = () => (this.auth?.isBot ? 100000 : 100)
} }
} }
@ -191,7 +193,8 @@ export class UpdatesManager {
this.stopLoop() this.stopLoop()
} }
notifyLoggedIn(): void { notifyLoggedIn(self: CurrentUserInfo): void {
this.auth = self
this.startLoop().catch(err => this.client.onError.emit(unknownToError(err))) this.startLoop().catch(err => this.client.onError.emit(unknownToError(err)))
} }
@ -1264,7 +1267,7 @@ export class UpdatesManager {
// } // }
break break
case 'updateDeleteChannelMessages': case 'updateDeleteChannelMessages':
if (!client.storage.self.getCached()?.isBot) { if (!this.auth?.isBot) {
await client.storage.refMsgs.delete(toggleChannelIdMark(upd.channelId), upd.messages) await client.storage.refMsgs.delete(toggleChannelIdMark(upd.channelId), upd.messages)
} }
break break
@ -1272,14 +1275,14 @@ export class UpdatesManager {
case 'updateEditMessage': case 'updateEditMessage':
case 'updateNewChannelMessage': case 'updateNewChannelMessage':
case 'updateEditChannelMessage': case 'updateEditChannelMessage':
if (!client.storage.self.getCached()?.isBot) { if (!this.auth?.isBot) {
await this._storeMessageReferences(upd.message) await this._storeMessageReferences(upd.message)
} }
break break
} }
if (missing?.size) { if (missing?.size) {
if (client.storage.self.getCached()?.isBot) { if (this.auth?.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,
@ -1510,11 +1513,6 @@ 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',
@ -1525,7 +1523,7 @@ export class UpdatesManager {
id: upd.id, id: upd.id,
fromId: { fromId: {
_: 'peerUser', _: 'peerUser',
userId: upd.out ? self.userId : upd.userId, userId: upd.out ? this.auth!.userId : upd.userId,
}, },
peerId: { peerId: {
_: 'peerUser', _: 'peerUser',

View file

@ -13,6 +13,6 @@
}, },
"dependencies": { "dependencies": {
"@mtcute/tl-runtime": "workspace:^", "@mtcute/tl-runtime": "workspace:^",
"crc": "4.3.2" "crc-32": "1.2.0"
} }
} }

View file

@ -1,6 +1,6 @@
import type { TlEntry } from './types.js' import type { TlEntry } from './types.js'
import crc32 from 'crc/calculators/crc32' import CRC32 from 'crc-32'
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(new TextEncoder().encode(str)) >>> 0 return CRC32.str(str) >>> 0
} }

View file

@ -478,9 +478,9 @@ importers:
'@mtcute/tl-runtime': '@mtcute/tl-runtime':
specifier: workspace:^ specifier: workspace:^
version: link:../tl-runtime version: link:../tl-runtime
crc: crc-32:
specifier: 4.3.2 specifier: 1.2.0
version: 4.3.2 version: 1.2.0
packages/wasm: packages/wasm:
devDependencies: devDependencies:
@ -2046,14 +2046,10 @@ packages:
core-util-is@1.0.3: core-util-is@1.0.3:
resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
crc@4.3.2: crc-32@1.2.0:
resolution: {integrity: sha512-uGDHf4KLLh2zsHa8D8hIQ1H/HtFQhyHrc0uhHBcoKGol/Xnb+MPYfUMw7cvON6ze/GUESTudKayDcJC5HnJv1A==} resolution: {integrity: sha512-1uBwHxF+Y/4yF5G48fwnKq6QsIXheor3ZLPT80yGBV1oEUwpPojlEhQbWKVw1VwcTQyMGHK1/XMmTjmlsmTTGA==}
engines: {node: '>=12'} engines: {node: '>=0.8'}
peerDependencies: hasBin: true
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==}
@ -2497,6 +2493,10 @@ 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,6 +3462,11 @@ 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==}
@ -5752,7 +5757,10 @@ snapshots:
core-util-is@1.0.3: {} core-util-is@1.0.3: {}
crc@4.3.2: {} crc-32@1.2.0:
dependencies:
exit-on-epipe: 1.0.1
printj: 1.1.2
create-ecdh@4.0.4: create-ecdh@4.0.4:
dependencies: dependencies:
@ -6388,6 +6396,8 @@ 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:
@ -7575,6 +7585,8 @@ 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: {}