From 44a915a31c561db3de5a857a6eb79abea2bf3cc8 Mon Sep 17 00:00:00 2001 From: morethanwords Date: Wed, 15 Sep 2021 16:02:09 +0400 Subject: [PATCH] Fix starting multiselect from grouped documents --- src/components/chat/selection.ts | 13 ++++- src/components/sidebarRight/tabs/editChat.ts | 12 +++-- .../sidebarRight/tabs/groupPermissions.ts | 50 ++++++++++++------- src/pages/pageIm.ts | 40 ++++++++------- 4 files changed, 73 insertions(+), 42 deletions(-) diff --git a/src/components/chat/selection.ts b/src/components/chat/selection.ts index 19ff5e70..07c585b3 100644 --- a/src/components/chat/selection.ts +++ b/src/components/chat/selection.ts @@ -35,6 +35,7 @@ import isInDOM from "../../helpers/dom/isInDOM"; import { randomLong } from "../../helpers/random"; import { attachContextMenuListener } from "../misc"; import { attachClickEvent, AttachClickOptions } from "../../helpers/dom/clickEvent"; +import findUpAsChild from "../../helpers/dom/findUpAsChild"; const accumulateMapSet = (map: Map>) => { return [...map.values()].reduce((acc, v) => acc + v.size, 0); @@ -136,6 +137,8 @@ class AppSelection { const slice = elements.slice(firstIndex + 1, lastIndex); + console.log('getElementsBetween', first, last, slice, firstIndex, lastIndex, isHigher); + return slice; }; @@ -190,8 +193,16 @@ class AppSelection { seenSet.add(mid); if((selecting && !isSelected) || (!selecting && isSelected)) { + const seenLength = accumulateMapSet(seen); if(this.toggleByElement && checkBetween) { + if(seenLength < 2) { + if(findUpAsChild(element, firstTarget)) { + firstTarget = element; + } + } + const elementsBetween = getElementsBetween(firstTarget, element); + console.log(elementsBetween); if(elementsBetween.length) { elementsBetween.forEach(element => { processElement(element, false); @@ -200,7 +211,7 @@ class AppSelection { } if(!this.selectedMids.size) { - if(accumulateMapSet(seen) === 2 && this.toggleByMid) { + if(seenLength === 2 && this.toggleByMid) { for(const [peerId, mids] of seen) { for(const mid of mids) { this.toggleByMid(peerId, mid); diff --git a/src/components/sidebarRight/tabs/editChat.ts b/src/components/sidebarRight/tabs/editChat.ts index fa20cea4..2d3cfcec 100644 --- a/src/components/sidebarRight/tabs/editChat.ts +++ b/src/components/sidebarRight/tabs/editChat.ts @@ -255,8 +255,7 @@ export default class AppEditChatTab extends SliderSuperTab { if(!isBroadcast && appChatsManager.hasRights(this.chatId, 'change_permissions')) { const showChatHistoryCheckboxField = new CheckboxField({ text: 'ChatHistory', - withRipple: true, - checked: !(chatFull as ChatFull.channelFull).pFlags.hidden_prehistory + withRipple: true }); this.listenerSetter.add(showChatHistoryCheckboxField.input)('change', () => { @@ -266,9 +265,12 @@ export default class AppEditChatTab extends SliderSuperTab { }); }); - addChatUpdateListener(() => { - showChatHistoryCheckboxField.setValueSilently(!(chatFull as ChatFull.channelFull).pFlags.hidden_prehistory); - }); + const onChatUpdate = () => { + showChatHistoryCheckboxField.setValueSilently(isChannel && !(chatFull as ChatFull.channelFull).pFlags.hidden_prehistory); + }; + + onChatUpdate(); + addChatUpdateListener(onChatUpdate); section.content.append(showChatHistoryCheckboxField.label); } diff --git a/src/components/sidebarRight/tabs/groupPermissions.ts b/src/components/sidebarRight/tabs/groupPermissions.ts index 59203a4f..094fa791 100644 --- a/src/components/sidebarRight/tabs/groupPermissions.ts +++ b/src/components/sidebarRight/tabs/groupPermissions.ts @@ -288,26 +288,42 @@ export default class AppGroupPermissionsTab extends SliderSuperTabEventable { }; let exceptionsCount = 0; - const LOAD_COUNT = 50; - const loader = new ScrollableLoader({ - scrollable: this.scrollable, - getPromise: () => { - return appProfileManager.getChannelParticipants(this.chatId, {_: 'channelParticipantsBanned', q: ''}, LOAD_COUNT, list.childElementCount).then(res => { - for(const participant of res.participants) { - add(participant as ChannelParticipant.channelParticipantBanned, true); - } - - exceptionsCount = res.count; - setLength(); - - return res.participants.length < LOAD_COUNT || res.count === list.childElementCount; - }); - } - }); + let loader: ScrollableLoader; + const setLoader = () => { + const LOAD_COUNT = 50; + loader = new ScrollableLoader({ + scrollable: this.scrollable, + getPromise: () => { + return appProfileManager.getChannelParticipants(this.chatId, {_: 'channelParticipantsBanned', q: ''}, LOAD_COUNT, list.childElementCount).then(res => { + for(const participant of res.participants) { + add(participant as ChannelParticipant.channelParticipantBanned, true); + } + + exceptionsCount = res.count; + setLength(); + + return res.participants.length < LOAD_COUNT || res.count === list.childElementCount; + }); + } + }); + + return loader.load(); + }; this.scrollable.append(section.container); - await loader.load(); + if(appChatsManager.isChannel(this.chatId)) { + await setLoader(); + } else { + setLength(); + + this.listenerSetter.add(rootScope)('dialog_migrate', ({migrateFrom, migrateTo}) => { + if(this.chatId === migrateFrom) { + this.chatId = migrateTo; + setLoader(); + } + }); + } } } diff --git a/src/pages/pageIm.ts b/src/pages/pageIm.ts index 74cc5b84..b5e59b7c 100644 --- a/src/pages/pageIm.ts +++ b/src/pages/pageIm.ts @@ -32,26 +32,28 @@ let onFirstMount = () => { return loadFonts().then(() => { return new Promise((resolve) => { window.requestAnimationFrame(() => { - const promise = import('../lib/appManagers/appDialogsManager'); - promise.finally(async() => { - //alert('pageIm!'); - resolve(); - - //AudioContext && global.navigator && global.navigator.mediaDevices && global.navigator.mediaDevices.getUserMedia && global.WebAssembly; - - /* // @ts-ignore - var AudioContext = globalThis.AudioContext || globalThis.webkitAudioContext; - alert('AudioContext:' + typeof(AudioContext)); - // @ts-ignore - alert('global.navigator:' + typeof(navigator)); - alert('navigator.mediaDevices:' + typeof(navigator.mediaDevices)); - alert('navigator.mediaDevices.getUserMedia:' + typeof(navigator.mediaDevices?.getUserMedia)); - alert('global.WebAssembly:' + typeof(WebAssembly)); */ - - //(Array.from(document.getElementsByClassName('rp')) as HTMLElement[]).forEach(el => ripple(el)); - }); + // setTimeout(() => { + const promise = import('../lib/appManagers/appDialogsManager'); + promise.finally(async() => { + //alert('pageIm!'); + resolve(); + + //AudioContext && global.navigator && global.navigator.mediaDevices && global.navigator.mediaDevices.getUserMedia && global.WebAssembly; + + /* // @ts-ignore + var AudioContext = globalThis.AudioContext || globalThis.webkitAudioContext; + alert('AudioContext:' + typeof(AudioContext)); + // @ts-ignore + alert('global.navigator:' + typeof(navigator)); + alert('navigator.mediaDevices:' + typeof(navigator.mediaDevices)); + alert('navigator.mediaDevices.getUserMedia:' + typeof(navigator.mediaDevices?.getUserMedia)); + alert('global.WebAssembly:' + typeof(WebAssembly)); */ + + //(Array.from(document.getElementsByClassName('rp')) as HTMLElement[]).forEach(el => ripple(el)); + }); + // }, 5e3); }); - }); + }) }); //let promise = /* Promise.resolve() */.then(() => {//import('../lib/services').then(services => {