Added keys for date search

Search for messages with peer || date
This commit is contained in:
Eduard Kuzmenko 2020-12-25 20:20:43 +02:00
parent f7394d0971
commit 0aa3ed648e
3 changed files with 99 additions and 5 deletions

View File

@ -1255,7 +1255,9 @@ export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delet
backLimit,
threadId: this.searchContext.threadId,
folderId: this.searchContext.folderId,
nextRate: this.searchContext.nextRate
nextRate: this.searchContext.nextRate,
minDate: this.searchContext.minDate,
maxDate: this.searchContext.maxDate
}).then(value => {
this.log('loaded more media by maxId:', maxId, value, older, this.reverse);

View File

@ -741,7 +741,7 @@ export default class AppSearchSuper {
}
})
]);
} else {
} else if(!this.searchContext.peerId && !this.searchContext.minDate) {
const renderRecentSearch = (setActive = true) => {
return appStateManager.getState().then(state => {
if(!middleware()) {
@ -794,7 +794,7 @@ export default class AppSearchSuper {
renderRecentSearch()
]);
}
} else return Promise.resolve();
}
public load(single = false, justLoad = false) {
@ -828,7 +828,7 @@ export default class AppSearchSuper {
this.loadedChats = true;
}
if(!this.searchContext.query.trim()) {
if(!this.searchContext.query.trim() && !this.searchContext.peerId && !this.searchContext.minDate) {
this.loaded[type] = true;
return Promise.resolve();
}

View File

@ -67,12 +67,83 @@ export type DateData = {
maxDate: number,
};
export function fillTipDates(query: string, dates: DateData[]) {
const q = query.trim();
const q = query.trim().toLowerCase();
if(q.length < 3) {
return;
}
if("today".indexOf(q) === 0) {
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth();
const day = date.getDate();
date.setFullYear(year, month, day);
date.setHours(0, 0, 0);
const minDate = date.getTime();
date.setFullYear(year, month, day + 1);
date.setHours(0, 0, 0);
const maxDate = date.getTime() - 1;
dates.push({
title: 'Today',
minDate,
maxDate
});
return;
}
if("yesterday".indexOf(q) === 0) {
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth();
const day = date.getDate();
date.setFullYear(year, month, day);
date.setHours(0, 0, 0);
const minDate = date.getTime() - 86400000;
date.setFullYear(year, month, day + 1);
date.setHours(0, 0, 0);
const maxDate = date.getTime() - 86400001;
dates.push({
title: 'Yesterday',
minDate,
maxDate
});
return;
}
const dayOfWeek = getDayOfWeek(q);
if(dayOfWeek >= 0) {
const date = new Date();
const now = date.getTime();
const currentDay = date.getDay();
const distance = dayOfWeek - currentDay;
date.setDate(date.getDate() + distance);
if(date.getTime() > now) {
date.setTime(date.getTime() - 604800000);
}
const year = date.getFullYear()
const month = date.getMonth();
const day = date.getDate();
date.setFullYear(year, month, day);
date.setHours(0, 0, 0);
const minDate = date.getTime();
date.setFullYear(year, month, day + 1);
date.setHours(0, 0, 0);
const maxDate = date.getTime() - 1;
dates.push({
title: formatWeekLong(minDate),
minDate,
maxDate
});
return;
}
let matches: any[];
if((matches = shortDate.exec(q)) !== null) {
const g1 = matches[1];
@ -289,6 +360,11 @@ function formatterYearMax(timestamp: number) {
return ('0' + date.getDate()).slice(-2) + '.' + ('0' + (date.getMonth() + 1)).slice(-2) + '.' + date.getFullYear();
}
function formatWeekLong(timestamp: number) {
const date = new Date(timestamp);
return days[date.getDay()];
}
function validDateForMonth(day: number, month: number) {
if(month >= 0 && month < 12) {
if(day >= 0 && day < numberOfDaysEachMonth[month]) {
@ -336,4 +412,20 @@ function getMonth(q: string) {
return -1;
}
function getDayOfWeek(q: string) {
const c = new Date();
if(q.length <= 3) {
return -1;
}
for(let i = 0; i < 7; i++) {
c.setDate(c.getDate() + 1);
if(formatWeekLong(c.getTime()).toLowerCase().indexOf(q) === 0) {
return c.getDay();
}
}
return -1;
}
MOUNT_CLASS_TO && (MOUNT_CLASS_TO.fillTipDates = fillTipDates);