Fix unneeded saving webPage and stickers
This commit is contained in:
parent
7c67d80dab
commit
a9c70efda6
@ -1494,10 +1494,15 @@ export default class ChatInput {
|
|||||||
if(this.lastUrl !== url) {
|
if(this.lastUrl !== url) {
|
||||||
this.lastUrl = url;
|
this.lastUrl = url;
|
||||||
// this.willSendWebPage = null;
|
// this.willSendWebPage = null;
|
||||||
const promise = this.getWebPagePromise = apiManager.invokeApiHashable('messages.getWebPage', {
|
const promise = this.getWebPagePromise = apiManager.invokeApiHashable({
|
||||||
url,
|
method: 'messages.getWebPage',
|
||||||
|
processResult: (webPage) => {
|
||||||
|
return this.appWebPagesManager.saveWebPage(webPage);
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
url
|
||||||
|
},
|
||||||
}).then((webpage) => {
|
}).then((webpage) => {
|
||||||
webpage = this.appWebPagesManager.saveWebPage(webpage);
|
|
||||||
if(this.getWebPagePromise === promise) this.getWebPagePromise = undefined;
|
if(this.getWebPagePromise === promise) this.getWebPagePromise = undefined;
|
||||||
if(this.lastUrl !== url) return;
|
if(this.lastUrl !== url) return;
|
||||||
if(webpage._ === 'webPage') {
|
if(webpage._ === 'webPage') {
|
||||||
|
@ -85,7 +85,7 @@ export default class AppBackgroundTab extends SliderSuperTab {
|
|||||||
|
|
||||||
rootScope.addEventListener('background_change', this.setActive);
|
rootScope.addEventListener('background_change', this.setActive);
|
||||||
|
|
||||||
apiManager.invokeApiHashable('account.getWallPapers').then((accountWallpapers) => {
|
apiManager.invokeApiHashable({method: 'account.getWallPapers'}).then((accountWallpapers) => {
|
||||||
const wallpapers = (accountWallpapers as AccountWallPapers.accountWallPapers).wallpapers as WallPaper.wallPaper[];
|
const wallpapers = (accountWallpapers as AccountWallPapers.accountWallPapers).wallpapers as WallPaper.wallPaper[];
|
||||||
wallpapers.forEach((wallpaper) => {
|
wallpapers.forEach((wallpaper) => {
|
||||||
this.addWallPaper(wallpaper);
|
this.addWallPaper(wallpaper);
|
||||||
|
@ -18,6 +18,7 @@ import lottieLoader from '../rlottie/lottieLoader';
|
|||||||
import mediaSizes from '../../helpers/mediaSizes';
|
import mediaSizes from '../../helpers/mediaSizes';
|
||||||
import { getEmojiToneIndex } from '../../vendor/emoji';
|
import { getEmojiToneIndex } from '../../vendor/emoji';
|
||||||
import RichTextProcessor from '../richtextprocessor';
|
import RichTextProcessor from '../richtextprocessor';
|
||||||
|
import assumeType from '../../helpers/assumeType';
|
||||||
|
|
||||||
const CACHE_TIME = 3600e3;
|
const CACHE_TIME = 3600e3;
|
||||||
|
|
||||||
@ -137,9 +138,14 @@ export class AppStickersManager {
|
|||||||
public async getRecentStickers(): Promise<Modify<MessagesRecentStickers.messagesRecentStickers, {
|
public async getRecentStickers(): Promise<Modify<MessagesRecentStickers.messagesRecentStickers, {
|
||||||
stickers: Document[]
|
stickers: Document[]
|
||||||
}>> {
|
}>> {
|
||||||
const res = await apiManager.invokeApiHashable('messages.getRecentStickers') as MessagesRecentStickers.messagesRecentStickers;
|
const res = await apiManager.invokeApiHashable({
|
||||||
|
method: 'messages.getRecentStickers',
|
||||||
this.saveStickers(res.stickers);
|
processResult: (res) => {
|
||||||
|
assumeType<MessagesRecentStickers.messagesRecentStickers>(res);
|
||||||
|
this.saveStickers(res.stickers);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -260,10 +266,16 @@ export class AppStickersManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getFeaturedStickers() {
|
public async getFeaturedStickers() {
|
||||||
const res = await apiManager.invokeApiHashable('messages.getFeaturedStickers') as MessagesFeaturedStickers.messagesFeaturedStickers;
|
const res = await apiManager.invokeApiHashable({
|
||||||
|
method: 'messages.getFeaturedStickers',
|
||||||
res.sets.forEach(covered => {
|
processResult: (res) => {
|
||||||
this.saveStickerSet({set: covered.set, documents: [], packs: []}, covered.set.id);
|
assumeType<MessagesFeaturedStickers.messagesFeaturedStickers>(res);
|
||||||
|
res.sets.forEach(covered => {
|
||||||
|
this.saveStickerSet({set: covered.set, documents: [], packs: []}, covered.set.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.sets;
|
return res.sets;
|
||||||
@ -299,14 +311,22 @@ export class AppStickersManager {
|
|||||||
|
|
||||||
public async searchStickerSets(query: string, excludeFeatured = true) {
|
public async searchStickerSets(query: string, excludeFeatured = true) {
|
||||||
const flags = excludeFeatured ? 1 : 0;
|
const flags = excludeFeatured ? 1 : 0;
|
||||||
const res = await apiManager.invokeApiHashable('messages.searchStickerSets', {
|
const res = await apiManager.invokeApiHashable({
|
||||||
flags,
|
method: 'messages.searchStickerSets',
|
||||||
exclude_featured: excludeFeatured || undefined,
|
params: {
|
||||||
q: query
|
flags,
|
||||||
}) as MessagesFoundStickerSets.messagesFoundStickerSets;
|
exclude_featured: excludeFeatured || undefined,
|
||||||
|
q: query
|
||||||
|
},
|
||||||
|
processResult: (res) => {
|
||||||
|
assumeType<MessagesFoundStickerSets.messagesFoundStickerSets>(res);
|
||||||
|
|
||||||
res.sets.forEach(covered => {
|
res.sets.forEach(covered => {
|
||||||
this.saveStickerSet({set: covered.set, documents: [], packs: []}, covered.set.id);
|
this.saveStickerSet({set: covered.set, documents: [], packs: []}, covered.set.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const foundSaved: StickerSetCovered[] = [];
|
const foundSaved: StickerSetCovered[] = [];
|
||||||
@ -323,7 +343,7 @@ export class AppStickersManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getAllStickers() {
|
public getAllStickers() {
|
||||||
return apiManager.invokeApiHashable('messages.getAllStickers');
|
return apiManager.invokeApiHashable({method: 'messages.getAllStickers'});
|
||||||
}
|
}
|
||||||
|
|
||||||
public preloadStickerSets() {
|
public preloadStickerSets() {
|
||||||
@ -338,8 +358,11 @@ export class AppStickersManager {
|
|||||||
if(this.getStickersByEmoticonsPromises[emoticon]) return this.getStickersByEmoticonsPromises[emoticon];
|
if(this.getStickersByEmoticonsPromises[emoticon]) return this.getStickersByEmoticonsPromises[emoticon];
|
||||||
|
|
||||||
return this.getStickersByEmoticonsPromises[emoticon] = Promise.all([
|
return this.getStickersByEmoticonsPromises[emoticon] = Promise.all([
|
||||||
apiManager.invokeApiHashable('messages.getStickers', {
|
apiManager.invokeApiHashable({
|
||||||
emoticon
|
method: 'messages.getStickers',
|
||||||
|
params: {
|
||||||
|
emoticon
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
includeOurStickers ? this.preloadStickerSets() : [],
|
includeOurStickers ? this.preloadStickerSets() : [],
|
||||||
includeOurStickers ? this.getRecentStickers() : undefined
|
includeOurStickers ? this.getRecentStickers() : undefined
|
||||||
|
@ -460,9 +460,20 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
|
|||||||
return this.invokeApi(method, params, o);
|
return this.invokeApi(method, params, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public invokeApiHashable<T extends keyof MethodDeclMap>(method: T, params: Omit<MethodDeclMap[T]['req'], 'hash'> = {} as any, options: InvokeApiOptions = {}): Promise<MethodDeclMap[T]['res']> {
|
public invokeApiHashable<T extends keyof MethodDeclMap, R>(o: {
|
||||||
|
method: T,
|
||||||
|
processResult?: (response: MethodDeclMap[T]['res']) => R,
|
||||||
|
processError?: (error: ApiError) => any,
|
||||||
|
params?: Omit<MethodDeclMap[T]['req'], 'hash'>,
|
||||||
|
options?: InvokeApiOptions & {cacheKey?: string}
|
||||||
|
}): Promise<R> {
|
||||||
|
// @ts-ignore
|
||||||
|
o.params ??= {};
|
||||||
|
o.options ??= {};
|
||||||
//console.log('will invokeApi:', method, params, options);
|
//console.log('will invokeApi:', method, params, options);
|
||||||
|
|
||||||
|
const {params, options, method} = o;
|
||||||
|
|
||||||
const queryJSON = JSON.stringify(params);
|
const queryJSON = JSON.stringify(params);
|
||||||
let cached: HashResult;
|
let cached: HashResult;
|
||||||
if(this.hashes[method]) {
|
if(this.hashes[method]) {
|
||||||
@ -472,23 +483,32 @@ export class ApiManagerProxy extends CryptoWorkerMethods {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.invokeApi(method, params, options).then((result: any) => {
|
return this.invokeApiSingleProcess({
|
||||||
if(result._.includes('NotModified')) {
|
method,
|
||||||
this.debug && this.log.warn('NotModified saved!', method, queryJSON);
|
processResult: (result) => {
|
||||||
return cached.result;
|
if(result._.includes('NotModified')) {
|
||||||
}
|
this.debug && this.log.warn('NotModified saved!', method, queryJSON);
|
||||||
|
return cached.result;
|
||||||
if(result.hash/* || result.messages */) {
|
}
|
||||||
const hash = result.hash/* || this.computeHash(result.messages) */;
|
|
||||||
|
|
||||||
if(!this.hashes[method]) this.hashes[method] = {};
|
if(result.hash/* || result.messages */) {
|
||||||
this.hashes[method][queryJSON] = {
|
const hash = result.hash/* || this.computeHash(result.messages) */;
|
||||||
hash,
|
|
||||||
result
|
if(!this.hashes[method]) this.hashes[method] = {};
|
||||||
};
|
this.hashes[method][queryJSON] = {
|
||||||
}
|
hash,
|
||||||
|
result
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
if(o.processResult) {
|
||||||
|
return o.processResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
params,
|
||||||
|
options
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user