Fix repeat search

Fix dates in chat list
This commit is contained in:
morethanwords 2020-10-08 01:39:38 +03:00
parent 8a0f1ac794
commit f0ecb48a7c
2 changed files with 7 additions and 6 deletions

View File

@ -280,10 +280,11 @@ export default class AppSearch {
this.minMsgID = history[history.length - 1]; this.minMsgID = history[history.length - 1];
this.offsetRate = next_rate; this.offsetRate = next_rate;
this.loadedCount += history.length;
if(this.loadedCount == -1) { if(this.loadedCount == -1) {
this.loadedCount = 0; this.loadedCount = 0;
} }
this.loadedCount += history.length;
if(this.foundCount == -1) { if(this.foundCount == -1) {
this.foundCount = count; this.foundCount = count;

View File

@ -1,7 +1,7 @@
export const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; export const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
export const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; export const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const ONE_DAY = 86400e3; const ONE_DAY = 86400;
// https://stackoverflow.com/a/6117889 // https://stackoverflow.com/a/6117889
export const getWeekNumber = (date: Date) => { export const getWeekNumber = (date: Date) => {
@ -14,16 +14,16 @@ export const getWeekNumber = (date: Date) => {
export const formatDateAccordingToToday = (time: Date) => { export const formatDateAccordingToToday = (time: Date) => {
const date = new Date(); const date = new Date();
const now = date.getTime() / 1000; const now = date.getTime() / 1000 | 0;
const timestamp = date.getTime() / 1000; const timestamp = time.getTime() / 1000 | 0;
let timeStr: string; let timeStr: string;
if((now - timestamp) < ONE_DAY && date.getDate() == time.getDate()) { // if the same day if((now - timestamp) < ONE_DAY && date.getDate() == time.getDate()) { // if the same day
timeStr = ('0' + time.getHours()).slice(-2) + ':' + ('0' + time.getMinutes()).slice(-2); timeStr = ('0' + time.getHours()).slice(-2) + ':' + ('0' + time.getMinutes()).slice(-2);
} else if((now - timestamp) < (ONE_DAY * 7) && getWeekNumber(date) == getWeekNumber(time)) { // current week
timeStr = days[time.getDay()].slice(0, 3);
} else if(date.getFullYear() != time.getFullYear()) { // different year } else if(date.getFullYear() != time.getFullYear()) { // different year
timeStr = time.getDate() + '.' + (time.getMonth() + 1) + '.' + time.getFullYear(); timeStr = time.getDate() + '.' + (time.getMonth() + 1) + '.' + time.getFullYear();
} else if((now - timestamp) < (ONE_DAY * 7) && getWeekNumber(date) == getWeekNumber(time)) { // current week
timeStr = days[time.getDay()].slice(0, 3);
} else { // same year } else { // same year
timeStr = months[time.getMonth()].slice(0, 3) + ' ' + ('0' + time.getDate()).slice(-2); timeStr = months[time.getMonth()].slice(0, 3) + ' ' + ('0' + time.getDate()).slice(-2);
} }