diff --git a/src/components/appSelectPeers.ts b/src/components/appSelectPeers.ts index 8f5b33f1..c8edcfeb 100644 --- a/src/components/appSelectPeers.ts +++ b/src/components/appSelectPeers.ts @@ -261,7 +261,7 @@ export default class AppSelectPeers { const pageCount = windowSize.windowH / 72 * 1.25 | 0; const tempId = this.getTempId('dialogs'); - const promise = appMessagesManager.getConversations(this.query, this.offsetIndex, pageCount, this.folderId); + const promise = appMessagesManager.getConversations(this.query, this.offsetIndex, pageCount, this.folderId, true); this.promise = promise; const value = await promise; if(this.tempIds.dialogs !== tempId) { diff --git a/src/components/dialogsContextMenu.ts b/src/components/dialogsContextMenu.ts index 36c88a84..58342384 100644 --- a/src/components/dialogsContextMenu.ts +++ b/src/components/dialogsContextMenu.ts @@ -49,7 +49,7 @@ export default class DialogsContextMenu { text: 'ChatList.Context.Pin', onClick: this.onPinClick, verify: () => { - const isPinned = this.filterId > 1 ? appMessagesManager.filtersStorage.filters[this.filterId].pinned_peers.includes(this.dialog.peerId) : !!this.dialog.pFlags?.pinned; + const isPinned = this.filterId > 1 ? appMessagesManager.filtersStorage.getFilter(this.filterId).pinned_peers.includes(this.dialog.peerId) : !!this.dialog.pFlags?.pinned; return !isPinned; } }, { @@ -57,7 +57,7 @@ export default class DialogsContextMenu { text: 'ChatList.Context.Unpin', onClick: this.onPinClick, verify: () => { - const isPinned = this.filterId > 1 ? appMessagesManager.filtersStorage.filters[this.filterId].pinned_peers.includes(this.dialog.peerId) : !!this.dialog.pFlags?.pinned; + const isPinned = this.filterId > 1 ? appMessagesManager.filtersStorage.getFilter(this.filterId).pinned_peers.includes(this.dialog.peerId) : !!this.dialog.pFlags?.pinned; return isPinned; } }, { diff --git a/src/components/sidebarLeft/tabs/archivedTab.ts b/src/components/sidebarLeft/tabs/archivedTab.ts index a507dcb9..a3aeb799 100644 --- a/src/components/sidebarLeft/tabs/archivedTab.ts +++ b/src/components/sidebarLeft/tabs/archivedTab.ts @@ -34,7 +34,7 @@ export default class AppArchivedTab extends SliderSuperTab { } this.wasFilterId = appDialogsManager.filterId; - appDialogsManager.filterId = AppArchivedTab.filterId; + appDialogsManager.setFilterId(AppArchivedTab.filterId); appDialogsManager.onTabChange(); } @@ -44,7 +44,7 @@ export default class AppArchivedTab extends SliderSuperTab { } onClose() { - appDialogsManager.filterId = this.wasFilterId; + appDialogsManager.setFilterId(this.wasFilterId); appDialogsManager.onTabChange(); } diff --git a/src/components/sidebarLeft/tabs/chatFolders.ts b/src/components/sidebarLeft/tabs/chatFolders.ts index 7e8f0cd2..b8095d69 100644 --- a/src/components/sidebarLeft/tabs/chatFolders.ts +++ b/src/components/sidebarLeft/tabs/chatFolders.ts @@ -97,7 +97,7 @@ export default class AppChatFoldersTab extends SliderSuperTab { const filterId = filter.id; if(!this.filtersRendered.hasOwnProperty(filter.id)) { attachClickEvent(row.container, () => { - new AppEditFolderTab(this.slider).open(appMessagesManager.filtersStorage.filters[filterId]); + new AppEditFolderTab(this.slider).open(appMessagesManager.filtersStorage.getFilter(filterId)); }, {listenerSetter: this.listenerSetter}); } diff --git a/src/index.ts b/src/index.ts index 70b48caf..1e9a9a3a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -169,10 +169,12 @@ console.timeEnd('get storage1'); */ document.documentElement.classList.add('is-safari'); } - document.documentElement.classList.add('is-mac', 'emoji-supported'); + document.documentElement.classList.add('emoji-supported'); if(userAgent.isAppleMobile) { document.documentElement.classList.add('is-ios'); + } else { + document.documentElement.classList.add('is-mac'); } } else if(userAgent.isAndroid) { document.documentElement.classList.add('is-android'); diff --git a/src/layer.d.ts b/src/layer.d.ts index b4137a46..9b7d63ca 100644 --- a/src/layer.d.ts +++ b/src/layer.d.ts @@ -1239,6 +1239,17 @@ export namespace Dialog { draft?: DraftMessage, folder_id?: number, index?: number, + index_0?: number, + index_1?: number, + index_2?: number, + index_3?: number, + index_4?: number, + index_5?: number, + index_6?: number, + index_7?: number, + index_8?: number, + index_9?: number, + index_10?: number, peerId?: number, topMessage?: any, migratedTo?: number @@ -8092,7 +8103,10 @@ export namespace DialogFilter { emoticon?: string, pinned_peers: Array, include_peers: Array, - exclude_peers: Array + exclude_peers: Array, + orderIndex?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10, + peerId?: number, + folder_id?: number }; } diff --git a/src/lib/appManagers/appDialogsManager.ts b/src/lib/appManagers/appDialogsManager.ts index 8b6e5b78..3d286bb0 100644 --- a/src/lib/appManagers/appDialogsManager.ts +++ b/src/lib/appManagers/appDialogsManager.ts @@ -20,7 +20,7 @@ import apiUpdatesManager from "./apiUpdatesManager"; import appPeersManager from './appPeersManager'; import appImManager from "./appImManager"; import appMessagesManager, { Dialog } from "./appMessagesManager"; -import {MyDialogFilter as DialogFilter} from "../storages/filters"; +import {MyDialogFilter as DialogFilter, MyDialogFilter} from "../storages/filters"; import appStateManager, { State } from "./appStateManager"; import appUsersManager from "./appUsersManager"; import Button from "../../components/button"; @@ -33,7 +33,7 @@ import I18n, { FormatterArguments, i18n, LangPackKey, _i18n } from "../langPack" import findUpTag from "../../helpers/dom/findUpTag"; import { LazyLoadQueueIntersector } from "../../components/lazyLoadQueue"; import lottieLoader from "../lottieLoader"; -import { wrapLocalSticker } from "../../components/wrappers"; +import { wrapLocalSticker, wrapPhoto } from "../../components/wrappers"; import AppEditFolderTab from "../../components/sidebarLeft/tabs/editFolder"; import appSidebarLeft, { SettingSection } from "../../components/sidebarLeft"; import { attachClickEvent } from "../../helpers/dom/clickEvent"; @@ -48,6 +48,8 @@ import { isTouchSupported } from "../../helpers/touchSupport"; import handleTabSwipe from "../../helpers/dom/handleTabSwipe"; import windowSize from "../../helpers/windowSize"; import isInDOM from "../../helpers/dom/isInDOM"; +import appPhotosManager from "./appPhotosManager"; +import DialogsStorage from "../storages/dialogs"; export type DialogDom = { avatarEl: AvatarElement, @@ -61,7 +63,7 @@ export type DialogDom = { lastMessageSpan: HTMLSpanElement, containerEl: HTMLElement, listEl: HTMLLIElement, - messageEl: HTMLElement + subtitleEl: HTMLElement }; //const testScroll = false; @@ -116,6 +118,8 @@ export class AppDialogsManager { private loadContacts: () => void; private processContact: (peerId: number) => void; + private indexKey: ReturnType; + constructor() { this.chatsPreloader = putPreloader(null, true); @@ -156,7 +160,7 @@ export class AppDialogsManager { }); } - this.filterId = 0; + this.setFilterId(0); this.addFilter({ id: this.filterId, title: '', @@ -207,7 +211,7 @@ export class AppDialogsManager { const dialog = appMessagesManager.getDialogOnly(peerId); if(dialog) { this.setLastMessage(dialog); - this.validateForFilter(); + this.validateDialogForFilter(dialog); this.setFiltersUnreadCount(); } }); @@ -220,9 +224,10 @@ export class AppDialogsManager { if(this.processContact) { this.processContact(+id); } + + this.validateDialogForFilter(dialog); } - this.validateForFilter(); this.setFiltersUnreadCount(); }); @@ -239,7 +244,7 @@ export class AppDialogsManager { const dialog = appMessagesManager.getDialogOnly(peerId); if(dialog) { this.setUnreadMessages(dialog); - this.validateForFilter(); + this.validateDialogForFilter(dialog); this.setFiltersUnreadCount(); } }); @@ -283,7 +288,7 @@ export class AppDialogsManager { } else if(filter.id === this.filterId) { // это нет тут смысла вызывать, так как будет dialogs_multiupdate //this.validateForFilter(); const folder = appMessagesManager.dialogsStorage.getFolder(filter.id); - this.validateForFilter(); + this.validateListForFilter(); for(let i = 0, length = folder.length; i < length; ++i) { const dialog = folder[i]; this.updateDialog(dialog); @@ -318,13 +323,15 @@ export class AppDialogsManager { rootScope.addEventListener('filter_order', (order) => { const containerToAppend = this.folders.menu as HTMLElement; order.forEach((filterId) => { - const filter = appMessagesManager.filtersStorage.filters[filterId]; + const filter = appMessagesManager.filtersStorage.getFilter(filterId); const renderedFilter = this.filtersRendered[filterId]; positionElementByIndex(renderedFilter.menu, containerToAppend, filter.orderIndex); positionElementByIndex(renderedFilter.container, this.folders.container, filter.orderIndex); }); + this.indexKey = appMessagesManager.dialogsStorage.getDialogIndexKey(this.filterId); + /* if(this.filterId) { const tabIndex = order.indexOf(this.filterId) + 1; selectTab.prevId = tabIndex; @@ -367,7 +374,7 @@ export class AppDialogsManager { clearPromises.push(storage.clear()); } */ - this.validateForFilter(); + this.validateListForFilter(); this.onStateLoaded(state); })//, 5000); @@ -385,7 +392,7 @@ export class AppDialogsManager { if(this.filterId === id) return; this.chatLists[id].innerHTML = ''; - this.filterId = id; + this.setFilterId(id); this.onTabChange(); }, () => { for(const folderId in this.chatLists) { @@ -429,6 +436,11 @@ export class AppDialogsManager { }, 200); } + public setFilterId(filterId: number) { + this.filterId = filterId; + this.indexKey = appMessagesManager.dialogsStorage ? appMessagesManager.dialogsStorage.getDialogIndexKey(this.filterId) : 'index'; + } + private async onStateLoaded(state: State) { appNotificationsManager.getNotifyPeerTypeSettings(); @@ -478,7 +490,7 @@ export class AppDialogsManager { return true; } - const index = dialog.index; + const index = dialog[this.indexKey]; return (!topOffset.index || index <= topOffset.index) && (!bottomOffset.index || index >= bottomOffset.index); } @@ -587,7 +599,7 @@ export class AppDialogsManager { /** * Удалит неподходящие чаты из списка, но не добавит их(!) */ - private validateForFilter() { + private validateListForFilter() { // !WARNING, возможно это было зачем-то, но комментарий исправил архивирование //if(this.filterId === 0) return; @@ -602,6 +614,23 @@ export class AppDialogsManager { } } + /** + * Удалит неподходящие чат из списка, но не добавит его(!) + */ + private validateDialogForFilter(dialog: Dialog, filter?: MyDialogFilter) { + if(this.filterId <= 1 || !this.doms[dialog.peerId]) { + return; + } + + if(!filter) { + filter = appMessagesManager.filtersStorage.getFilter(this.filterId); + } + + if(!appMessagesManager.filtersStorage.testDialogForFilter(dialog, filter)) { + this.deleteDialog(dialog.peerId); + } + } + public generateScrollable(list: HTMLUListElement, filterId: number) { const scrollable = new Scrollable(null, 'CL', 500); scrollable.container.addEventListener('scroll', this.onChatsRegularScroll); @@ -705,11 +734,11 @@ export class AppDialogsManager { const {index: currentOffsetIndex} = this.getOffsetIndex(side); if(currentOffsetIndex) { if(side === 'top') { - const storage = appMessagesManager.dialogsStorage.getFolder(filterId); - const index = storage.findIndex(dialog => dialog.index <= currentOffsetIndex); + const storage = appMessagesManager.dialogsStorage.getFolder(filterId, true); + const index = storage.findIndex(dialog => dialog[this.indexKey] <= currentOffsetIndex); const needIndex = Math.max(0, index - loadCount); loadCount = index - needIndex; - offsetIndex = storage[needIndex].index + 1; + offsetIndex = storage[needIndex][this.indexKey] + 1; } else { offsetIndex = currentOffsetIndex; } @@ -721,7 +750,7 @@ export class AppDialogsManager { //console.time('getDialogs time'); const getConversationPromise = (this.filterId > 1 ? appUsersManager.getContacts() as Promise : Promise.resolve()).then(() => { - return appMessagesManager.getConversations('', offsetIndex, loadCount, filterId); + return appMessagesManager.getConversations('', offsetIndex, loadCount, filterId, true); }); const result = await getConversationPromise; @@ -742,7 +771,7 @@ export class AppDialogsManager { } } else { const storage = appMessagesManager.dialogsStorage.getFolder(filterId); - if(!result.dialogs.length || (storage.length && storage[0].index < offsetIndex)) { + if(!result.dialogs.length || (storage.length && storage[0][this.indexKey] < offsetIndex)) { this.scroll.loadedAll[side] = true; } } @@ -760,7 +789,7 @@ export class AppDialogsManager { const offsetDialog = result.dialogs[side === 'top' ? 0 : result.dialogs.length - 1]; if(offsetDialog) { - this.offsets[side] = offsetDialog.index; + this.offsets[side] = offsetDialog[this.indexKey]; } this.onListLengthChange(); @@ -887,7 +916,7 @@ export class AppDialogsManager { }); attachClickEvent(button, () => { - new AppEditFolderTab(appSidebarLeft).open(appMessagesManager.filtersStorage.filters[this.filterId]); + new AppEditFolderTab(appSidebarLeft).open(appMessagesManager.filtersStorage.getFilter(this.filterId)); }); placeholderContainer.append(button); @@ -1079,8 +1108,8 @@ export class AppDialogsManager { const firstDialog = this.getDialogFromElement(this.chatList.firstElementChild as HTMLElement); const lastDialog = this.getDialogFromElement(this.chatList.lastElementChild as HTMLElement); - this.offsets.top = firstDialog.index; - this.offsets.bottom = lastDialog.index; + this.offsets.top = firstDialog[this.indexKey]; + this.offsets.bottom = lastDialog[this.indexKey]; } private getDialogFromElement(element: HTMLElement) { @@ -1196,7 +1225,7 @@ export class AppDialogsManager { const currentOrder = (Array.from(this.chatList.children) as HTMLElement[]).map(el => +el.dataset.peerId); const {index} = this.getOffsetIndex('top'); - const pos = dialogs.findIndex(dialog => dialog.index <= index); + const pos = dialogs.findIndex(dialog => dialog[this.indexKey] <= index); const offset = Math.max(0, pos); dialogs.forEach((dialog, index) => { @@ -1267,6 +1296,28 @@ export class AppDialogsManager { } else if(!lastMessage.deleted) { fragment = appMessagesManager.wrapMessageForReply(lastMessage); } + + /* if(!lastMessage.deleted && !draftMessage) { + const photo = lastMessage.media?.photo; + if(photo) { + const div = document.createElement('div'); + div.classList.add('dialog-subtitle-media'); + + const size = appPhotosManager.choosePhotoSize(photo, 20, 20); + + wrapPhoto({ + photo, + message: lastMessage, + container: div, + withoutPreloader: true, + size + }); + + fragment.prepend(div); + // dom.subtitleEl.prepend(div); + } + } */ + replaceContent(dom.lastMessageSpan, fragment); /* if(lastMessage.from_id === auth.id) { // You: */ @@ -1344,7 +1395,7 @@ export class AppDialogsManager { } } else dom.statusSpan.classList.remove('tgico-check', 'tgico-checks'); - const filter = appMessagesManager.filtersStorage.filters[this.filterId]; + const filter = appMessagesManager.filtersStorage.getFilter(this.filterId); let isPinned: boolean; if(filter) { isPinned = filter.pinned_peers.indexOf(dialog.peerId) !== -1; @@ -1357,7 +1408,7 @@ export class AppDialogsManager { const isUnreadBadgeMounted = isInDOM(dom.unreadBadge); if(hasUnreadBadge && !isUnreadBadgeMounted) { - dom.messageEl.append(dom.unreadBadge); + dom.subtitleEl.append(dom.unreadBadge); } const hasMentionsBadge = dialog.unread_mentions_count > 1; @@ -1367,7 +1418,7 @@ export class AppDialogsManager { dom.mentionsBadge = document.createElement('div'); dom.mentionsBadge.className = 'dialog-subtitle-badge badge badge-24 mention mention-badge'; dom.mentionsBadge.innerText = '@'; - dom.messageEl.insertBefore(dom.mentionsBadge, dom.lastMessageSpan.nextSibling); + dom.subtitleEl.insertBefore(dom.mentionsBadge, dom.lastMessageSpan.nextSibling); } } @@ -1461,7 +1512,7 @@ export class AppDialogsManager { if(container === undefined) { if(this.doms[peerId] || dialog.migratedTo !== undefined) return; - const filter = appMessagesManager.filtersStorage.filters[this.filterId]; + const filter = appMessagesManager.filtersStorage.getFilter(this.filterId); if((filter && !appMessagesManager.filtersStorage.testDialogForFilter(dialog, filter)) || (!filter && this.filterId !== dialog.folder_id)) { return; } @@ -1552,11 +1603,11 @@ export class AppDialogsManager { rightSpan.append(statusSpan, lastTimeSpan); titleP.append(titleSpanContainer, rightSpan); - const messageEl = document.createElement('p'); - messageEl.classList.add('dialog-subtitle'); - messageEl.append(span); + const subtitleEl = document.createElement('p'); + subtitleEl.classList.add('dialog-subtitle'); + subtitleEl.append(span); - captionDiv.append(titleP, messageEl); + captionDiv.append(titleP, subtitleEl); const dom: DialogDom = { avatarEl, @@ -1569,7 +1620,7 @@ export class AppDialogsManager { lastMessageSpan: span, containerEl: li, listEl: li, - messageEl + subtitleEl }; /* let good = false; diff --git a/src/lib/appManagers/appMessagesManager.ts b/src/lib/appManagers/appMessagesManager.ts index 6a832968..18fc82f4 100644 --- a/src/lib/appManagers/appMessagesManager.ts +++ b/src/lib/appManagers/appMessagesManager.ts @@ -1653,8 +1653,8 @@ export class AppMessagesManager { return outDialogs; } - public getConversations(query = '', offsetIndex?: number, limit = 20, folderId = 0) { - return this.dialogsStorage.getDialogs(query, offsetIndex, limit, folderId); + public getConversations(query = '', offsetIndex?: number, limit = 20, folderId = 0, skipMigrated?: boolean) { + return this.dialogsStorage.getDialogs(query, offsetIndex, limit, folderId, skipMigrated); } public getReadMaxIdIfUnread(peerId: number, threadId?: number) { diff --git a/src/lib/storages/dialogs.ts b/src/lib/storages/dialogs.ts index eb1ded68..b0172cba 100644 --- a/src/lib/storages/dialogs.ts +++ b/src/lib/storages/dialogs.ts @@ -28,12 +28,24 @@ import { safeReplaceObject } from "../../helpers/object"; import { AppStateManager } from "../appManagers/appStateManager"; import { SliceEnd } from "../../helpers/slicedArray"; +export type FolderDialog = { + dialog: Dialog, + index: number +}; + +export type Folder = { + dialogs: FolderDialog[], + count?: number +}; + export default class DialogsStorage { private storage: AppStateManager['storages']['dialogs']; private dialogs: {[peerId: string]: Dialog}; public byFolders: {[folderId: number]: Dialog[]}; + // public folders: {[folderId: number]: Folder} = {}; + private allDialogsLoaded: {[folder_id: number]: boolean}; private dialogsOffsetDate: {[folder_id: number]: number}; private pinnedOrders: {[folder_id: number]: number[]}; @@ -167,9 +179,11 @@ export default class DialogsStorage { return skipMigrated ? arr.filter(dialog => dialog.migratedTo === undefined) : arr; } - const dialogs: {dialog: Dialog, index: number}[] = []; - const filter = this.appMessagesManager.filtersStorage.filters[id]; + // const dialogs: {dialog: Dialog, index: number}[] = []; + const dialogs: Dialog[] = []; + const filter = this.appMessagesManager.filtersStorage.getFilter(id); + const indexStr = this.getDialogIndexKey(id); for(const peerId in this.dialogs) { const dialog = this.dialogs[peerId]; if(this.appMessagesManager.filtersStorage.testDialogForFilter(dialog, filter) && (!skipMigrated || dialog.migratedTo === undefined)) { @@ -177,19 +191,22 @@ export default class DialogsStorage { const pinnedIndex = filter.pinned_peers.indexOf(dialog.peerId); if(pinnedIndex !== -1) { - index = this.generateDialogIndex(this.generateDialogPinnedDateByIndex(filter.pinned_peers.length - 1 - pinnedIndex)); + index = this.generateDialogIndex(this.generateDialogPinnedDateByIndex(filter.pinned_peers.length - 1 - pinnedIndex), true); } else if(dialog.pFlags?.pinned) { index = this.generateIndexForDialog(dialog, true); } else { index = dialog.index; } - dialogs.push({dialog, index}); + dialog[indexStr] = index; + insertInDescendSortedArray(dialogs, dialog, indexStr, -1); } } - dialogs.sort((a, b) => b.index - a.index); - return dialogs.map(d => d.dialog); + return dialogs; + + // dialogs.sort((a, b) => b.index - a.index); + // return dialogs.map(d => d.dialog); } public getDialog(peerId: number, folderId?: number, skipMigrated = true): [Dialog, number] | [] { @@ -231,28 +248,29 @@ export default class DialogsStorage { k - m; 65536 */ - public generateDialogIndex(date?: number) { + public generateDialogIndex(date?: number, isPinned?: boolean) { if(date === undefined) { date = tsNow(true) + this.serverTimeManager.serverTimeOffset; } - return (date * 0x10000) + ((++this.dialogsNum) & 0xFFFF); + return (date * 0x10000) + (isPinned ? 0 : ((++this.dialogsNum) & 0xFFFF)); } public generateIndexForDialog(dialog: Dialog, justReturn = false, message?: MyMessage) { - const channelId = this.appPeersManager.isChannel(dialog.peerId) ? -dialog.peerId : 0; - - let topDate = 0; + let topDate = 0, isPinned: boolean; if(dialog.pFlags.pinned && !justReturn) { topDate = this.generateDialogPinnedDate(dialog); + isPinned = true; } else { if(!message) { message = this.appMessagesManager.getMessageByPeer(dialog.peerId, dialog.top_message); } - + topDate = (message as Message.message).date || topDate; + + const channelId = this.appPeersManager.isChannel(dialog.peerId) ? -dialog.peerId : 0; if(channelId) { - const channel = this.appChatsManager.getChat(channelId); + const channel: Chat.channel = this.appChatsManager.getChat(channelId); if(!topDate || (channel.date && channel.date > topDate)) { topDate = channel.date; } @@ -264,10 +282,10 @@ export default class DialogsStorage { } if(!topDate) { - topDate = Date.now() / 1000; + topDate = tsNow(true); } - const index = this.generateDialogIndex(topDate); + const index = this.generateDialogIndex(topDate, isPinned); if(justReturn) return index; dialog.index = index; } @@ -338,6 +356,14 @@ export default class DialogsStorage { }); this.appStateManager.requestPeer(dialog.peerId, 'dialog_' + dialog.peerId, 1); + + /* for(let id in this.appMessagesManager.filtersStorage.filters) { + const filter = this.appMessagesManager.filtersStorage.filters[id]; + + if(this.appMessagesManager.filtersStorage.testDialogForFilter(dialog, filter)) { + + } + } */ } public pushDialog(dialog: Dialog, offsetDate?: number) { @@ -397,7 +423,7 @@ export default class DialogsStorage { this.appChatsManager.saveApiChats(dialogsResult.chats); this.appMessagesManager.saveMessages(dialogsResult.messages); - this.appMessagesManager.log('applyConversation', dialogsResult); + // this.appMessagesManager.log('applyConversation', dialogsResult); const updatedDialogs: {[peerId: number]: Dialog} = {}; (dialogsResult.dialogs as Dialog[]).forEach((dialog) => { @@ -565,9 +591,19 @@ export default class DialogsStorage { this.pushDialog(dialog, saveOffset && message.date); } - public getDialogs(query = '', offsetIndex?: number, limit = 20, folderId = 0) { + public getDialogIndexKey(filterId: number) { + const indexStr = filterId > 1 ? + `index_${this.appMessagesManager.filtersStorage.getFilter(filterId).orderIndex}` as const : + 'index' as const; + + return indexStr; + } + + public getDialogs(query = '', offsetIndex?: number, limit = 20, folderId = 0, skipMigrated = false) { const realFolderId = folderId > 1 ? 0 : folderId; - let curDialogStorage = this.getFolder(folderId, false); + let curDialogStorage = this.getFolder(folderId, skipMigrated); + + const indexStr = this.getDialogIndexKey(folderId); if(query) { if(!limit || this.cachedResults.query !== query || this.cachedResults.folderId !== folderId) { @@ -576,18 +612,17 @@ export default class DialogsStorage { const results = this.dialogsIndex.search(query); - this.cachedResults.dialogs = []; - + const dialogs: Dialog[] = []; for(const peerId in this.dialogs) { const dialog = this.dialogs[peerId]; if(results.has(dialog.peerId) && dialog.folder_id === folderId) { - this.cachedResults.dialogs.push(dialog); + dialogs.push(dialog); } } - this.cachedResults.dialogs.sort((d1, d2) => d2.index - d1.index); - - this.cachedResults.count = this.cachedResults.dialogs.length; + dialogs.sort((d1, d2) => d2[indexStr] - d1[indexStr]); + this.cachedResults.dialogs = dialogs; + this.cachedResults.count = dialogs.length; } curDialogStorage = this.cachedResults.dialogs; @@ -597,8 +632,8 @@ export default class DialogsStorage { let offset = 0; if(offsetIndex > 0) { - for(; offset < curDialogStorage.length; offset++) { - if(offsetIndex > curDialogStorage[offset].index) { + for(let length = curDialogStorage.length; offset < length; ++offset) { + if(offsetIndex > curDialogStorage[offset][indexStr]) { break; } } @@ -615,11 +650,14 @@ export default class DialogsStorage { return this.appMessagesManager.getTopMessages(limit, realFolderId).then(result => { //const curDialogStorage = this[folderId]; + if(skipMigrated) { + curDialogStorage = this.getFolder(folderId, skipMigrated); + } offset = 0; if(offsetIndex > 0) { - for(; offset < curDialogStorage.length; offset++) { - if(offsetIndex > curDialogStorage[offset].index) { + for(let length = curDialogStorage.length; offset < length; ++offset) { + if(offsetIndex > curDialogStorage[offset][indexStr]) { break; } } diff --git a/src/lib/storages/filters.ts b/src/lib/storages/filters.ts index 26278e9d..f57118c2 100644 --- a/src/lib/storages/filters.ts +++ b/src/lib/storages/filters.ts @@ -21,8 +21,7 @@ import { AppStateManager } from "../appManagers/appStateManager"; export type MyDialogFilter = Modify; // ! because 0 index is 'All Chats' @@ -51,6 +50,10 @@ export default class FiltersStorage { if(filter.hasOwnProperty('orderIndex') && filter.orderIndex >= this.orderIndex) { this.orderIndex = filter.orderIndex + 1; } + + /* this.appMessagesManager.dialogsStorage.folders[+filterId] = { + dialogs: [] + }; */ } }); @@ -114,18 +117,16 @@ export default class FiltersStorage { }; public testDialogForFilter(dialog: Dialog, filter: MyDialogFilter) { + const peerId = dialog.peerId; + // exclude_peers - for(const peerId of filter.exclude_peers) { - if(peerId === dialog.peerId) { - return false; - } + if(filter.exclude_peers.includes(peerId)) { + return false; } // include_peers - for(const peerId of filter.include_peers) { - if(peerId === dialog.peerId) { - return true; - } + if(filter.include_peers.includes(peerId)) { + return true; } const pFlags = filter.pFlags; @@ -142,13 +143,12 @@ export default class FiltersStorage { // exclude_muted if(pFlags.exclude_muted) { - const isMuted = this.appNotificationsManager.isPeerLocalMuted(dialog.peerId); + const isMuted = this.appNotificationsManager.isPeerLocalMuted(peerId); if(isMuted) { return false; } } - const peerId = dialog.peerId; if(peerId < 0) { // broadcasts if(pFlags.broadcasts && this.appPeersManager.isBroadcast(peerId)) { @@ -161,7 +161,7 @@ export default class FiltersStorage { } } else { // bots - if(this.appPeersManager.isBot(peerId)) { + if(this.appUsersManager.isBot(peerId)) { return !!pFlags.bots; } @@ -179,6 +179,14 @@ export default class FiltersStorage { return false; } + public testDialogForFilterId(dialog: Dialog, filterId: number) { + return this.testDialogForFilter(dialog, this.filters[filterId]); + } + + public getFilter(filterId: number) { + return this.filters[filterId]; + } + public toggleDialogPin(peerId: number, filterId: number) { const filter = this.filters[filterId]; @@ -195,7 +203,7 @@ export default class FiltersStorage { } public createDialogFilter(filter: MyDialogFilter) { - let maxId = Math.max(1, ...Object.keys(this.filters).map(i => +i)); + const maxId = Math.max(1, ...Object.keys(this.filters).map(i => +i)); filter = copy(filter); filter.id = maxId + 1; return this.updateDialogFilter(filter); @@ -293,7 +301,7 @@ export default class FiltersStorage { this.orderIndex = filter.orderIndex + 1; } } else { - filter.orderIndex = this.orderIndex++; + filter.orderIndex = this.orderIndex++ as DialogFilter['orderIndex']; } this.appStateManager.pushToState('filters', this.filters); diff --git a/src/scripts/in/schema_additional_params.json b/src/scripts/in/schema_additional_params.json index 4e0dab8a..a3bdd20c 100644 --- a/src/scripts/in/schema_additional_params.json +++ b/src/scripts/in/schema_additional_params.json @@ -29,6 +29,17 @@ "predicate": "dialog", "params": [ {"name": "index", "type": "number"}, + {"name": "index_0", "type": "number"}, + {"name": "index_1", "type": "number"}, + {"name": "index_2", "type": "number"}, + {"name": "index_3", "type": "number"}, + {"name": "index_4", "type": "number"}, + {"name": "index_5", "type": "number"}, + {"name": "index_6", "type": "number"}, + {"name": "index_7", "type": "number"}, + {"name": "index_8", "type": "number"}, + {"name": "index_9", "type": "number"}, + {"name": "index_10", "type": "number"}, {"name": "peerId", "type": "number"}, {"name": "topMessage", "type": "any"}, {"name": "migratedTo", "type": "number"} @@ -40,6 +51,13 @@ {"name": "peerId", "type": "number"}, {"name": "folder_id", "type": "number"} ] +}, { + "predicate": "dialogFilter", + "params": [ + {"name": "orderIndex", "type": "0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10"}, + {"name": "peerId", "type": "number"}, + {"name": "folder_id", "type": "number"} + ] }, { "predicate": "message", "params": [ diff --git a/src/scss/partials/_chat.scss b/src/scss/partials/_chat.scss index 44f63e08..f841f38b 100644 --- a/src/scss/partials/_chat.scss +++ b/src/scss/partials/_chat.scss @@ -1148,7 +1148,7 @@ $chat-helper-size: 36px; @include respond-to(handhelds) { padding: 0 $chat-padding-handhelds; - html.is-mac & { + html.is-ios & { -webkit-user-select: none; -webkit-touch-callout: none; } diff --git a/src/scss/partials/_chatlist.scss b/src/scss/partials/_chatlist.scss index 9d08f4e3..3d5e90cc 100644 --- a/src/scss/partials/_chatlist.scss +++ b/src/scss/partials/_chatlist.scss @@ -295,6 +295,25 @@ ul.chatlist { transition: none; } */ } + + &-media { + width: 1.25rem; + height: 1.25rem; + position: relative; + flex: 0 0 auto; + border-radius: .1875rem; + margin-top: -0.1875rem; + margin-right: 0.375rem; + display: inline-block; + vertical-align: middle; + + .media-photo { + width: inherit; + height: inherit; + object-fit: cover; + border-radius: inherit; + } + } } } @@ -423,6 +442,10 @@ ul.chatlist { .mention { padding: 0; background-color: var(--chatlist-status-color) !important; + + html.is-mac & { + line-height: 22px !important; + } } .mention-badge {