Browse Source

Load missing included chats for filter

Display dialog with unread mention in unmuted filter
master
morethanwords 3 years ago
parent
commit
8b04630124
  1. 4
      src/components/chat/bubbles.ts
  2. 46
      src/components/sidebarLeft/tabs/editFolder.ts
  3. 2
      src/components/sliderTab.ts
  4. 37
      src/lib/appManagers/appMessagesManager.ts
  5. 22
      src/lib/storages/filters.ts

4
src/components/chat/bubbles.ts

@ -2193,7 +2193,9 @@ export default class ChatBubbles { @@ -2193,7 +2193,9 @@ export default class ChatBubbles {
const queue = this.messagesQueue.slice();
this.messagesQueue.length = 0;
const promises = queue.reduce((acc, {promises}) => acc.concat(promises), []);
const promises = queue.reduce((acc, {promises}) => (acc.push(...promises), acc), []);
// promises.push(pause(200));
// * это нужно для того, чтобы если захочет подгрузить reply или какое-либо сообщение, то скролл не прервался
// * если добавить этот промис - в таком случае нужно сделать, чтобы скроллило к последнему сообщению после рендера

46
src/components/sidebarLeft/tabs/editFolder.ts

@ -224,17 +224,27 @@ export default class AppEditFolderTab extends SliderSuperTab { @@ -224,17 +224,27 @@ export default class AppEditFolderTab extends SliderSuperTab {
this.editCheckForChange();
});
return this.loadAnimationPromise = lottieLoader.loadAnimationAsAsset({
container: this.stickerContainer,
loop: false,
autoplay: false,
width: 86,
height: 86
}, 'Folders_2').then(player => {
this.animation = player;
return lottieLoader.waitForFirstFrame(player);
});
const reloadMissingPromises: Promise<any>[] = this.type === 'edit' ? [
appMessagesManager.filtersStorage.reloadMissingPeerIds(this.filter.id, 'pinned_peers'),
appMessagesManager.filtersStorage.reloadMissingPeerIds(this.filter.id, 'include_peers'),
appMessagesManager.filtersStorage.reloadMissingPeerIds(this.filter.id, 'exclude_peers')
] : [];
return Promise.all([
this.loadAnimationPromise = lottieLoader.loadAnimationAsAsset({
container: this.stickerContainer,
loop: false,
autoplay: false,
width: 86,
height: 86
}, 'Folders_2').then(player => {
this.animation = player;
return lottieLoader.waitForFirstFrame(player);
}),
...reloadMissingPromises
]);
}
onOpenAfterTimeout() {
@ -327,8 +337,10 @@ export default class AppEditFolderTab extends SliderSuperTab { @@ -327,8 +337,10 @@ export default class AppEditFolderTab extends SliderSuperTab {
};
setFilter(filter: DialogFilter, firstTime: boolean) {
// cleanup
Array.from(this.container.querySelectorAll('ul, .load-more')).forEach(el => el.remove());
if(this.container) {
// cleanup
Array.from(this.container.querySelectorAll('ul, .load-more')).forEach(el => el.remove());
}
if(firstTime) {
this.originalFilter = filter;
@ -341,8 +353,6 @@ export default class AppEditFolderTab extends SliderSuperTab { @@ -341,8 +353,6 @@ export default class AppEditFolderTab extends SliderSuperTab {
}
public open(filter?: DialogFilter) {
const ret = super.open();
if(filter === undefined) {
this.setFilter({
_: 'dialogFilter',
@ -361,9 +371,11 @@ export default class AppEditFolderTab extends SliderSuperTab { @@ -361,9 +371,11 @@ export default class AppEditFolderTab extends SliderSuperTab {
} else {
this.setFilter(filter, true);
this.type = 'edit';
this.onEditOpen();
}
return ret;
return super.open().then(() => {
if(this.type === 'edit') this.onEditOpen();
else this.onCreateOpen();
});
}
}

2
src/components/sliderTab.ts

@ -87,7 +87,7 @@ export default class SliderSuperTab implements SliderTab { @@ -87,7 +87,7 @@ export default class SliderSuperTab implements SliderTab {
}
}
return this.slider.selectTab(this);
this.slider.selectTab(this);
}
protected init(): Promise<any> | any {

37
src/lib/appManagers/appMessagesManager.ts

@ -2733,9 +2733,9 @@ export class AppMessagesManager { @@ -2733,9 +2733,9 @@ export class AppMessagesManager {
public wrapMessageForReply(message: MyMessage | MyDraftMessage, text: string, usingMids: number[], plain: true, highlightWord?: string, withoutMediaType?: boolean): string;
public wrapMessageForReply(message: MyMessage | MyDraftMessage, text?: string, usingMids?: number[], plain?: false, highlightWord?: string, withoutMediaType?: boolean): DocumentFragment;
public wrapMessageForReply(message: MyMessage | MyDraftMessage, text: string = (message as Message.message).message, usingMids?: number[], plain?: boolean, highlightWord?: string, withoutMediaType?: boolean): DocumentFragment | string {
const parts: (HTMLElement | string)[] = [];
const parts: (Node | string)[] = [];
const addPart = (langKey: LangPackKey, part?: string | HTMLElement, text?: string) => {
const addPart = (langKey: LangPackKey, part?: string | HTMLElement) => {
if(langKey) {
part = plain ? I18n.format(langKey, true) : i18n(langKey);
}
@ -2748,10 +2748,6 @@ export class AppMessagesManager { @@ -2748,10 +2748,6 @@ export class AppMessagesManager {
else el.append(part);
parts.push(el);
}
if(text) {
parts.push(', ');
}
};
if((message as Message.message).media) {
@ -2776,7 +2772,7 @@ export class AppMessagesManager { @@ -2776,7 +2772,7 @@ export class AppMessagesManager {
text = this.getAlbumText(message.grouped_id).message;
if(!withoutMediaType) {
addPart('AttachAlbum', undefined, text);
addPart('AttachAlbum');
}
}
} else {
@ -2787,15 +2783,14 @@ export class AppMessagesManager { @@ -2787,15 +2783,14 @@ export class AppMessagesManager {
const media = message.media;
switch(media._) {
case 'messageMediaPhoto':
addPart('AttachPhoto', undefined, message.message);
addPart('AttachPhoto');
break;
case 'messageMediaDice':
addPart(undefined, plain ? media.emoticon : RichTextProcessor.wrapEmojiText(media.emoticon));
break;
case 'messageMediaVenue': {
const text = plain ? media.title : RichTextProcessor.wrapEmojiText(media.title);
addPart('AttachLocation', undefined, text);
parts.push(htmlToDocumentFragment(text) as any);
text = media.title;
addPart('AttachLocation');
break;
}
case 'messageMediaGeo':
@ -2812,20 +2807,20 @@ export class AppMessagesManager { @@ -2812,20 +2807,20 @@ export class AppMessagesManager {
break;
case 'messageMediaGame': {
const prefix = '🎮' + ' ';
addPart(undefined, plain ? prefix + media.game.title : RichTextProcessor.wrapEmojiText(prefix + media.game.title));
text = prefix + media.game.title;
break;
}
case 'messageMediaDocument': {
const document = media.document as MyDocument;
if(document.type === 'video') {
addPart('AttachVideo', undefined, message.message);
addPart('AttachVideo');
} else if(document.type === 'voice') {
addPart('AttachAudio', undefined, message.message);
addPart('AttachAudio');
} else if(document.type === 'gif') {
addPart('AttachGif', undefined, message.message);
addPart('AttachGif');
} else if(document.type === 'round') {
addPart('AttachRound', undefined, message.message);
addPart('AttachRound');
} else if(document.type === 'sticker') {
if(document.stickerEmojiRaw) {
addPart(undefined, (plain ? document.stickerEmojiRaw : document.stickerEmoji) + ' ');
@ -2836,9 +2831,9 @@ export class AppMessagesManager { @@ -2836,9 +2831,9 @@ export class AppMessagesManager {
} else if(document.type === 'audio') {
const attribute = document.attributes.find(attribute => attribute._ === 'documentAttributeAudio' && (attribute.title || attribute.performer)) as DocumentAttribute.documentAttributeAudio;
const f = '🎵' + ' ' + (attribute ? [attribute.title, attribute.performer].filter(Boolean).join(' - ') : document.file_name);
addPart(undefined, plain ? f : RichTextProcessor.wrapEmojiText(f), message.message);
addPart(undefined, plain ? f : RichTextProcessor.wrapEmojiText(f));
} else {
addPart(undefined, plain ? document.file_name : RichTextProcessor.wrapEmojiText(document.file_name), message.message);
addPart(undefined, plain ? document.file_name : RichTextProcessor.wrapEmojiText(document.file_name));
}
break;
@ -2849,7 +2844,11 @@ export class AppMessagesManager { @@ -2849,7 +2844,11 @@ export class AppMessagesManager {
///////this.log.warn('Got unknown media type!', message);
break;
}
}
}
if(text && parts.length) {
parts.push(', ');
}
}
if((message as Message.messageService).action) {

22
src/lib/storages/filters.ts

@ -49,7 +49,7 @@ export default class FiltersStorage { @@ -49,7 +49,7 @@ export default class FiltersStorage {
private apiUpdatesManager: ApiUpdatesManager,
/* private apiManager: ApiManagerProxy, */
private rootScope: typeof _rootScope) {
this.clear();
this.clear(true);
this.filters = {};
this.appStateManager.getState().then((state) => {
@ -114,10 +114,13 @@ export default class FiltersStorage { @@ -114,10 +114,13 @@ export default class FiltersStorage {
public clear(init = false) {
if(!init) {
safeReplaceObject(this.filters, {});
this.reloadedPeerIds.clear();
} else {
this.filters = {};
this.reloadedPeerIds = new Set();
}
this.orderIndex = START_ORDER_INDEX;
this.reloadedPeerIds = new Set();
}
private onUpdateDialogFilter = (update: Update.updateDialogFilter) => {
@ -178,11 +181,8 @@ export default class FiltersStorage { @@ -178,11 +181,8 @@ export default class FiltersStorage {
}
// exclude_muted
if(pFlags.exclude_muted) {
const isMuted = this.appNotificationsManager.isPeerLocalMuted(peerId);
if(isMuted) {
return false;
}
if(pFlags.exclude_muted && this.appNotificationsManager.isPeerLocalMuted(peerId) && !(dialog.unread_mentions_count && dialog.unread_count)) {
return false;
}
if(this.appPeersManager.isAnyChat(peerId)) {
@ -320,12 +320,12 @@ export default class FiltersStorage { @@ -320,12 +320,12 @@ export default class FiltersStorage {
});
}
public reloadMissingPeerIds(filterId: number) {
public reloadMissingPeerIds(filterId: number, type: 'pinned_peers' | 'include_peers' | 'exclude_peers' = 'pinned_peers') {
const promises: Promise<any>[] = [];
const filter = this.getFilter(filterId);
const pinnedPeers = filter?.pinned_peers;
if(pinnedPeers?.length) {
const reloadDialogs = pinnedPeers.filter((inputPeer, idx) => {
const peers = filter && filter[type];
if(peers?.length) {
const reloadDialogs = peers.filter((inputPeer, idx) => {
const peerId = this.appPeersManager.getPeerId(inputPeer);
return !this.reloadedPeerIds.has(peerId) && !this.appMessagesManager.getDialogOnly(peerId);
});

Loading…
Cancel
Save