Browse Source

Shared media: fix handling deleted messages

master
Eduard Kuzmenko 3 years ago
parent
commit
deafecf214
  1. 103
      src/components/appSearchSuper..ts
  2. 5
      src/components/sidebarRight/tabs/sharedMedia.ts
  3. 2
      src/helpers/searchListLoader.ts
  4. 25
      src/lib/appManagers/appMessagesManager.ts

103
src/components/appSearchSuper..ts

@ -570,108 +570,7 @@ export default class AppSearchSuper { @@ -570,108 +570,7 @@ export default class AppSearchSuper {
};
public filterMessagesByType(messages: any[], type: SearchSuperType): MyMessage[] {
if(type === 'inputMessagesFilterEmpty') return messages;
if(type !== 'inputMessagesFilterUrl') {
messages = messages.filter(message => !!message.media);
}
/* if(!this.peerId) {
messages = messages.filter(message => {
if(message.peerId === rootScope.myId) {
return true;
}
const dialog = appMessagesManager.getDialogByPeerId(message.fromId)[0];
return dialog && dialog.folder_id === 0;
});
} */
let filtered: any[] = [];
switch(type) {
case 'inputMessagesFilterPhotoVideo': {
for(let message of messages) {
let media = message.media.photo || message.media.document || (message.media.webpage && message.media.webpage.document);
if(!media) {
//this.log('no media!', message);
continue;
}
if(media._ === 'document' && media.type !== 'video'/* && media.type !== 'gif' */) {
//this.log('broken video', media);
continue;
}
filtered.push(message);
}
break;
}
case 'inputMessagesFilterDocument': {
for(let message of messages) {
if(!message.media.document || ['voice', 'audio', 'gif', 'sticker', 'round'].includes(message.media.document.type)) {
continue;
}
filtered.push(message);
}
break;
}
case 'inputMessagesFilterUrl': {
//this.log('inputMessagesFilterUrl', messages);
for(let message of messages) {
//if((message.media.webpage && message.media.webpage._ !== 'webPageEmpty')) {
filtered.push(message);
//}
}
break;
}
case 'inputMessagesFilterMusic': {
for(let message of messages) {
if(!message.media.document || message.media.document.type !== 'audio') {
continue;
}
filtered.push(message);
}
break;
}
case 'inputMessagesFilterVoice': {
for(let message of messages) {
if(!message.media.document || message.media.document.type !== 'voice') {
continue;
}
filtered.push(message);
}
break;
}
case 'inputMessagesFilterRoundVoice': {
for(let message of messages) {
if(!message.media.document || !(['voice', 'round'] as MyDocument['type'][]).includes(message.media.document.type)) {
continue;
}
filtered.push(message);
}
break;
}
default:
break;
}
return filtered;
return appMessagesManager.filterMessagesByInputFilter(type, messages, messages.length);
}
private processEmptyFilter({message, searchGroup}: ProcessSearchSuperResult) {

5
src/components/sidebarRight/tabs/sharedMedia.ts

@ -364,7 +364,7 @@ export default class AppSharedMediaTab extends SliderSuperTab { @@ -364,7 +364,7 @@ export default class AppSharedMediaTab extends SliderSuperTab {
if(this.peerId === peerId) {
const container = this.searchSuper.tabs[inputFilter];
const div = container.querySelector(`div[data-mid="${mid}"][data-peer-id="${peerId}"]`) as HTMLElement;
const div = container.querySelector(`[data-mid="${mid}"][data-peer-id="${peerId}"]`) as HTMLElement;
if(div) {
if(this.searchSuper.selection.isSelecting) {
this.searchSuper.selection.toggleByElement(div);
@ -378,7 +378,8 @@ export default class AppSharedMediaTab extends SliderSuperTab { @@ -378,7 +378,8 @@ export default class AppSharedMediaTab extends SliderSuperTab {
}
}
break;
// can have element in different tabs somehow
// break;
}
}
}

2
src/helpers/searchListLoader.ts

@ -82,7 +82,7 @@ export default class SearchListLoader<Item extends {mid: number, peerId: PeerId} @@ -82,7 +82,7 @@ export default class SearchListLoader<Item extends {mid: number, peerId: PeerId}
const storage = this.searchContext.isScheduled ?
appMessagesManager.getScheduledMessagesStorage(this.searchContext.peerId) :
appMessagesManager.getMessagesStorage(this.searchContext.peerId);
const filtered = appMessagesManager.filterMessagesByInputFilter(this.searchContext.inputFilter._, mids, storage, mids.length) as Message.message[];
const filtered = appMessagesManager.filterMessagesByInputFilterFromStorage(this.searchContext.inputFilter._, mids, storage, mids.length) as Message.message[];
return filtered;
}

25
src/lib/appManagers/appMessagesManager.ts

@ -3727,7 +3727,15 @@ export class AppMessagesManager { @@ -3727,7 +3727,15 @@ export class AppMessagesManager {
});
}
public filterMessagesByInputFilter(inputFilter: MyInputMessagesFilter, history: number[], storage: MessagesStorage, limit: number) {
public filterMessagesByInputFilterFromStorage(inputFilter: MyInputMessagesFilter, history: number[], storage: MessagesStorage, limit: number) {
return this.filterMessagesByInputFilter(inputFilter, history.map(mid => storage.get(mid)), limit);
}
public filterMessagesByInputFilter(inputFilter: MyInputMessagesFilter, history: Array<Message.message | Message.messageService>, limit: number) {
if(inputFilter === 'inputMessagesFilterEmpty') {
return history;
}
const foundMsgs: MyMessage[] = [];
if(!history.length) {
return foundMsgs;
@ -3762,7 +3770,8 @@ export class AppMessagesManager { @@ -3762,7 +3770,8 @@ export class AppMessagesManager {
case 'inputMessagesFilterDocument':
neededContents['messageMediaDocument'] = true;
excludeDocTypes.push('video');
// excludeDocTypes.push('video');
neededDocTypes.push(undefined, 'photo', 'pdf');
break;
case 'inputMessagesFilterVoice':
@ -3816,7 +3825,7 @@ export class AppMessagesManager { @@ -3816,7 +3825,7 @@ export class AppMessagesManager {
}
for(let i = 0, length = history.length; i < length; ++i) {
const message: Message.message | Message.messageService = storage.get(history[i]);
const message: Message.message | Message.messageService = history[i];
if(!message) continue;
//|| (neededContents['mentioned'] && message.totalEntities.find((e: any) => e._ === 'messageEntityMention'));
@ -3825,8 +3834,12 @@ export class AppMessagesManager { @@ -3825,8 +3834,12 @@ export class AppMessagesManager {
if(message._ === 'message') {
if(message.media && neededContents[message.media._]/* && !message.fwd_from */) {
const doc = (message.media as MessageMedia.messageMediaDocument).document as MyDocument;
if(doc && ((neededDocTypes.length && !neededDocTypes.includes(doc.type))
|| excludeDocTypes.includes(doc.type))) {
if(doc &&
(
(neededDocTypes.length && !neededDocTypes.includes(doc.type)) ||
excludeDocTypes.includes(doc.type)
)
) {
continue;
}
@ -3920,7 +3933,7 @@ export class AppMessagesManager { @@ -3920,7 +3933,7 @@ export class AppMessagesManager {
storage = beta ?
this.getSearchStorage(peerId, inputFilter._) as any :
this.getHistoryStorage(peerId);
foundMsgs = this.filterMessagesByInputFilter(inputFilter._, storage.history.slice, this.getMessagesStorage(peerId), limit);
foundMsgs = this.filterMessagesByInputFilterFromStorage(inputFilter._, storage.history.slice, this.getMessagesStorage(peerId), limit);
}
if(foundMsgs.length) {

Loading…
Cancel
Save