Possible FILE_REFERENCE_EXPIRED fix
This commit is contained in:
parent
b279abaeb4
commit
7d794758a1
@ -55,6 +55,7 @@ export class AppStickersManager {
|
|||||||
|
|
||||||
if(!this.getGreetingStickersPromise) {
|
if(!this.getGreetingStickersPromise) {
|
||||||
this.getGreetingStickersPromise = this.getStickersByEmoticon('👋⭐️', false).then(docs => {
|
this.getGreetingStickersPromise = this.getStickersByEmoticon('👋⭐️', false).then(docs => {
|
||||||
|
if(!docs.length) throw 'NO_STICKERS';
|
||||||
this.greetingStickers = docs.slice() as Document.document[];
|
this.greetingStickers = docs.slice() as Document.document[];
|
||||||
this.greetingStickers.sort((a, b) => Math.random() - Math.random());
|
this.greetingStickers.sort((a, b) => Math.random() - Math.random());
|
||||||
});
|
});
|
||||||
|
@ -86,7 +86,12 @@ export class ApiFileManager {
|
|||||||
private downloadActives: {[dcId: string]: number} = {};
|
private downloadActives: {[dcId: string]: number} = {};
|
||||||
|
|
||||||
public webpConvertPromises: {[fileName: string]: CancellablePromise<Uint8Array>} = {};
|
public webpConvertPromises: {[fileName: string]: CancellablePromise<Uint8Array>} = {};
|
||||||
public refreshReferencePromises: {[referenceHex: string]: CancellablePromise<ReferenceBytes>} = {};
|
public refreshReferencePromises: {
|
||||||
|
[referenceHex: string]: {
|
||||||
|
deferred: CancellablePromise<ReferenceBytes>,
|
||||||
|
ready: Promise<void>
|
||||||
|
}
|
||||||
|
} = {};
|
||||||
|
|
||||||
private log: ReturnType<typeof logger> = logger('AFM', LogTypes.Error | LogTypes.Log);
|
private log: ReturnType<typeof logger> = logger('AFM', LogTypes.Error | LogTypes.Log);
|
||||||
private tempId = 0;
|
private tempId = 0;
|
||||||
@ -96,7 +101,7 @@ export class ApiFileManager {
|
|||||||
constructor() {
|
constructor() {
|
||||||
setInterval(() => { // clear old promises
|
setInterval(() => { // clear old promises
|
||||||
for(const hex in this.refreshReferencePromises) {
|
for(const hex in this.refreshReferencePromises) {
|
||||||
const deferred = this.refreshReferencePromises[hex];
|
const {deferred} = this.refreshReferencePromises[hex];
|
||||||
if(deferred.isFulfilled || deferred.isRejected) {
|
if(deferred.isFulfilled || deferred.isRejected) {
|
||||||
delete this.refreshReferencePromises[hex];
|
delete this.refreshReferencePromises[hex];
|
||||||
}
|
}
|
||||||
@ -256,29 +261,36 @@ export class ApiFileManager {
|
|||||||
private refreshReference(inputFileLocation: InputFileLocation) {
|
private refreshReference(inputFileLocation: InputFileLocation) {
|
||||||
const reference = (inputFileLocation as InputFileLocation.inputDocumentFileLocation).file_reference;
|
const reference = (inputFileLocation as InputFileLocation.inputDocumentFileLocation).file_reference;
|
||||||
const hex = bytesToHex(reference);
|
const hex = bytesToHex(reference);
|
||||||
let promise = this.refreshReferencePromises[hex];
|
|
||||||
const havePromise = !!promise;
|
|
||||||
|
|
||||||
if(!havePromise) {
|
let r = this.refreshReferencePromises[hex];
|
||||||
promise = deferredPromise<ReferenceBytes>();
|
if(!r) {
|
||||||
this.refreshReferencePromises[hex] = promise;
|
const deferred = deferredPromise<ReferenceBytes>();
|
||||||
}
|
|
||||||
|
|
||||||
promise = promise.then(reference => {
|
r = this.refreshReferencePromises[hex] = {
|
||||||
|
deferred,
|
||||||
|
ready: deferred.then(reference => {
|
||||||
if(hex === bytesToHex(reference)) {
|
if(hex === bytesToHex(reference)) {
|
||||||
throw 'REFERENCE_IS_NOT_REFRESHED';
|
throw 'REFERENCE_IS_NOT_REFRESHED';
|
||||||
}
|
}
|
||||||
|
|
||||||
return (inputFileLocation as InputFileLocation.inputDocumentFileLocation).file_reference = reference;
|
(inputFileLocation as InputFileLocation.inputDocumentFileLocation).file_reference = reference;
|
||||||
});
|
})
|
||||||
|
};
|
||||||
|
|
||||||
if(havePromise) {
|
const timeout = setTimeout(() => {
|
||||||
return promise;
|
this.log.error('Didn\'t refresh the reference:', inputFileLocation);
|
||||||
}
|
deferred.reject('REFERENCE_IS_NOT_REFRESHED');
|
||||||
|
}, 60000);
|
||||||
|
|
||||||
|
deferred.finally(() => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
});
|
||||||
|
|
||||||
const task = {type: 'refreshReference', payload: reference};
|
const task = {type: 'refreshReference', payload: reference};
|
||||||
notifySomeone(task);
|
notifySomeone(task);
|
||||||
return this.refreshReferencePromises[hex] = promise;
|
}
|
||||||
|
|
||||||
|
return r.ready;
|
||||||
}
|
}
|
||||||
|
|
||||||
public downloadFile(options: DownloadOptions): CancellablePromise<Blob> {
|
public downloadFile(options: DownloadOptions): CancellablePromise<Blob> {
|
||||||
|
@ -88,7 +88,8 @@ const taskListeners = {
|
|||||||
|
|
||||||
refreshReference: (task: RefreshReferenceTaskResponse) => {
|
refreshReference: (task: RefreshReferenceTaskResponse) => {
|
||||||
const hex = bytesToHex(task.originalPayload);
|
const hex = bytesToHex(task.originalPayload);
|
||||||
const deferred = apiFileManager.refreshReferencePromises[hex];
|
const r = apiFileManager.refreshReferencePromises[hex];
|
||||||
|
const deferred = r?.deferred;
|
||||||
if(deferred) {
|
if(deferred) {
|
||||||
if(task.error) {
|
if(task.error) {
|
||||||
deferred.reject(task.error);
|
deferred.reject(task.error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user