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. 2
      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 @@
//import { logger } from "../polyfill";
/* /*
* https://github.com/morethanwords/tweb * https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko * Copyright (C) 2019-2021 Eduard Kuzmenko
@ -36,6 +35,7 @@ import findUpTag from "../../helpers/dom/findUpTag";
import PeerTitle from "../peerTitle"; import PeerTitle from "../peerTitle";
import App from "../../config/app"; import App from "../../config/app";
import ButtonMenuToggle from "../buttonMenuToggle"; import ButtonMenuToggle from "../buttonMenuToggle";
import replaceContent from "../../helpers/dom/replaceContent";
export const LEFT_COLUMN_ACTIVE_CLASSNAME = 'is-left-column-shown'; 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(); const appSidebarLeft = new AppSidebarLeft();
MOUNT_CLASS_TO.appSidebarLeft = appSidebarLeft; MOUNT_CLASS_TO.appSidebarLeft = appSidebarLeft;
export default 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 @@
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
import { SettingSection } from ".."; import { SettingSection } from "..";
import { hexaToRgba } from "../../../helpers/color"; import { hexaToRgba } from "../../../helpers/color";
import { attachClickEvent } from "../../../helpers/dom/clickEvent";
import findUpClassName from "../../../helpers/dom/findUpClassName"; import findUpClassName from "../../../helpers/dom/findUpClassName";
import highlightningColor from "../../../helpers/highlightningColor"; import highlightningColor from "../../../helpers/highlightningColor";
import { throttle } from "../../../helpers/schedulers"; import { throttle } from "../../../helpers/schedulers";
@ -142,7 +149,3 @@ export default class AppBackgroundColorTab extends SliderSuperTab {
return super.onCloseAfterTimeout(); 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";
import rootScope from "../../../lib/rootScope"; import rootScope from "../../../lib/rootScope";
import findUpTag from "../../../helpers/dom/findUpTag"; import findUpTag from "../../../helpers/dom/findUpTag";
import ButtonCorner from "../../buttonCorner"; import ButtonCorner from "../../buttonCorner";
import { attachClickEvent } from "../../../helpers/dom/clickEvent";
export default class AppBlockedUsersTab extends SliderSuperTab { export default class AppBlockedUsersTab extends SliderSuperTab {
public peerIds: number[]; public peerIds: number[];
@ -156,7 +157,3 @@ export default class AppBlockedUsersTab extends SliderSuperTab {
return super.onCloseAfterTimeout(); 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 @@
/*
* 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 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) { 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) => { const onTouchEnd = (event: TouchEvent) => {
document.removeEventListener('touchmove', onTouchMove); 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}); 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); onTouchMove(event);
document.addEventListener('touchmove', onTouchMove, {passive: false}); 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 () => { return () => {
element.removeEventListener('mousedown', onMouseDown); element.removeEventListener('mousedown', onMouseDown);

2
src/lib/appManagers/appDialogsManager.ts

@ -908,7 +908,7 @@ export class AppDialogsManager {
const offsetTop = this.folders.container.offsetTop; const offsetTop = this.folders.container.offsetTop;
const firstY = rectContainer.y + 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 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; const lastElement = findUpTag(document.elementFromPoint(Math.ceil(rectTarget.x), Math.floor(lastY + rectContainer.height - 1)), firstElementChild.tagName) as HTMLElement;

2
src/lib/appManagers/appStateManager.ts

@ -378,8 +378,10 @@ export class AppStateManager extends EventListenerBase<{
} }
} }
if(peerId) {
this.singlePeerMap.set(type, peerId); this.singlePeerMap.set(type, peerId);
} }
}
/* public resetState() { /* public resetState() {
for(let i in this.state) { for(let i in this.state) {

51
src/lib/storage.ts

@ -31,6 +31,10 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex
private saveThrottled: () => void; private saveThrottled: () => void;
private saveDeferred = deferredPromise<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}) { constructor(storageOptions: Omit<IDBOptions, 'storeName' | 'stores'> & {stores?: DatabaseStore[], storeName: DatabaseStoreName}) {
this.storage = new IDBStorage(storageOptions); this.storage = new IDBStorage(storageOptions);
@ -40,9 +44,10 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex
const deferred = this.saveDeferred; const deferred = this.saveDeferred;
this.saveDeferred = deferredPromise<void>(); this.saveDeferred = deferredPromise<void>();
if(this.keysToSet.size) { const set = this.keysToSet;
const keys = Array.from(this.keysToSet.values()) as string[]; if(set.size) {
this.keysToSet.clear(); const keys = Array.from(set.values()) as string[];
set.clear();
try { try {
//console.log('setItem: will set', key/* , value */); //console.log('setItem: will set', key/* , value */);
@ -58,11 +63,34 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex
deferred.resolve(); deferred.resolve();
if(this.keysToSet.size) { if(set.size) {
this.saveThrottled(); this.saveThrottled();
} }
}, 16, false); }, 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() => { this.getThrottled = throttle(async() => {
const keys = Array.from(this.getPromises.keys()); const keys = Array.from(this.getPromises.keys());
@ -161,6 +189,7 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex
if(this.useStorage && !onlyLocal) { if(this.useStorage && !onlyLocal) {
this.keysToSet.add(key); this.keysToSet.add(key);
this.keysToDelete.delete(key);
this.saveThrottled(); this.saveThrottled();
} }
} }
@ -169,7 +198,7 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex
return this.useStorage ? this.saveDeferred : Promise.resolve(); 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)) { /* if(!this.cache.hasOwnProperty(key)) {
return; return;
} */ } */
@ -183,14 +212,11 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex
if(this.useStorage) { if(this.useStorage) {
this.keysToSet.delete(key); this.keysToSet.delete(key);
this.keysToDelete.add(key);
try { this.deleteThrottled();
await this.storage.delete(key as string);
} catch(e) {
this.useStorage = false;
console.error('[AS]: remove error:', e);
}
} }
return this.useStorage ? this.deleteDeferred : Promise.resolve();
} }
public clear() { public clear() {
@ -203,6 +229,7 @@ export default class AppStorage<Storage extends Record<string, any>/* Storage ex
if(!enabled) { if(!enabled) {
storage.keysToSet.clear(); storage.keysToSet.clear();
storage.keysToDelete.clear();
storage.getPromises.forEach((deferred) => deferred.resolve()); storage.getPromises.forEach((deferred) => deferred.resolve());
storage.getPromises.clear(); storage.getPromises.clear();
return storage.clear(); return storage.clear();

9
src/lib/storages/dialogs.ts

@ -9,7 +9,6 @@
* https://github.com/zhukov/webogram/blob/master/LICENSE * https://github.com/zhukov/webogram/blob/master/LICENSE
*/ */
import { tsNow } from "../../helpers/date";
import type { Chat, DialogPeer, Message, MessagesPeerDialogs, Update } from "../../layer"; import type { Chat, DialogPeer, Message, MessagesPeerDialogs, Update } from "../../layer";
import type { AppChatsManager } from "../appManagers/appChatsManager"; import type { AppChatsManager } from "../appManagers/appChatsManager";
import type { AppMessagesManager, Dialog, MyMessage } from "../appManagers/appMessagesManager"; 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 { AppNotificationsManager } from "../appManagers/appNotificationsManager";
import type { ApiUpdatesManager } from "../appManagers/apiUpdatesManager"; import type { ApiUpdatesManager } from "../appManagers/apiUpdatesManager";
import type { ServerTimeManager } from "../mtproto/serverTimeManager"; import type { ServerTimeManager } from "../mtproto/serverTimeManager";
import { tsNow } from "../../helpers/date";
import apiManager from "../mtproto/mtprotoworker"; import apiManager from "../mtproto/mtprotoworker";
import searchIndexManager from "../searchIndexManager"; import searchIndexManager from "../searchIndexManager";
import { forEachReverse, insertInDescendSortedArray } from "../../helpers/array"; import { forEachReverse, insertInDescendSortedArray } from "../../helpers/array";
@ -306,7 +306,7 @@ export default class DialogsStorage {
[dialog.peerId]: dialog [dialog.peerId]: dialog
}); });
this.appStateManager.requestPeer(dialog.peerId, 'dialog'); this.appStateManager.requestPeer(dialog.peerId, 'dialog_' + dialog.peerId, 1);
} }
public pushDialog(dialog: Dialog, offsetDate?: number) { public pushDialog(dialog: Dialog, offsetDate?: number) {
@ -341,6 +341,11 @@ export default class DialogsStorage {
this.byFolders[foundDialog[0].folder_id].splice(foundDialog[1], 1); this.byFolders[foundDialog[0].folder_id].splice(foundDialog[1], 1);
delete this.dialogs[peerId]; delete this.dialogs[peerId];
searchIndexManager.indexObject(peerId, '', this.dialogsIndex); 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; return foundDialog;

4
src/scss/partials/_chatlist.scss

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

2
src/scss/partials/_leftSidebar.scss

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

Loading…
Cancel
Save