Compare commits

..

2 commits

Author SHA1 Message Date
6c9391dfa5
fix(core): handle no auth case in updates manager + slight refactor
Some checks failed
Tests / lint (push) Failing after 1m29s
Tests / test-deno (push) Successful in 1m38s
Tests / test-node (node18) (push) Successful in 1m49s
Tests / test-node (node22) (push) Successful in 1m45s
Tests / test-node (node20) (push) Successful in 1m49s
Tests / test-bun (push) Successful in 1m47s
Tests / test-web (firefox) (push) Successful in 1m56s
Build and deploy typedoc / build (push) Failing after 4m41s
Tests / test-web (chromium) (push) Successful in 48s
Tests / e2e (push) Has been skipped
Tests / e2e-deno (push) Has been skipped
2025-01-20 15:16:54 +03:00
424245eefc
chore(tl-utils): crc-32 -> crc 2025-01-20 10:49:06 +03:00
4 changed files with 26 additions and 36 deletions

View file

@ -4,7 +4,6 @@ import type {
} from '../../utils/index.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 { tl } from '@mtcute/tl'
import Long from 'long'
@ -152,7 +151,6 @@ export class UpdatesManager {
// eslint-disable-next-line ts/no-unsafe-function-type
private _channelPtsLimit: Extract<UpdatesManagerParams['channelPtsLimit'], Function>
auth?: CurrentUserInfo | null // todo: do we need a local copy?
keepAliveInterval?: timers.Interval
constructor(
@ -181,7 +179,7 @@ export class UpdatesManager {
this._channelPtsLimit = () => limit
}
} 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()
}
notifyLoggedIn(self: CurrentUserInfo): void {
this.auth = self
notifyLoggedIn(): void {
this.startLoop().catch(err => this.client.onError.emit(unknownToError(err)))
}
@ -1267,7 +1264,7 @@ export class UpdatesManager {
// }
break
case 'updateDeleteChannelMessages':
if (!this.auth?.isBot) {
if (!client.storage.self.getCached()?.isBot) {
await client.storage.refMsgs.delete(toggleChannelIdMark(upd.channelId), upd.messages)
}
break
@ -1275,14 +1272,14 @@ export class UpdatesManager {
case 'updateEditMessage':
case 'updateNewChannelMessage':
case 'updateEditChannelMessage':
if (!this.auth?.isBot) {
if (!client.storage.self.getCached()?.isBot) {
await this._storeMessageReferences(upd.message)
}
break
}
if (missing?.size) {
if (this.auth?.isBot) {
if (client.storage.self.getCached()?.isBot) {
this.log.warn(
'missing peers (%J) after getDifference for %s (pts = %d, cid = %d)',
missing,
@ -1513,6 +1510,11 @@ export class UpdatesManager {
}
case 'updateShortMessage': {
log.debug('received updateShortMessage')
const self = client.storage.self.getCached()
if (!self) {
log.warn('received updateShortMessage without auth')
break
}
const message: tl.RawMessage = {
_: 'message',
@ -1523,7 +1525,7 @@ export class UpdatesManager {
id: upd.id,
fromId: {
_: 'peerUser',
userId: upd.out ? this.auth!.userId : upd.userId,
userId: upd.out ? self.userId : upd.userId,
},
peerId: {
_: 'peerUser',

View file

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

View file

@ -1,6 +1,6 @@
import type { TlEntry } from './types.js'
import CRC32 from 'crc-32'
import crc32 from 'crc/calculators/crc32'
import { writeTlEntryToString } from './stringify.js'
/**
@ -11,5 +11,5 @@ import { writeTlEntryToString } from './stringify.js'
export function computeConstructorIdFromEntry(entry: TlEntry): number {
const str = writeTlEntryToString(entry, true)
return CRC32.str(str) >>> 0
return crc32(new TextEncoder().encode(str)) >>> 0
}

View file

@ -478,9 +478,9 @@ importers:
'@mtcute/tl-runtime':
specifier: workspace:^
version: link:../tl-runtime
crc-32:
specifier: 1.2.0
version: 1.2.0
crc:
specifier: 4.3.2
version: 4.3.2
packages/wasm:
devDependencies:
@ -2046,10 +2046,14 @@ packages:
core-util-is@1.0.3:
resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
crc-32@1.2.0:
resolution: {integrity: sha512-1uBwHxF+Y/4yF5G48fwnKq6QsIXheor3ZLPT80yGBV1oEUwpPojlEhQbWKVw1VwcTQyMGHK1/XMmTjmlsmTTGA==}
engines: {node: '>=0.8'}
hasBin: true
crc@4.3.2:
resolution: {integrity: sha512-uGDHf4KLLh2zsHa8D8hIQ1H/HtFQhyHrc0uhHBcoKGol/Xnb+MPYfUMw7cvON6ze/GUESTudKayDcJC5HnJv1A==}
engines: {node: '>=12'}
peerDependencies:
buffer: '>=6.0.3'
peerDependenciesMeta:
buffer:
optional: true
create-ecdh@4.0.4:
resolution: {integrity: sha512-mf+TCx8wWc9VpuxfP2ht0iSISLZnt0JgWlrOKZiNqyUZWnjIaCIVNQArMHnCZKfEYRg6IM7A+NeJoN8gf/Ws0A==}
@ -2493,10 +2497,6 @@ packages:
resolution: {integrity: sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==}
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:
resolution: {integrity: sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==}
engines: {node: '>=6'}
@ -3462,11 +3462,6 @@ packages:
resolution: {integrity: sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==}
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:
resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==}
@ -5757,10 +5752,7 @@ snapshots:
core-util-is@1.0.3: {}
crc-32@1.2.0:
dependencies:
exit-on-epipe: 1.0.1
printj: 1.1.2
crc@4.3.2: {}
create-ecdh@4.0.4:
dependencies:
@ -6396,8 +6388,6 @@ snapshots:
signal-exit: 4.1.0
strip-final-newline: 3.0.0
exit-on-epipe@1.0.1: {}
expand-template@2.0.3: {}
external-editor@3.1.0:
@ -7585,8 +7575,6 @@ snapshots:
ansi-styles: 5.2.0
react-is: 17.0.2
printj@1.1.2: {}
process-nextick-args@2.0.1: {}
process@0.11.10: {}