Browse Source

(Android) Fix color picker

Fix deleting dialogs
Fix missed implementations
master
Eduard Kuzmenko 4 years ago
parent
commit
e170b90a78
  1. 6
      src/components/sidebarLeft/index.ts
  2. 11
      src/components/sidebarLeft/tabs/backgroundColor.ts
  3. 5
      src/components/sidebarLeft/tabs/blockedUsers.ts
  4. 12
      src/helpers/dom/attachGrabListeners.ts
  5. 2
      src/lib/appManagers/appDialogsManager.ts
  6. 4
      src/lib/appManagers/appStateManager.ts
  7. 51
      src/lib/storage.ts
  8. 9
      src/lib/storages/dialogs.ts
  9. 4
      src/scss/partials/_chatlist.scss
  10. 2
      src/scss/partials/_leftSidebar.scss

6
src/components/sidebarLeft/index.ts

@ -1,4 +1,3 @@ @@ -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"; @@ -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 @@ -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.");
}

11
src/components/sidebarLeft/tabs/backgroundColor.ts

@ -1,5 +1,12 @@ @@ -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 { @@ -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.");
}

5
src/components/sidebarLeft/tabs/blockedUsers.ts

@ -14,6 +14,7 @@ import PopupPickUser from "../../popups/pickUser"; @@ -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 { @@ -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.");
}

12
src/helpers/dom/attachGrabListeners.ts

@ -1,3 +1,9 @@ @@ -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 @@ -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 @@ -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);

2
src/lib/appManagers/appDialogsManager.ts

@ -908,7 +908,7 @@ export class AppDialogsManager { @@ -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;

4
src/lib/appManagers/appStateManager.ts

@ -378,7 +378,9 @@ export class AppStateManager extends EventListenerBase<{ @@ -378,7 +378,9 @@ export class AppStateManager extends EventListenerBase<{
}
}
this.singlePeerMap.set(type, peerId);
if(peerId) {
this.singlePeerMap.set(type, peerId);
}
}
/* public resetState() {

51
src/lib/storage.ts

@ -31,6 +31,10 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex @@ -31,6 +31,10 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex
private saveThrottled: () => void;
private saveDeferred = deferredPromise<void>();
private keysToDelete: Set<keyof Storage> = new Set();
private deleteThrottled: () => void;
private deleteDeferred = deferredPromise<void>();
constructor(storageOptions: Omit<IDBOptions, 'storeName' | 'stores'> & {stores?: DatabaseStore[], storeName: DatabaseStoreName}) {
this.storage = new IDBStorage(storageOptions);
@ -40,9 +44,10 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex @@ -40,9 +44,10 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex
const deferred = this.saveDeferred;
this.saveDeferred = deferredPromise<void>();
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 extends Record<string, any>/* Storage ex @@ -58,11 +63,34 @@ export default class AppStorage<Storage extends Record<string, any>/* 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<void>();
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 extends Record<string, any>/* Storage ex @@ -161,6 +189,7 @@ export default class AppStorage<Storage extends Record<string, any>/* 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 extends Record<string, any>/* Storage ex @@ -169,7 +198,7 @@ export default class AppStorage<Storage extends Record<string, any>/* 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 extends Record<string, any>/* Storage ex @@ -183,14 +212,11 @@ export default class AppStorage<Storage extends Record<string, any>/* 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 extends Record<string, any>/* Storage ex @@ -203,6 +229,7 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex
if(!enabled) {
storage.keysToSet.clear();
storage.keysToDelete.clear();
storage.getPromises.forEach((deferred) => deferred.resolve());
storage.getPromises.clear();
return storage.clear();

9
src/lib/storages/dialogs.ts

@ -9,7 +9,6 @@ @@ -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"; @@ -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 { @@ -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 { @@ -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;

4
src/scss/partials/_chatlist.scss

@ -76,10 +76,10 @@ @@ -76,10 +76,10 @@
}
ul.chatlist {
padding: 0 .5rem;
padding: 0 .5rem .5rem;
@include respond-to(handhelds) {
padding: 0;
padding: 0 0 .5rem;
}
}

2
src/scss/partials/_leftSidebar.scss

@ -809,7 +809,7 @@ @@ -809,7 +809,7 @@
@include respond-to(handhelds) {
padding-bottom: .5rem;
} */
user-select: none;
padding: .5rem 0 1rem;
@include respond-to(handhelds) {

Loading…
Cancel
Save