feat(client): allow disabling updates manager
This commit is contained in:
parent
2815567330
commit
c278599612
3 changed files with 52 additions and 5 deletions
|
@ -346,6 +346,25 @@ interface TelegramClientOptions extends Omit<BaseTelegramClientOptions, 'storage
|
||||||
* Parameters for updates manager.
|
* Parameters for updates manager.
|
||||||
*/
|
*/
|
||||||
updates?: Omit<ParsedUpdateHandlerParams & UpdatesManagerParams, 'onUpdate' | 'onRawUpdate'>
|
updates?: Omit<ParsedUpdateHandlerParams & UpdatesManagerParams, 'onUpdate' | 'onRawUpdate'>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* **ADVANCED**
|
||||||
|
*
|
||||||
|
* If set to `true`, updates manager will not be created,
|
||||||
|
* and only raw TL Updates will be emitted.
|
||||||
|
*
|
||||||
|
* Unlike {@link TelegramClientOptions.disableUpdates}, this
|
||||||
|
* does not prevent the updates from being sent by the server,
|
||||||
|
* but disables proper handling of them (see [Working with Updates](https://core.telegram.org/api/updates))
|
||||||
|
*
|
||||||
|
* This may be useful in some cases when you require more control over
|
||||||
|
* the updates or to minimize additional overhead from properly handling them
|
||||||
|
* for some very particular use cases.
|
||||||
|
*
|
||||||
|
* The updates **will not** be dispatched the normal way, instead
|
||||||
|
* you should manually add a handler using `client.network.setUpdateHandler`.
|
||||||
|
*/
|
||||||
|
disableUpdatesManager?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TelegramClient extends BaseTelegramClient {
|
export interface TelegramClient extends BaseTelegramClient {
|
||||||
|
@ -5206,6 +5225,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
export type { TelegramClientOptions }
|
export type { TelegramClientOptions }
|
||||||
|
|
||||||
export class TelegramClient extends BaseTelegramClient {
|
export class TelegramClient extends BaseTelegramClient {
|
||||||
|
protected _disableUpdatesManager: boolean
|
||||||
constructor(opts: TelegramClientOptions) {
|
constructor(opts: TelegramClientOptions) {
|
||||||
if (typeof opts.storage === 'string') {
|
if (typeof opts.storage === 'string') {
|
||||||
opts.storage = _defaultStorageFactory(opts.storage)
|
opts.storage = _defaultStorageFactory(opts.storage)
|
||||||
|
@ -5216,9 +5236,10 @@ export class TelegramClient extends BaseTelegramClient {
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||||
// @ts-expect-error codegen
|
// @ts-expect-error codegen
|
||||||
super(opts)
|
super(opts)
|
||||||
|
|
||||||
/* eslint-enable @typescript-eslint/no-unsafe-call */
|
/* eslint-enable @typescript-eslint/no-unsafe-call */
|
||||||
if (!opts.disableUpdates) {
|
this._disableUpdatesManager = opts.disableUpdatesManager ?? false
|
||||||
|
|
||||||
|
if (!opts.disableUpdates && !opts.disableUpdatesManager) {
|
||||||
const { messageGroupingInterval, ...managerParams } = opts.updates ?? {}
|
const { messageGroupingInterval, ...managerParams } = opts.updates ?? {}
|
||||||
|
|
||||||
enableUpdatesProcessing(this, {
|
enableUpdatesProcessing(this, {
|
||||||
|
@ -6239,7 +6260,7 @@ TelegramClient.prototype.start =
|
||||||
async function _start(this: TelegramClient, params: Parameters<typeof start>[1]) {
|
async function _start(this: TelegramClient, params: Parameters<typeof start>[1]) {
|
||||||
const user = await start(this, params)
|
const user = await start(this, params)
|
||||||
|
|
||||||
if (!this.network.params.disableUpdates) {
|
if (!this.network.params.disableUpdates && !this._disableUpdatesManager) {
|
||||||
await this.startUpdatesLoop()
|
await this.startUpdatesLoop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,11 @@ import {
|
||||||
UpdatesManagerParams,
|
UpdatesManagerParams,
|
||||||
} from './updates/index.js'
|
} from './updates/index.js'
|
||||||
|
|
||||||
|
// @extension
|
||||||
|
interface TelegramClientExt {
|
||||||
|
_disableUpdatesManager: boolean
|
||||||
|
}
|
||||||
|
|
||||||
// @copy
|
// @copy
|
||||||
interface TelegramClientOptions extends Omit<BaseTelegramClientOptions, 'storage'> {
|
interface TelegramClientOptions extends Omit<BaseTelegramClientOptions, 'storage'> {
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +39,25 @@ interface TelegramClientOptions extends Omit<BaseTelegramClientOptions, 'storage
|
||||||
* Parameters for updates manager.
|
* Parameters for updates manager.
|
||||||
*/
|
*/
|
||||||
updates?: Omit<ParsedUpdateHandlerParams & UpdatesManagerParams, 'onUpdate' | 'onRawUpdate'>
|
updates?: Omit<ParsedUpdateHandlerParams & UpdatesManagerParams, 'onUpdate' | 'onRawUpdate'>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* **ADVANCED**
|
||||||
|
*
|
||||||
|
* If set to `true`, updates manager will not be created,
|
||||||
|
* and only raw TL Updates will be emitted.
|
||||||
|
*
|
||||||
|
* Unlike {@link TelegramClientOptions.disableUpdates}, this
|
||||||
|
* does not prevent the updates from being sent by the server,
|
||||||
|
* but disables proper handling of them (see [Working with Updates](https://core.telegram.org/api/updates))
|
||||||
|
*
|
||||||
|
* This may be useful in some cases when you require more control over
|
||||||
|
* the updates or to minimize additional overhead from properly handling them
|
||||||
|
* for some very particular use cases.
|
||||||
|
*
|
||||||
|
* The updates **will not** be dispatched the normal way, instead
|
||||||
|
* you should manually add a handler using `client.network.setUpdateHandler`.
|
||||||
|
*/
|
||||||
|
disableUpdatesManager?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
// @initialize=super
|
// @initialize=super
|
||||||
|
@ -54,7 +78,9 @@ function _initializeClientSuper(this: TelegramClient, opts: TelegramClientOption
|
||||||
// @initialize
|
// @initialize
|
||||||
/** @internal */
|
/** @internal */
|
||||||
function _initializeClient(this: TelegramClient, opts: TelegramClientOptions) {
|
function _initializeClient(this: TelegramClient, opts: TelegramClientOptions) {
|
||||||
if (!opts.disableUpdates) {
|
this._disableUpdatesManager = opts.disableUpdatesManager ?? false
|
||||||
|
|
||||||
|
if (!opts.disableUpdates && !opts.disableUpdatesManager) {
|
||||||
const { messageGroupingInterval, ...managerParams } = opts.updates ?? {}
|
const { messageGroupingInterval, ...managerParams } = opts.updates ?? {}
|
||||||
|
|
||||||
enableUpdatesProcessing(this, {
|
enableUpdatesProcessing(this, {
|
||||||
|
|
|
@ -217,7 +217,7 @@ export async function start(
|
||||||
async function _start(this: TelegramClient, params: Parameters<typeof start>[1]) {
|
async function _start(this: TelegramClient, params: Parameters<typeof start>[1]) {
|
||||||
const user = await start(this, params)
|
const user = await start(this, params)
|
||||||
|
|
||||||
if (!this.network.params.disableUpdates) {
|
if (!this.network.params.disableUpdates && !this._disableUpdatesManager) {
|
||||||
await this.startUpdatesLoop()
|
await this.startUpdatesLoop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue