Skip to content

Commit

Permalink
Fix sending some gifs
Browse files Browse the repository at this point in the history
Fix freezed media in ESG
  • Loading branch information
morethanwords committed Nov 27, 2022
1 parent d5255be commit 12fcc3c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/components/chat/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2611,7 +2611,7 @@ export default class ChatInput {
return false;
}

if(getStickerEffectThumb(document) && !rootScope.premium) {
if(document.sticker && getStickerEffectThumb(document) && !rootScope.premium) {
return false;
}

Expand Down
45 changes: 31 additions & 14 deletions src/helpers/dropdownHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import IS_TOUCH_SUPPORTED from '../environment/touchSupport';
import safeAssign from './object/safeAssign';
import appNavigationController, {NavigationItem} from '../components/appNavigationController';
import findUpClassName from './dom/findUpClassName';
import rootScope from '../lib/rootScope';

const KEEP_OPEN = false;
const TOGGLE_TIMEOUT = 200;
const ANIMATION_DURATION = 200;

export type IgnoreMouseOutType = 'click' | 'menu' | 'popup';
type DropdownHoverTimeoutType = 'toggle' | 'done';

export default class DropdownHover extends EventListenerBase<{
open: () => Promise<any> | void,
Expand All @@ -27,13 +29,13 @@ export default class DropdownHover extends EventListenerBase<{
closed: () => any
}> {
protected element: HTMLElement;
protected displayTimeout: number;
protected forceClose: boolean;
protected inited: boolean;
protected ignoreMouseOut: Set<IgnoreMouseOutType>;
protected ignoreButtons: Set<HTMLElement>;
protected navigationItem: NavigationItem;
protected ignoreOutClickClassName: string;
protected timeouts: {[type in DropdownHoverTimeoutType]?: number};

constructor(options: {
element: DropdownHover['element'],
Expand All @@ -45,6 +47,7 @@ export default class DropdownHover extends EventListenerBase<{
this.inited = false;
this.ignoreMouseOut = new Set();
this.ignoreButtons = new Set();
this.timeouts = {};
}

public attachButtonListener(
Expand All @@ -63,17 +66,15 @@ export default class DropdownHover extends EventListenerBase<{
}, {listenerSetter});
} else {
listenerSetter.add(button)('mouseover', (e) => {
// console.log('onmouseover button');
if(firstTime) {
listenerSetter.add(button)('mouseout', (e) => {
clearTimeout(this.displayTimeout);
this.clearTimeout('toggle');
this.onMouseOut(e);
});
firstTime = false;
}

clearTimeout(this.displayTimeout);
this.displayTimeout = window.setTimeout(() => {
this.setTimeout('toggle', () => {
this.toggle(true);
}, TOGGLE_TIMEOUT);
});
Expand Down Expand Up @@ -109,7 +110,7 @@ export default class DropdownHover extends EventListenerBase<{

protected onMouseOut = (e: MouseEvent) => {
if(KEEP_OPEN || !this.isActive()) return;
clearTimeout(this.displayTimeout);
this.clearTimeout('toggle');

if(this.ignoreMouseOut.size) {
return;
Expand All @@ -120,11 +121,26 @@ export default class DropdownHover extends EventListenerBase<{
return;
}

this.displayTimeout = window.setTimeout(() => {
this.setTimeout('toggle', () => {
this.toggle(false);
}, TOGGLE_TIMEOUT);
};

protected clearTimeout(type: DropdownHoverTimeoutType) {
if(this.timeouts[type] !== undefined) {
clearTimeout(this.timeouts[type]);
delete this.timeouts[type];
}
}

protected setTimeout(type: DropdownHoverTimeoutType, cb: () => void, timeout: number) {
this.clearTimeout(type);
this.timeouts[type] = window.setTimeout(() => {
this.clearTimeout(type);
cb();
}, timeout);
}

public init() {
if(!IS_TOUCH_SUPPORTED) {
this.element.onmouseout = this.onMouseOut;
Expand All @@ -134,7 +150,7 @@ export default class DropdownHover extends EventListenerBase<{
}

// console.log('onmouseover element');
clearTimeout(this.displayTimeout);
this.clearTimeout('toggle');
};
}
}
Expand All @@ -155,6 +171,7 @@ export default class DropdownHover extends EventListenerBase<{
return;
}

const delay = IS_TOUCH_SUPPORTED || !rootScope.settings.animationsEnabled ? 0 : ANIMATION_DURATION;
if((this.element.style.display && enable === undefined) || enable) {
const res = this.dispatchResultableEvent('open');
await Promise.all(res);
Expand All @@ -172,11 +189,11 @@ export default class DropdownHover extends EventListenerBase<{
}
});

clearTimeout(this.displayTimeout);
this.displayTimeout = window.setTimeout(() => {
this.clearTimeout('toggle');
this.setTimeout('done', () => {
this.forceClose = false;
this.dispatchEvent('opened');
}, IS_TOUCH_SUPPORTED ? 0 : ANIMATION_DURATION);
}, delay);

// ! can't use together with resizeObserver
/* if(isTouchSupported) {
Expand All @@ -198,12 +215,12 @@ export default class DropdownHover extends EventListenerBase<{
appNavigationController.removeItem(this.navigationItem);
detachClickEvent(window, this.onClickOut, {capture: true});

clearTimeout(this.displayTimeout);
this.displayTimeout = window.setTimeout(() => {
this.clearTimeout('toggle');
this.setTimeout('done', () => {
this.element.style.display = 'none';
this.forceClose = false;
this.dispatchEvent('closed');
}, IS_TOUCH_SUPPORTED ? 0 : ANIMATION_DURATION);
}, delay);

/* if(isTouchSupported) {
const scrollHeight = this.container.scrollHeight;
Expand Down

0 comments on commit 12fcc3c

Please sign in to comment.