Shared media: fix handling deleted messages
This commit is contained in:
parent
28ea417d0a
commit
deafecf214
@ -570,108 +570,7 @@ export default class AppSearchSuper {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public filterMessagesByType(messages: any[], type: SearchSuperType): MyMessage[] {
|
public filterMessagesByType(messages: any[], type: SearchSuperType): MyMessage[] {
|
||||||
if(type === 'inputMessagesFilterEmpty') return messages;
|
return appMessagesManager.filterMessagesByInputFilter(type, messages, messages.length);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private processEmptyFilter({message, searchGroup}: ProcessSearchSuperResult) {
|
private processEmptyFilter({message, searchGroup}: ProcessSearchSuperResult) {
|
||||||
|
@ -364,7 +364,7 @@ export default class AppSharedMediaTab extends SliderSuperTab {
|
|||||||
|
|
||||||
if(this.peerId === peerId) {
|
if(this.peerId === peerId) {
|
||||||
const container = this.searchSuper.tabs[inputFilter];
|
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(div) {
|
||||||
if(this.searchSuper.selection.isSelecting) {
|
if(this.searchSuper.selection.isSelecting) {
|
||||||
this.searchSuper.selection.toggleByElement(div);
|
this.searchSuper.selection.toggleByElement(div);
|
||||||
@ -378,7 +378,8 @@ export default class AppSharedMediaTab extends SliderSuperTab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
// can have element in different tabs somehow
|
||||||
|
// break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ export default class SearchListLoader<Item extends {mid: number, peerId: PeerId}
|
|||||||
const storage = this.searchContext.isScheduled ?
|
const storage = this.searchContext.isScheduled ?
|
||||||
appMessagesManager.getScheduledMessagesStorage(this.searchContext.peerId) :
|
appMessagesManager.getScheduledMessagesStorage(this.searchContext.peerId) :
|
||||||
appMessagesManager.getMessagesStorage(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;
|
return filtered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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[] = [];
|
const foundMsgs: MyMessage[] = [];
|
||||||
if(!history.length) {
|
if(!history.length) {
|
||||||
return foundMsgs;
|
return foundMsgs;
|
||||||
@ -3762,7 +3770,8 @@ export class AppMessagesManager {
|
|||||||
|
|
||||||
case 'inputMessagesFilterDocument':
|
case 'inputMessagesFilterDocument':
|
||||||
neededContents['messageMediaDocument'] = true;
|
neededContents['messageMediaDocument'] = true;
|
||||||
excludeDocTypes.push('video');
|
// excludeDocTypes.push('video');
|
||||||
|
neededDocTypes.push(undefined, 'photo', 'pdf');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'inputMessagesFilterVoice':
|
case 'inputMessagesFilterVoice':
|
||||||
@ -3816,7 +3825,7 @@ export class AppMessagesManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(let i = 0, length = history.length; i < length; ++i) {
|
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;
|
if(!message) continue;
|
||||||
|
|
||||||
//|| (neededContents['mentioned'] && message.totalEntities.find((e: any) => e._ === 'messageEntityMention'));
|
//|| (neededContents['mentioned'] && message.totalEntities.find((e: any) => e._ === 'messageEntityMention'));
|
||||||
@ -3825,8 +3834,12 @@ export class AppMessagesManager {
|
|||||||
if(message._ === 'message') {
|
if(message._ === 'message') {
|
||||||
if(message.media && neededContents[message.media._]/* && !message.fwd_from */) {
|
if(message.media && neededContents[message.media._]/* && !message.fwd_from */) {
|
||||||
const doc = (message.media as MessageMedia.messageMediaDocument).document as MyDocument;
|
const doc = (message.media as MessageMedia.messageMediaDocument).document as MyDocument;
|
||||||
if(doc && ((neededDocTypes.length && !neededDocTypes.includes(doc.type))
|
if(doc &&
|
||||||
|| excludeDocTypes.includes(doc.type))) {
|
(
|
||||||
|
(neededDocTypes.length && !neededDocTypes.includes(doc.type)) ||
|
||||||
|
excludeDocTypes.includes(doc.type)
|
||||||
|
)
|
||||||
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3920,7 +3933,7 @@ export class AppMessagesManager {
|
|||||||
storage = beta ?
|
storage = beta ?
|
||||||
this.getSearchStorage(peerId, inputFilter._) as any :
|
this.getSearchStorage(peerId, inputFilter._) as any :
|
||||||
this.getHistoryStorage(peerId);
|
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) {
|
if(foundMsgs.length) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user