Browse Source

Fix unloading stickers from panel after closening

master
Eduard Kuzmenko 4 years ago
parent
commit
a4e46571de
  1. 4
      src/components/chat/input.ts
  2. 7
      src/components/chat/topbar.ts
  3. 3
      src/components/dialogsContextMenu.ts
  4. 57
      src/components/emoticonsDropdown/index.ts
  5. 3
      src/components/emoticonsDropdown/tabs/stickers.ts
  6. 6
      src/lib/appManagers/appMessagesManager.ts
  7. 5
      src/lib/lottieLoader.ts

4
src/components/chat/input.ts

@ -574,11 +574,11 @@ export default class ChatInput {
}); });
if(isTouchSupported) { if(isTouchSupported) {
this.listenerSetter.add(this.messageInput, 'touchend', (e) => { attachClickEvent(this.messageInput, (e) => {
this.appImManager.selectTab(1); // * set chat tab for album orientation this.appImManager.selectTab(1); // * set chat tab for album orientation
this.saveScroll(); this.saveScroll();
emoticonsDropdown.toggle(false); emoticonsDropdown.toggle(false);
}); }, {listenerSetter: this.listenerSetter});
this.listenerSetter.add(window, 'resize', () => { this.listenerSetter.add(window, 'resize', () => {
this.restoreScroll(); this.restoreScroll();

7
src/components/chat/topbar.ts

@ -3,7 +3,7 @@ import type { AppMessagesManager } from "../../lib/appManagers/appMessagesManage
import type { AppPeersManager } from "../../lib/appManagers/appPeersManager"; import type { AppPeersManager } from "../../lib/appManagers/appPeersManager";
import type { AppSidebarRight } from "../sidebarRight"; import type { AppSidebarRight } from "../sidebarRight";
import type Chat from "./chat"; import type Chat from "./chat";
import { findUpClassName, cancelEvent, attachClickEvent } from "../../helpers/dom"; import { findUpClassName, cancelEvent, attachClickEvent, blurActiveElement } from "../../helpers/dom";
import mediaSizes, { ScreenSize } from "../../helpers/mediaSizes"; import mediaSizes, { ScreenSize } from "../../helpers/mediaSizes";
import { isSafari } from "../../helpers/userAgent"; import { isSafari } from "../../helpers/userAgent";
import rootScope from "../../lib/rootScope"; import rootScope from "../../lib/rootScope";
@ -121,6 +121,7 @@ export default class ChatTopbar {
attachClickEvent(this.container, (e) => { attachClickEvent(this.container, (e) => {
const container: HTMLElement = findUpClassName(e.target, 'pinned-container'); const container: HTMLElement = findUpClassName(e.target, 'pinned-container');
blurActiveElement();
if(container) { if(container) {
cancelEvent(e); cancelEvent(e);
@ -141,6 +142,7 @@ export default class ChatTopbar {
attachClickEvent(this.btnBack, (e) => { attachClickEvent(this.btnBack, (e) => {
cancelEvent(e); cancelEvent(e);
this.chat.appImManager.setPeer(0); this.chat.appImManager.setPeer(0);
blurActiveElement();
}, {listenerSetter: this.listenerSetter}); }, {listenerSetter: this.listenerSetter});
} }
@ -222,17 +224,20 @@ export default class ChatTopbar {
attachClickEvent(this.btnPinned, (e) => { attachClickEvent(this.btnPinned, (e) => {
cancelEvent(e); cancelEvent(e);
blurActiveElement();
this.openPinned(true); this.openPinned(true);
}, {listenerSetter: this.listenerSetter}); }, {listenerSetter: this.listenerSetter});
attachClickEvent(this.btnMute, (e) => { attachClickEvent(this.btnMute, (e) => {
cancelEvent(e); cancelEvent(e);
blurActiveElement();
this.appMessagesManager.mutePeer(this.peerId); this.appMessagesManager.mutePeer(this.peerId);
}, {listenerSetter: this.listenerSetter}); }, {listenerSetter: this.listenerSetter});
attachClickEvent(this.btnJoin, (e) => { attachClickEvent(this.btnJoin, (e) => {
cancelEvent(e); cancelEvent(e);
blurActiveElement();
this.btnJoin.setAttribute('disabled', 'true'); this.btnJoin.setAttribute('disabled', 'true');
this.appChatsManager.joinChannel(-this.peerId).finally(() => { this.appChatsManager.joinChannel(-this.peerId).finally(() => {
this.btnJoin.removeAttribute('disabled'); this.btnJoin.removeAttribute('disabled');

3
src/components/dialogsContextMenu.ts

@ -1,12 +1,9 @@
import appChatsManager from "../lib/appManagers/appChatsManager";
import appDialogsManager from "../lib/appManagers/appDialogsManager"; import appDialogsManager from "../lib/appManagers/appDialogsManager";
import appMessagesManager, {Dialog} from "../lib/appManagers/appMessagesManager"; import appMessagesManager, {Dialog} from "../lib/appManagers/appMessagesManager";
import appPeersManager from "../lib/appManagers/appPeersManager"; import appPeersManager from "../lib/appManagers/appPeersManager";
import rootScope from "../lib/rootScope"; import rootScope from "../lib/rootScope";
import { findUpTag } from "../helpers/dom"; import { findUpTag } from "../helpers/dom";
import { positionMenu, openBtnMenu } from "./misc"; import { positionMenu, openBtnMenu } from "./misc";
import { PopupButton } from "./popups";
import PopupPeer from "./popups/peer";
import ButtonMenu, { ButtonMenuItemOptions } from "./buttonMenu"; import ButtonMenu, { ButtonMenuItemOptions } from "./buttonMenu";
import PopupDeleteDialog from "./popups/deleteDialog"; import PopupDeleteDialog from "./popups/deleteDialog";

57
src/components/emoticonsDropdown/index.ts

@ -56,18 +56,18 @@ export class EmoticonsDropdown {
}; };
private selectTab: ReturnType<typeof horizontalMenu>; private selectTab: ReturnType<typeof horizontalMenu>;
private forceClose = false;
private firstTime = true;
constructor() { constructor() {
this.element = document.getElementById('emoji-dropdown') as HTMLDivElement; this.element = document.getElementById('emoji-dropdown') as HTMLDivElement;
} }
public attachButtonListener(button: HTMLElement) { public attachButtonListener(button: HTMLElement) {
let firstTime = true;
if(isTouchSupported) { if(isTouchSupported) {
button.addEventListener('click', () => { button.addEventListener('click', () => {
if(this.firstTime) { if(firstTime) {
this.firstTime = false; firstTime = false;
this.toggle(true); this.toggle(true);
} else { } else {
this.toggle(); this.toggle();
@ -75,10 +75,22 @@ export class EmoticonsDropdown {
}); });
} else { } else {
button.onmouseover = (e) => { button.onmouseover = (e) => {
//console.log('onmouseover button');
clearTimeout(this.displayTimeout); clearTimeout(this.displayTimeout);
//this.displayTimeout = setTimeout(() => { //this.displayTimeout = setTimeout(() => {
if(this.firstTime) { if(firstTime) {
button.onmouseout = this.element.onmouseout = (e) => { button.onmouseout = this.onMouseOut;
firstTime = false;
}
this.toggle(true);
//}, 0/* 200 */);
};
}
}
private onMouseOut = (e: MouseEvent) => {
if(test) return; if(test) return;
if(!this.element.classList.contains('active')) return; if(!this.element.classList.contains('active')) return;
@ -93,19 +105,6 @@ export class EmoticonsDropdown {
}, 200); }, 200);
}; };
this.element.onmouseover = (e) => {
clearTimeout(this.displayTimeout);
};
this.firstTime = false;
}
this.toggle(true);
//}, 0/* 200 */);
};
}
}
private init() { private init() {
this.emojiTab = new EmojiTab(); this.emojiTab = new EmojiTab();
this.stickersTab = new StickersTab(); this.stickersTab = new StickersTab();
@ -161,6 +160,18 @@ export class EmoticonsDropdown {
rootScope.on('peer_changed', this.checkRights); rootScope.on('peer_changed', this.checkRights);
this.checkRights(); this.checkRights();
if(!isTouchSupported) {
this.element.onmouseout = this.onMouseOut;
this.element.onmouseover = (e) => {
if(this.forceClose) {
return;
}
//console.log('onmouseover element');
clearTimeout(this.displayTimeout);
};
}
} }
private onSelectTabClick = (id: number) => { private onSelectTabClick = (id: number) => {
@ -237,6 +248,9 @@ export class EmoticonsDropdown {
EmoticonsDropdown.lazyLoadQueue.unlock(); EmoticonsDropdown.lazyLoadQueue.unlock();
EmoticonsDropdown.lazyLoadQueue.refresh(); EmoticonsDropdown.lazyLoadQueue.refresh();
this.forceClose = false;
this.container.classList.remove('disable-hover');
this.events.onOpenAfter.forEach(cb => cb()); this.events.onOpenAfter.forEach(cb => cb());
}, isTouchSupported ? 0 : 200); }, isTouchSupported ? 0 : 200);
@ -264,6 +278,9 @@ export class EmoticonsDropdown {
EmoticonsDropdown.lazyLoadQueue.unlock(); EmoticonsDropdown.lazyLoadQueue.unlock();
EmoticonsDropdown.lazyLoadQueue.refresh(); EmoticonsDropdown.lazyLoadQueue.refresh();
this.forceClose = false;
this.container.classList.remove('disable-hover');
this.events.onCloseAfter.forEach(cb => cb()); this.events.onCloseAfter.forEach(cb => cb());
}, isTouchSupported ? 0 : 200); }, isTouchSupported ? 0 : 200);
@ -353,6 +370,8 @@ export class EmoticonsDropdown {
if(appImManager.chat.input.sendMessageWithDocument(fileId)) { if(appImManager.chat.input.sendMessageWithDocument(fileId)) {
/* dropdown.classList.remove('active'); /* dropdown.classList.remove('active');
toggleEl.classList.remove('active'); */ toggleEl.classList.remove('active'); */
emoticonsDropdown.forceClose = true;
emoticonsDropdown.container.classList.add('disable-hover');
emoticonsDropdown.toggle(false); emoticonsDropdown.toggle(false);
} else { } else {
console.warn('got no doc by id:', fileId); console.warn('got no doc by id:', fileId);

3
src/components/emoticonsDropdown/tabs/stickers.ts

@ -6,7 +6,6 @@ import appDocsManager, { MyDocument } from "../../../lib/appManagers/appDocsMana
import appDownloadManager from "../../../lib/appManagers/appDownloadManager"; import appDownloadManager from "../../../lib/appManagers/appDownloadManager";
import appStickersManager from "../../../lib/appManagers/appStickersManager"; import appStickersManager from "../../../lib/appManagers/appStickersManager";
import lottieLoader from "../../../lib/lottieLoader"; import lottieLoader from "../../../lib/lottieLoader";
import apiManager from "../../../lib/mtproto/mtprotoworker";
import { RichTextProcessor } from "../../../lib/richtextprocessor"; import { RichTextProcessor } from "../../../lib/richtextprocessor";
import rootScope from "../../../lib/rootScope"; import rootScope from "../../../lib/rootScope";
import animationIntersector from "../../animationIntersector"; import animationIntersector from "../../animationIntersector";
@ -330,7 +329,7 @@ export default class StickersTab implements EmoticonsTab {
// @ts-ignore // @ts-ignore
const players = Object.values(lottieLoader.players).filter(p => p.width == 80); const players = Object.values(lottieLoader.players).filter(p => p.width == 80);
console.log('STICKERS RENDERED IN PANEL:', players.length, players.filter(p => !p.paused).length, this.lazyLoadQueue.intersector.getVisible().length); console.log('STICKERS RENDERED IN PANEL:', players.length, players.filter(p => !p.paused).length, this.superStickerRenderer.lazyLoadQueue.intersector.getVisible().length);
}, .25e3); */ }, .25e3); */

6
src/lib/appManagers/appMessagesManager.ts

@ -2799,7 +2799,7 @@ export class AppMessagesManager {
offset_id_offset: number, offset_id_offset: number,
history: MyMessage[] history: MyMessage[]
}> { }> {
const foundMsgs: any[] = []; const foundMsgs: Message.message[] = [];
//this.log('search', maxId); //this.log('search', maxId);
@ -2940,7 +2940,7 @@ export class AppMessagesManager {
if(foundMsgs.length) { if(foundMsgs.length) {
if(foundMsgs.length < limit && (beta ? storage.count !== storage.history.length : true)) { if(foundMsgs.length < limit && (beta ? storage.count !== storage.history.length : true)) {
maxId = foundMsgs[foundMsgs.length - 1]; maxId = foundMsgs[foundMsgs.length - 1].mid;
limit = limit - foundMsgs.length; limit = limit - foundMsgs.length;
} else { } else {
return Promise.resolve({ return Promise.resolve({
@ -3036,7 +3036,7 @@ export class AppMessagesManager {
return { return {
count: foundCount, count: foundCount,
offset_id_offset: searchResult.offset_id_offset, offset_id_offset: searchResult.offset_id_offset || 0,
next_rate: searchResult.next_rate, next_rate: searchResult.next_rate,
history: foundMsgs history: foundMsgs
}; };

5
src/lib/lottieLoader.ts

@ -129,6 +129,8 @@ export class RLottiePlayer extends EventListenerBase<{
} }
} }
//options.noCache = true;
// * Cache frames params // * Cache frames params
if(!options.noCache/* && false */) { if(!options.noCache/* && false */) {
// проверка на размер уже после скейлинга, сделано для попапа и сайдбара, где стикеры 80х80 и 68х68, туда нужно 75% // проверка на размер уже после скейлинга, сделано для попапа и сайдбара, где стикеры 80х80 и 68х68, туда нужно 75%
@ -141,6 +143,7 @@ export class RLottiePlayer extends EventListenerBase<{
} }
} }
// this.cachingDelta = Infinity;
// if(isApple) { // if(isApple) {
// this.cachingDelta = 0; //2 // 50% // this.cachingDelta = 0; //2 // 50%
// } // }
@ -240,7 +243,9 @@ export class RLottiePlayer extends EventListenerBase<{
this.imageData.data.set(frame); this.imageData.data.set(frame);
//this.context.putImageData(new ImageData(frame, this.width, this.height), 0, 0); //this.context.putImageData(new ImageData(frame, this.width, this.height), 0, 0);
//let perf = performance.now();
this.context.putImageData(this.imageData, 0, 0); this.context.putImageData(this.imageData, 0, 0);
//console.log('renderFrame2 perf:', performance.now() - perf);
} catch(err) { } catch(err) {
console.error('RLottiePlayer renderFrame error:', err/* , frame */, this.width, this.height); console.error('RLottiePlayer renderFrame error:', err/* , frame */, this.width, this.height);
this.autoplay = false; this.autoplay = false;

Loading…
Cancel
Save