Skip to content

Commit

Permalink
Handle pts errors
Browse files Browse the repository at this point in the history
  • Loading branch information
roj1512 committed May 19, 2024
1 parent 50369dc commit 6baee4d
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions client/2_update_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import { unreachable } from "../0_deps.ts";
import { getLogger, Logger, Queue, ZERO_CHANNEL_ID } from "../1_utilities.ts";
import { Api, as, inputPeerToPeer, is, isOfEnum, isOneOf, peerToChatId, ReadObject } from "../2_tl.ts";
import { PersistentTimestampEmpty, PersistentTimestampInvalid } from "../3_errors.ts";
import { CHANNEL_DIFFERENCE_LIMIT_BOT, CHANNEL_DIFFERENCE_LIMIT_USER } from "../4_constants.ts";
import { C } from "./1_types.ts";

Expand Down Expand Up @@ -632,9 +633,22 @@ export class UpdateManager {

this.#c.setConnectionState("updating");
try {
let tries = 0;
let state = await this.#getLocalState();
while (true) {
const difference = await this.#c.invoke({ _: "updates.getDifference", pts: state.pts, date: state.date, qts: state.qts ?? 0 });
let difference: Api.updates_Difference;
try {
difference = await this.#c.invoke({ _: "updates.getDifference", pts: state.pts, date: state.date, qts: state.qts ?? 0 });
} catch (err) {
if (err instanceof PersistentTimestampEmpty || err instanceof PersistentTimestampInvalid && tries <= 5) {
await this.fetchState(err.errorMessage);
state = await this.#getLocalState();
++tries;
continue;
} else {
throw err;
}
}
if (is("updates.difference", difference) || is("updates.differenceSlice", difference)) {
await this.processChats(difference.chats);
await this.processUsers(difference.users);
Expand Down Expand Up @@ -675,16 +689,30 @@ export class UpdateManager {
async #recoverChannelUpdateGap(channelId: bigint, source: string) {
this.#LrecoverChannelUpdateGap.debug(`recovering channel update gap [${channelId}, ${source}]`);
const pts_ = await this.#c.storage.getChannelPts(channelId);
let tries = 0;
let pts = pts_ == null ? 1 : pts_;
while (true) {
const { access_hash } = await this.#c.getInputPeer(ZERO_CHANNEL_ID + -Number(channelId)).then((v) => as("inputPeerChannel", v));
const difference = await this.#c.invoke({
_: "updates.getChannelDifference",
pts,
channel: { _: "inputChannel", channel_id: channelId, access_hash },
filter: { _: "channelMessagesFilterEmpty" },
limit: await this.#c.storage.getAccountType() == "user" ? CHANNEL_DIFFERENCE_LIMIT_USER : CHANNEL_DIFFERENCE_LIMIT_BOT,
});
let difference: Api.updates_Difference;

try {
difference = await this.#c.invoke({
_: "updates.getChannelDifference",
pts,
channel: { _: "inputChannel", channel_id: channelId, access_hash },
filter: { _: "channelMessagesFilterEmpty" },
limit: await this.#c.storage.getAccountType() == "user" ? CHANNEL_DIFFERENCE_LIMIT_USER : CHANNEL_DIFFERENCE_LIMIT_BOT,
});
} catch (err) {
if (err instanceof PersistentTimestampEmpty || err instanceof PersistentTimestampInvalid && tries <= 5) {
pts = 1;
++tries;
continue;
} else {
throw err;
}
}

if (is("updates.channelDifference", difference)) {
await this.processChats(difference.chats);
await this.processUsers(difference.users);
Expand Down

0 comments on commit 6baee4d

Please sign in to comment.