From e170b90a78d4071ce8c1fcd705eb74a03f8a9415 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Sun, 9 May 2021 22:09:35 +0400 Subject: [PATCH] (Android) Fix color picker Fix deleting dialogs Fix missed implementations --- src/components/sidebarLeft/index.ts | 6 +-- .../sidebarLeft/tabs/backgroundColor.ts | 11 ++-- .../sidebarLeft/tabs/blockedUsers.ts | 5 +- src/helpers/dom/attachGrabListeners.ts | 12 +++-- src/lib/appManagers/appDialogsManager.ts | 2 +- src/lib/appManagers/appStateManager.ts | 4 +- src/lib/storage.ts | 51 ++++++++++++++----- src/lib/storages/dialogs.ts | 9 +++- src/scss/partials/_chatlist.scss | 4 +- src/scss/partials/_leftSidebar.scss | 2 +- 10 files changed, 71 insertions(+), 35 deletions(-) diff --git a/src/components/sidebarLeft/index.ts b/src/components/sidebarLeft/index.ts index 6a95bdbe..d88c2236 100644 --- a/src/components/sidebarLeft/index.ts +++ b/src/components/sidebarLeft/index.ts @@ -1,4 +1,3 @@ -//import { logger } from "../polyfill"; /* * https://github.com/morethanwords/tweb * Copyright (C) 2019-2021 Eduard Kuzmenko @@ -36,6 +35,7 @@ import findUpTag from "../../helpers/dom/findUpTag"; import PeerTitle from "../peerTitle"; import App from "../../config/app"; import ButtonMenuToggle from "../buttonMenuToggle"; +import replaceContent from "../../helpers/dom/replaceContent"; export const LEFT_COLUMN_ACTIVE_CLASSNAME = 'is-left-column-shown'; @@ -606,7 +606,3 @@ export const generateSection = (appendTo: Scrollable, name?: LangPackKey, captio const appSidebarLeft = new AppSidebarLeft(); MOUNT_CLASS_TO.appSidebarLeft = appSidebarLeft; export default appSidebarLeft; -function replaceContent(div: HTMLDivElement, title: HTMLElement) { - throw new Error("Function not implemented."); -} - diff --git a/src/components/sidebarLeft/tabs/backgroundColor.ts b/src/components/sidebarLeft/tabs/backgroundColor.ts index 2026cce9..fb37ebb2 100644 --- a/src/components/sidebarLeft/tabs/backgroundColor.ts +++ b/src/components/sidebarLeft/tabs/backgroundColor.ts @@ -1,5 +1,12 @@ +/* + * https://github.com/morethanwords/tweb + * Copyright (C) 2019-2021 Eduard Kuzmenko + * https://github.com/morethanwords/tweb/blob/master/LICENSE + */ + import { SettingSection } from ".."; import { hexaToRgba } from "../../../helpers/color"; +import { attachClickEvent } from "../../../helpers/dom/clickEvent"; import findUpClassName from "../../../helpers/dom/findUpClassName"; import highlightningColor from "../../../helpers/highlightningColor"; import { throttle } from "../../../helpers/schedulers"; @@ -142,7 +149,3 @@ export default class AppBackgroundColorTab extends SliderSuperTab { return super.onCloseAfterTimeout(); } } -function attachClickEvent(grid: HTMLDivElement, arg1: (e: any) => void, arg2: { listenerSetter: import("../../../helpers/listenerSetter").default; }) { - throw new Error("Function not implemented."); -} - diff --git a/src/components/sidebarLeft/tabs/blockedUsers.ts b/src/components/sidebarLeft/tabs/blockedUsers.ts index b91cf135..22b97e96 100644 --- a/src/components/sidebarLeft/tabs/blockedUsers.ts +++ b/src/components/sidebarLeft/tabs/blockedUsers.ts @@ -14,6 +14,7 @@ import PopupPickUser from "../../popups/pickUser"; import rootScope from "../../../lib/rootScope"; import findUpTag from "../../../helpers/dom/findUpTag"; import ButtonCorner from "../../buttonCorner"; +import { attachClickEvent } from "../../../helpers/dom/clickEvent"; export default class AppBlockedUsersTab extends SliderSuperTab { public peerIds: number[]; @@ -156,7 +157,3 @@ export default class AppBlockedUsersTab extends SliderSuperTab { return super.onCloseAfterTimeout(); } } -function attachClickEvent(btnAdd: HTMLButtonElement, arg1: (e: any) => void, arg2: { listenerSetter: import("../../../helpers/listenerSetter").default; }) { - throw new Error("Function not implemented."); -} - diff --git a/src/helpers/dom/attachGrabListeners.ts b/src/helpers/dom/attachGrabListeners.ts index 78b4c855..3a6e1e78 100644 --- a/src/helpers/dom/attachGrabListeners.ts +++ b/src/helpers/dom/attachGrabListeners.ts @@ -1,3 +1,9 @@ +/* + * https://github.com/morethanwords/tweb + * Copyright (C) 2019-2021 Eduard Kuzmenko + * https://github.com/morethanwords/tweb/blob/master/LICENSE + */ + export type GrabEvent = {x: number, y: number, isTouch?: boolean}; export default function attachGrabListeners(element: HTMLElement, onStart: (position: GrabEvent) => void, onMove: (position: GrabEvent) => void, onEnd: (position: GrabEvent) => void) { @@ -35,7 +41,7 @@ export default function attachGrabListeners(element: HTMLElement, onStart: (posi const onTouchEnd = (event: TouchEvent) => { document.removeEventListener('touchmove', onTouchMove); - element.addEventListener('touchstart', onTouchStart, {passive: true, once: true}); + element.addEventListener('touchstart', onTouchStart, {passive: false, once: true}); onEnd && onEnd({x: event.touches[0].clientX, y: event.touches[0].clientY, isTouch: true}); }; @@ -44,10 +50,10 @@ export default function attachGrabListeners(element: HTMLElement, onStart: (posi onTouchMove(event); document.addEventListener('touchmove', onTouchMove, {passive: false}); - document.addEventListener('touchend', onTouchEnd, {passive: true, once: true}); + document.addEventListener('touchend', onTouchEnd, {passive: false, once: true}); }; - element.addEventListener('touchstart', onTouchStart, {passive: true, once: true}); + element.addEventListener('touchstart', onTouchStart, {passive: false, once: true}); return () => { element.removeEventListener('mousedown', onMouseDown); diff --git a/src/lib/appManagers/appDialogsManager.ts b/src/lib/appManagers/appDialogsManager.ts index 4cd81020..289dbd51 100644 --- a/src/lib/appManagers/appDialogsManager.ts +++ b/src/lib/appManagers/appDialogsManager.ts @@ -908,7 +908,7 @@ export class AppDialogsManager { const offsetTop = this.folders.container.offsetTop; const firstY = rectContainer.y + offsetTop; - const lastY = rectContainer.y; + const lastY = rectContainer.y - 8; // 8px - .chatlist padding-bottom const firstElement = findUpTag(document.elementFromPoint(Math.ceil(rectTarget.x), Math.ceil(firstY + 1)), firstElementChild.tagName) as HTMLElement; const lastElement = findUpTag(document.elementFromPoint(Math.ceil(rectTarget.x), Math.floor(lastY + rectContainer.height - 1)), firstElementChild.tagName) as HTMLElement; diff --git a/src/lib/appManagers/appStateManager.ts b/src/lib/appManagers/appStateManager.ts index 794142f3..7c1375a0 100644 --- a/src/lib/appManagers/appStateManager.ts +++ b/src/lib/appManagers/appStateManager.ts @@ -378,7 +378,9 @@ export class AppStateManager extends EventListenerBase<{ } } - this.singlePeerMap.set(type, peerId); + if(peerId) { + this.singlePeerMap.set(type, peerId); + } } /* public resetState() { diff --git a/src/lib/storage.ts b/src/lib/storage.ts index 512ca021..3becac92 100644 --- a/src/lib/storage.ts +++ b/src/lib/storage.ts @@ -31,6 +31,10 @@ export default class AppStorage/* Storage ex private saveThrottled: () => void; private saveDeferred = deferredPromise(); + private keysToDelete: Set = new Set(); + private deleteThrottled: () => void; + private deleteDeferred = deferredPromise(); + constructor(storageOptions: Omit & {stores?: DatabaseStore[], storeName: DatabaseStoreName}) { this.storage = new IDBStorage(storageOptions); @@ -40,9 +44,10 @@ export default class AppStorage/* Storage ex const deferred = this.saveDeferred; this.saveDeferred = deferredPromise(); - if(this.keysToSet.size) { - const keys = Array.from(this.keysToSet.values()) as string[]; - this.keysToSet.clear(); + const set = this.keysToSet; + if(set.size) { + const keys = Array.from(set.values()) as string[]; + set.clear(); try { //console.log('setItem: will set', key/* , value */); @@ -58,11 +63,34 @@ export default class AppStorage/* Storage ex deferred.resolve(); - if(this.keysToSet.size) { + if(set.size) { this.saveThrottled(); } }, 16, false); + this.deleteThrottled = throttle(async() => { + const deferred = this.deleteDeferred; + this.deleteDeferred = deferredPromise(); + + const set = this.keysToDelete; + if(set.size) { + const keys = Array.from(set.values()) as string[]; + set.clear(); + + try { + await this.storage.delete(keys); + } catch(e) { + console.error('[AS]: delete error:', e, keys); + } + } + + deferred.resolve(); + + if(set.size) { + this.deleteThrottled(); + } + }, 16, false); + this.getThrottled = throttle(async() => { const keys = Array.from(this.getPromises.keys()); @@ -161,6 +189,7 @@ export default class AppStorage/* Storage ex if(this.useStorage && !onlyLocal) { this.keysToSet.add(key); + this.keysToDelete.delete(key); this.saveThrottled(); } } @@ -169,7 +198,7 @@ export default class AppStorage/* Storage ex return this.useStorage ? this.saveDeferred : Promise.resolve(); } - public async delete(key: keyof Storage, saveLocal = false) { + public delete(key: keyof Storage, saveLocal = false) { /* if(!this.cache.hasOwnProperty(key)) { return; } */ @@ -183,14 +212,11 @@ export default class AppStorage/* Storage ex if(this.useStorage) { this.keysToSet.delete(key); - - try { - await this.storage.delete(key as string); - } catch(e) { - this.useStorage = false; - console.error('[AS]: remove error:', e); - } + this.keysToDelete.add(key); + this.deleteThrottled(); } + + return this.useStorage ? this.deleteDeferred : Promise.resolve(); } public clear() { @@ -203,6 +229,7 @@ export default class AppStorage/* Storage ex if(!enabled) { storage.keysToSet.clear(); + storage.keysToDelete.clear(); storage.getPromises.forEach((deferred) => deferred.resolve()); storage.getPromises.clear(); return storage.clear(); diff --git a/src/lib/storages/dialogs.ts b/src/lib/storages/dialogs.ts index dc2a20a5..7f85f983 100644 --- a/src/lib/storages/dialogs.ts +++ b/src/lib/storages/dialogs.ts @@ -9,7 +9,6 @@ * https://github.com/zhukov/webogram/blob/master/LICENSE */ -import { tsNow } from "../../helpers/date"; import type { Chat, DialogPeer, Message, MessagesPeerDialogs, Update } from "../../layer"; import type { AppChatsManager } from "../appManagers/appChatsManager"; import type { AppMessagesManager, Dialog, MyMessage } from "../appManagers/appMessagesManager"; @@ -19,6 +18,7 @@ import type { AppDraftsManager } from "../appManagers/appDraftsManager"; import type { AppNotificationsManager } from "../appManagers/appNotificationsManager"; import type { ApiUpdatesManager } from "../appManagers/apiUpdatesManager"; import type { ServerTimeManager } from "../mtproto/serverTimeManager"; +import { tsNow } from "../../helpers/date"; import apiManager from "../mtproto/mtprotoworker"; import searchIndexManager from "../searchIndexManager"; import { forEachReverse, insertInDescendSortedArray } from "../../helpers/array"; @@ -306,7 +306,7 @@ export default class DialogsStorage { [dialog.peerId]: dialog }); - this.appStateManager.requestPeer(dialog.peerId, 'dialog'); + this.appStateManager.requestPeer(dialog.peerId, 'dialog_' + dialog.peerId, 1); } public pushDialog(dialog: Dialog, offsetDate?: number) { @@ -341,6 +341,11 @@ export default class DialogsStorage { this.byFolders[foundDialog[0].folder_id].splice(foundDialog[1], 1); delete this.dialogs[peerId]; searchIndexManager.indexObject(peerId, '', this.dialogsIndex); + + // clear from state + this.appStateManager.keepPeerSingle(0, 'topMessage_' + peerId); + this.appStateManager.keepPeerSingle(0, 'dialog_' + peerId); + this.storage.delete(peerId); } return foundDialog; diff --git a/src/scss/partials/_chatlist.scss b/src/scss/partials/_chatlist.scss index 71ecd68b..7404ebcf 100644 --- a/src/scss/partials/_chatlist.scss +++ b/src/scss/partials/_chatlist.scss @@ -76,10 +76,10 @@ } ul.chatlist { - padding: 0 .5rem; + padding: 0 .5rem .5rem; @include respond-to(handhelds) { - padding: 0; + padding: 0 0 .5rem; } } diff --git a/src/scss/partials/_leftSidebar.scss b/src/scss/partials/_leftSidebar.scss index b79b77e4..51d610b7 100644 --- a/src/scss/partials/_leftSidebar.scss +++ b/src/scss/partials/_leftSidebar.scss @@ -809,7 +809,7 @@ @include respond-to(handhelds) { padding-bottom: .5rem; } */ - + user-select: none; padding: .5rem 0 1rem; @include respond-to(handhelds) {