fix(core): handle no auth case in updates manager + slight refactor
All checks were successful
Tests / test-deno (push) Successful in 1m54s
Tests / test-bun (push) Successful in 2m2s
Tests / test-node (node18) (push) Successful in 2m18s
Tests / test-node (node22) (push) Successful in 2m14s
Tests / test-node (node20) (push) Successful in 2m19s
Tests / test-web (chromium) (push) Successful in 2m15s
Tests / test-web (firefox) (push) Successful in 2m27s
Build and deploy typedoc / build (push) Successful in 6m14s
Tests / lint (push) Successful in 6m57s
Tests / e2e-deno (push) Successful in 52s
Tests / e2e (push) Successful in 46s

This commit is contained in:
alina 🌸 2025-01-20 15:16:54 +03:00
parent 424245eefc
commit 016a6dce3f
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
2 changed files with 13 additions and 11 deletions

View file

@ -165,9 +165,9 @@ export class BaseTelegramClient implements ITelegramClient {
const user = this.mt.network.notifyLoggedIn(auth) const user = this.mt.network.notifyLoggedIn(auth)
this.log.prefix = `[USER ${user.id}] ` this.log.prefix = `[USER ${user.id}] `
const self = await this.storage.self.storeFrom(user) await this.storage.self.storeFrom(user)
this.updates?.notifyLoggedIn(self) this.updates?.notifyLoggedIn()
return user return user
} }

View file

@ -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',