Fix dialogs placeholder for moved folder

Fix stickers loading order
Fix disappearing faved stickers
This commit is contained in:
Eduard Kuzmenko 2022-11-27 18:50:02 +04:00
parent d68536e26b
commit ed7f9f1470
12 changed files with 82 additions and 57 deletions

View File

@ -139,9 +139,7 @@ export default class AvatarElement extends HTMLElement {
}
}
if(this.lazyLoadQueue) {
this.lazyLoadQueue.unobserve(this);
}
this.lazyLoadQueue?.delete({div: this});
}
public attachClickEvent() {
@ -235,7 +233,7 @@ export default class AvatarElement extends HTMLElement {
return this.r(true);
} else if(this.addedToQueue) {
this.lazyLoadQueue.unobserve(this);
this.lazyLoadQueue.delete({div: this});
}
}

View File

@ -93,7 +93,7 @@ export class SuperStickerRenderer {
public unobserveAnimated(element: HTMLElement) {
this.animated.delete(element);
this.lazyLoadQueue.unobserve(element);
this.lazyLoadQueue.delete({div: element});
}
private checkAnimationContainer = (element: HTMLElement, visible: boolean) => {
@ -114,7 +114,7 @@ export class SuperStickerRenderer {
const size = mediaSizes.active.esgSticker.width;
// console.log('processVisibleDiv:', div);
// console.log('processVisibleDiv:', element);
const promise = wrapSticker({
doc,
@ -608,8 +608,8 @@ export default class StickersTab extends EmoticonsTabC<StickersTabCategory<Stick
category.elements.container.classList.remove('hide');
};
const favedCategory = this.createLocalCategory('faved', 'FavoriteStickers', 'saved');
favedCategory.elements.menuTab.classList.add('active');
const favedCategory = this.createLocalCategory('faved', 'FavoriteStickers', 'savedmessages');
// favedCategory.elements.menuTab.classList.add('active');
const recentCategory = this.createLocalCategory('recent', 'Stickers.Recent', 'recent');
recentCategory.limit = 20;
@ -670,7 +670,10 @@ export default class StickersTab extends EmoticonsTabC<StickersTabCategory<Stick
Promise.all(promises).finally(() => {
this.mounted = true;
this.setTyping();
this.menuOnClickResult.setActive(this.categories['recent']);
const favedCategory = this.categories['faved'];
const recentCategory = this.categories['recent'];
this.menuOnClickResult.setActive(favedCategory.items.length ? favedCategory : recentCategory);
rootScope.addEventListener('stickers_installed', (set) => {
if(!this.categories[set.id]) {

View File

@ -14,6 +14,7 @@ import {AppManagers} from '../lib/appManagers/managers';
import rootScope from '../lib/rootScope';
import LazyLoadQueueRepeat2 from './lazyLoadQueueRepeat2';
import wrapVideo from './wrappers/video';
import noop from '../helpers/noop';
const width = 400;
const maxSingleWidth = width - 100;
@ -195,7 +196,7 @@ export default class GifsMasonry {
appendTo.append(div);
this.lazyLoadQueue.observe(div);
this.lazyLoadQueue.observe({div, load: noop as any});
// let preloader = new ProgressivePreloader(div);

View File

@ -56,12 +56,11 @@ export default class LazyLoadQueue extends LazyLoadQueueIntersector {
if(!inserted) return false;
this.intersector.observe(el.div);
this.observe(el);
/* if(el.wasSeen) {
this.processQueue(el);
} else */if(el.wasSeen === undefined) {
el.wasSeen = false;
}
} else */
el.wasSeen ??= false;
return true;
}

View File

@ -71,12 +71,10 @@ export default class LazyLoadQueueIntersector extends LazyLoadQueueBase {
}
protected setProcessQueueTimeout() {
if(!this.intersectorTimeout) {
this.intersectorTimeout = window.setTimeout(() => {
this.intersectorTimeout = 0;
this.processQueue();
}, 0);
}
this.intersectorTimeout ??= window.setTimeout(() => {
this.intersectorTimeout = undefined;
this.processQueue();
}, 0);
}
public push(el: LazyLoadElement) {
@ -87,9 +85,16 @@ export default class LazyLoadQueueIntersector extends LazyLoadQueueBase {
super.unshift(el);
}
public unobserve(el: HTMLElement) {
findAndSpliceAll(this.queue, (i) => i.div === el);
public delete(el: Omit<LazyLoadElement, 'load'>) {
findAndSpliceAll(this.queue, (i) => i.div === el.div);
this.unobserve(el);
}
this.intersector.unobserve(el);
public observe(el: LazyLoadElement) {
this.intersector.observe(el.div);
}
public unobserve(el: Omit<LazyLoadElement, 'load'>) {
this.intersector.unobserve(el.div);
}
}

View File

@ -4,34 +4,43 @@
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
import findAndSpliceAll from '../helpers/array/findAndSpliceAll';
import indexOfAndSplice from '../helpers/array/indexOfAndSplice';
import LazyLoadQueueIntersector, {LazyLoadElement} from './lazyLoadQueueIntersector';
import VisibilityIntersector, {OnVisibilityChange} from './visibilityIntersector';
export default class LazyLoadQueueRepeat extends LazyLoadQueueIntersector {
private _queue: Map<HTMLElement, LazyLoadElement> = new Map();
private elementsMap: Map<HTMLElement, LazyLoadElement> = new Map();
constructor(parallelLimit?: number, protected onVisibilityChange?: OnVisibilityChange, options?: IntersectionObserverInit) {
constructor(
parallelLimit?: number,
protected onVisibilityChange?: OnVisibilityChange,
options?: IntersectionObserverInit
) {
super(parallelLimit);
this.intersector = new VisibilityIntersector((item) => {
const {target, visible} = item;
const spliced = findAndSpliceAll(this.queue, (i) => i.div === target);
const queueItem = this.elementsMap.get(target);
queueItem.visible = visible;
if(visible) {
const items = spliced.length ? spliced : [this._queue.get(target)];
items.forEach((item) => {
this.queue.unshift(item || this._queue.get(target));
});
queueItem.wasSeen = true;
if(!this.queue.includes(queueItem)) {
this.queue.push(queueItem);
}
} else {
indexOfAndSplice(this.queue, queueItem);
}
this.onVisibilityChange && this.onVisibilityChange(item);
this.onVisibilityChange?.(item);
this.setProcessQueueTimeout();
}, options);
}
public clear() {
super.clear();
this._queue.clear();
this.elementsMap.clear();
}
/* public async processItem(item: LazyLoadElement) {
@ -44,7 +53,12 @@ export default class LazyLoadQueueRepeat extends LazyLoadQueueIntersector {
} */
public observe(el: LazyLoadElement) {
this._queue.set(el.div, el);
this.intersector.observe(el.div);
this.elementsMap.set(el.div, el);
super.observe(el);
}
public unobserve(el: LazyLoadElement) {
this.elementsMap.delete(el.div);
super.unobserve(el);
}
}

View File

@ -5,7 +5,7 @@
*/
import findAndSpliceAll from '../helpers/array/findAndSpliceAll';
import LazyLoadQueueIntersector from './lazyLoadQueueIntersector';
import LazyLoadQueueIntersector, {LazyLoadElement} from './lazyLoadQueueIntersector';
import VisibilityIntersector, {OnVisibilityChange} from './visibilityIntersector';
export default class LazyLoadQueueRepeat2 extends LazyLoadQueueIntersector {
@ -26,7 +26,7 @@ export default class LazyLoadQueueRepeat2 extends LazyLoadQueueIntersector {
});
}
public observe(el: HTMLElement) {
this.intersector.observe(el);
public observe(el: LazyLoadElement) {
super.observe(el);
}
}

View File

@ -500,7 +500,7 @@ export class AppDialogsManager {
const _id = id;
id = +tabContent.dataset.filterId || FOLDER_ID_ALL;
const isFilterAvailable = REAL_FOLDERS.has(id) || await this.managers.filtersStorage.isFilterIdAvailable(id);
const isFilterAvailable = this.filterId === -1 || REAL_FOLDERS.has(id) || await this.managers.filtersStorage.isFilterIdAvailable(id);
if(!isFilterAvailable) {
return false;
}

View File

@ -66,7 +66,7 @@ export class AppStickersManager extends AppManager {
this.rootScope.addEventListener('user_auth', () => {
setTimeout(() => {
this.getAnimatedEmojiStickerSet();
this.getFavedStickersStickers();
// this.getFavedStickersStickers();
}, 1000);
if(!this.getGreetingStickersPromise && this.getGreetingStickersTimeout === undefined) {
@ -269,7 +269,7 @@ export class AppStickersManager extends AppManager {
return promise;
}
public async getRecentStickers(): Promise<Modify<MessagesRecentStickers.messagesRecentStickers, {
public async getRecentStickers(overwrite?: boolean): Promise<Modify<MessagesRecentStickers.messagesRecentStickers, {
stickers: Document[]
}>> {
const res = await this.apiManager.invokeApiHashable({
@ -280,7 +280,8 @@ export class AppStickersManager extends AppManager {
this.recentStickers = res.stickers as MyDocument[];
this.saveStickers(res.stickers);
return res;
}
},
overwrite
});
return res;
@ -289,7 +290,7 @@ export class AppStickersManager extends AppManager {
public getRecentStickersStickers(overwrite?: boolean) {
if(overwrite) this.recentStickers = undefined;
else if(this.recentStickers) return this.recentStickers;
return this.getRecentStickers().then(() => this.recentStickers);
return this.getRecentStickers(overwrite).then(() => this.recentStickers);
}
public saveRecentSticker(docId: DocId, unsave?: boolean, attached?: boolean) {
@ -507,7 +508,7 @@ export class AppStickersManager extends AppManager {
return this.getStickersByEmoticon('📂⭐️', false);
}
public getFavedStickers() {
public getFavedStickers(overwrite?: boolean) {
return this.apiManager.invokeApiHashable({
method: 'messages.getFavedStickers',
processResult: (favedStickers) => {
@ -515,14 +516,15 @@ export class AppStickersManager extends AppManager {
this.saveStickers(favedStickers.stickers);
this.favedStickers = favedStickers.stickers as MyDocument[];
return favedStickers;
}
},
overwrite
});
}
public getFavedStickersStickers(overwrite?: boolean) {
if(overwrite) this.favedStickers = undefined;
else if(this.favedStickers) return this.favedStickers;
return this.getFavedStickers().then(() => this.favedStickers);
return this.getFavedStickers(overwrite).then(() => this.favedStickers);
}
public getFavedStickersLimit() {

View File

@ -79,21 +79,27 @@ export default abstract class ApiManagerMethods extends AppManager {
processResult?: (response: MethodDeclMap[T]['res']) => R,
processError?: (error: ApiError) => any,
params?: Omit<MethodDeclMap[T]['req'], 'hash'>,
options?: InvokeApiOptions & {cacheKey?: string}
options?: InvokeApiOptions & {cacheKey?: string},
overwrite?: boolean
}) {
// @ts-ignore
o.params ??= {};
o.options ??= {};
// console.log('will invokeApi:', method, params, options);
const {params, options, method} = o;
const {params, options, method, overwrite} = o;
const queryJSON = JSON.stringify(params);
let cached: HashResult;
if(this.hashes[method]) {
cached = this.hashes[method][queryJSON];
if(cached) {
(params as any).hash = cached.hash;
if(overwrite) {
delete this.hashes[method][queryJSON];
cached = undefined;
} else {
(params as any).hash = cached.hash;
}
}
}

View File

@ -141,7 +141,7 @@ export class CustomEmojiElement extends HTMLElement {
}
if(globalLazyLoadQueue) {
globalLazyLoadQueue.unobserve(this);
globalLazyLoadQueue.delete({div: this});
}
/* this.disconnectedCallback = */this.elements =
@ -784,7 +784,7 @@ export class CustomEmojiRendererElement extends HTMLElement {
div: element,
load: () => {
elements.forEach((element) => {
globalLazyLoadQueue.unobserve(element);
globalLazyLoadQueue.delete({div: element});
});
return l();

View File

@ -2409,17 +2409,14 @@ $bubble-border-radius-big: 12px;
a,
.peer-title,
[data-saved-from] {
cursor: pointer;
font-weight: var(--font-weight-bold);
&:hover {
text-decoration: underline;
cursor: pointer;
}
}
.peer-title {
cursor: pointer;
//margin-right: 5px;
}
img.emoji {
margin-bottom: 3px;
}