Browse Source

Fix flood wait list loading stuck

master
morethanwords 4 years ago
parent
commit
043bdeedb0
  1. 20
      src/lib/appManagers/appImManager.ts
  2. 9
      src/lib/appManagers/appMessagesManager.ts
  3. 3
      src/lib/mtproto/apiManager.ts

20
src/lib/appManagers/appImManager.ts

@ -2355,7 +2355,14 @@ export class AppImManager { @@ -2355,7 +2355,14 @@ export class AppImManager {
});
}
// reverse means scroll up
/**
* Load and render history
* @param maxID max message id
* @param reverse 'true' means up
* @param isBackLimit is search
* @param additionMsgID for the last message
* @param justLoad do not render
*/
public getHistory(maxID = 0, reverse = false, isBackLimit = false, additionMsgID = 0, justLoad = false): {cached: boolean, promise: Promise<boolean>} {
const peerID = this.peerID;
@ -2390,14 +2397,14 @@ export class AppImManager { @@ -2390,14 +2397,14 @@ export class AppImManager {
cached = false;
promise = result.then((result) => {
this.log('getHistory not cached result by maxID:', maxID, reverse, isBackLimit, result, peerID, justLoad);
if(justLoad) {
this.scrollable.onScroll(); // нужно делать из-за ранней прогрузки
return true;
}
//console.timeEnd('appImManager call getHistory');
if(this.peerID != peerID) {
if(this.peerID != peerID || (this.getHistoryTopPromise != promise && this.getHistoryBottomPromise != promise)) {
this.log.warn('peer changed');
////console.timeEnd('render history total');
return Promise.reject();
@ -2453,12 +2460,17 @@ export class AppImManager { @@ -2453,12 +2460,17 @@ export class AppImManager {
//ids = ids.slice(removeCount * 2);
ids = ids.slice(safeCount);
this.scrolledAllDown = false;
this.log('getHistory: slice bottom messages:', ids.length, loadCount);
this.getHistoryBottomPromise = undefined; // !WARNING, это нужно для обратной загрузки истории, если запрос словил флуд
} else {
//ids = ids.slice(0, removeCount);
//ids = ids.slice(0, ids.length - (removeCount * 2));
ids = ids.slice(0, ids.length - safeCount);
this.scrolledAll = false;
this.log('getHistory: slice bottom: to:', ids.length, loadCount);
this.log('getHistory: slice up messages:', ids.length, loadCount);
this.getHistoryTopPromise = undefined; // !WARNING, это нужно для обратной загрузки истории, если запрос словил флуд
}
this.log('getHistory: will slice ids:', ids, reverse);

9
src/lib/appManagers/appMessagesManager.ts

@ -1871,7 +1871,8 @@ export class AppMessagesManager { @@ -1871,7 +1871,8 @@ export class AppMessagesManager {
limit: limit,
hash: 0
}, {
timeout: APITIMEOUT
//timeout: APITIMEOUT,
noErrorBox: true
}).then((dialogsResult) => {
///////this.log('messages.getDialogs result:', dialogsResult);
@ -2968,7 +2969,7 @@ export class AppMessagesManager { @@ -2968,7 +2969,7 @@ export class AppMessagesManager {
min_id: 0,
hash: 0
}, {
timeout: APITIMEOUT,
//timeout: APITIMEOUT,
noErrorBox: true
});
} else {
@ -2991,7 +2992,7 @@ export class AppMessagesManager { @@ -2991,7 +2992,7 @@ export class AppMessagesManager {
offset_id: appMessagesIDsManager.getMessageLocalID(offsetID),
limit: limit || 20
}, {
timeout: APITIMEOUT,
//timeout: APITIMEOUT,
noErrorBox: true
});
}
@ -4195,7 +4196,7 @@ export class AppMessagesManager { @@ -4195,7 +4196,7 @@ export class AppMessagesManager {
min_id: 0,
hash: 0
}, {
timeout: APITIMEOUT,
//timeout: APITIMEOUT,
noErrorBox: true
}).then((historyResult: any) => {
this.log('requestHistory result:', historyResult, maxID, limit, offset);

3
src/lib/mtproto/apiManager.ts

@ -16,6 +16,7 @@ import { InvokeApiOptions } from '../../types'; @@ -16,6 +16,7 @@ import { InvokeApiOptions } from '../../types';
/// #endif
//console.error('apiManager included!');
// TODO: если запрос словил флуд, нужно сохранять его параметры и возвращать тот же промис на новый такой же запрос, например - загрузка истории
export class ApiManager {
public cachedNetworkers: {[x: number]: MTPNetworker} = {};
@ -290,7 +291,7 @@ export class ApiManager { @@ -290,7 +291,7 @@ export class ApiManager {
setTimeout(() => {
performRequest(cachedNetworker);
}, (waitTime + 5) * 1000); // 03.02.2020
}, waitTime/* (waitTime + 5) */ * 1000); // 03.02.2020
} else if(!options.rawError && (error.code == 500 || error.type == 'MSG_WAIT_FAILED')) {
var now = Date.now();
if(options.stopTime) {

Loading…
Cancel
Save