Browse Source

Media viewer changes:

New date formatting
Providing now correct date of message
master
Eduard Kuzmenko 4 years ago
parent
commit
87c747a31a
  1. 33
      src/components/appMediaViewer.ts
  2. 2
      src/helpers/date.ts
  3. 3
      src/lib/appManagers/appImManager.ts

33
src/components/appMediaViewer.ts

@ -23,8 +23,9 @@ import { renderImageFromUrl } from "./misc"; @@ -23,8 +23,9 @@ import { renderImageFromUrl } from "./misc";
import PopupForward from "./popupForward";
import ProgressivePreloader from "./preloader";
import Scrollable from "./scrollable";
import appSidebarRight, { AppSidebarRight } from "./sidebarRight";
import appSidebarRight from "./sidebarRight";
import SwipeHandler from "./swipeHandler";
import { months, ONE_DAY } from "../helpers/date";
// TODO: масштабирование картинок (не SVG) при ресайзе, и правильный возврат на исходную позицию
// TODO: картинки "обрезаются" если возвращаются или появляются с места, где есть их перекрытие (топбар, поле ввода)
@ -772,11 +773,23 @@ class AppMediaViewerBase<ContentAdditionType extends string, ButtonsAdditionType @@ -772,11 +773,23 @@ class AppMediaViewerBase<ContentAdditionType extends string, ButtonsAdditionType
}
protected setAuthorInfo(fromID: number, timestamp: number) {
const date = new Date(timestamp * 1000);
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const dateStr = months[date.getMonth()] + ' ' + date.getDate() + ' at '+ date.getHours() + ':' + ('0' + date.getMinutes()).slice(-2);
this.author.date.innerText = dateStr;
const date = new Date();
const time = new Date(timestamp * 1000);
const now = date.getTime() / 1000;
const timeStr = time.getHours() + ':' + ('0' + time.getMinutes()).slice(-2);
let dateStr: string;
if((now - timestamp) < ONE_DAY && date.getDate() == time.getDate()) { // if the same day
dateStr = 'Today';
} else if((now - timestamp) < (ONE_DAY * 2) && (date.getDate() - 1) == time.getDate()) { // yesterday
dateStr = 'Yesterday';
} else if(date.getFullYear() != time.getFullYear()) { // different year
dateStr = months[time.getMonth()].slice(0, 3) + ' ' + time.getDate() + ', ' + time.getFullYear();
} else {
dateStr = months[time.getMonth()].slice(0, 3) + ' ' + time.getDate();
}
this.author.date.innerText = dateStr + ' at ' + timeStr;
const name = appPeersManager.getPeerTitle(fromID);
this.author.nameEl.innerHTML = name;
@ -787,13 +800,13 @@ class AppMediaViewerBase<ContentAdditionType extends string, ButtonsAdditionType @@ -787,13 +800,13 @@ class AppMediaViewerBase<ContentAdditionType extends string, ButtonsAdditionType
oldAvatar.parentElement.replaceChild(this.author.avatarEl, oldAvatar);
}
protected async _openMedia(media: any, fromID: number, fromRight: number, target?: HTMLElement, reverse = false,
protected async _openMedia(media: any, timestamp: number, fromID: number, fromRight: number, target?: HTMLElement, reverse = false,
prevTargets: TargetType[] = [], nextTargets: TargetType[] = [], needLoadMore = true) {
if(this.setMoverPromise) return this.setMoverPromise;
this.log('openMedia:', media, fromID);
this.setAuthorInfo(fromID, media.date);
this.setAuthorInfo(fromID, timestamp);
const isVideo = (media as MyDocument).type == 'video' || (media as MyDocument).type == 'gif';
@ -1315,7 +1328,7 @@ export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delet @@ -1315,7 +1328,7 @@ export default class AppMediaViewer extends AppMediaViewerBase<'caption', 'delet
}
this.currentMessageID = mid;
const promise = super._openMedia(media, fromID, fromRight, target, reverse, prevTargets, nextTargets, needLoadMore);
const promise = super._openMedia(media, message.date, fromID, fromRight, target, reverse, prevTargets, nextTargets, needLoadMore);
this.setCaption(message);
return promise;
@ -1404,6 +1417,6 @@ export class AppMediaViewerAvatar extends AppMediaViewerBase<'', 'delete', AppMe @@ -1404,6 +1417,6 @@ export class AppMediaViewerAvatar extends AppMediaViewerBase<'', 'delete', AppMe
this.currentPhotoID = photo.id;
return super._openMedia(photo, this.peerID, fromRight, target, false);
return super._openMedia(photo, photo.date, this.peerID, fromRight, target, false);
}
}

2
src/helpers/date.ts

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
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'];
const ONE_DAY = 86400;
export const ONE_DAY = 86400;
// https://stackoverflow.com/a/6117889
export const getWeekNumber = (date: Date) => {

3
src/lib/appManagers/appImManager.ts

@ -53,6 +53,7 @@ import appPollsManager from './appPollsManager'; @@ -53,6 +53,7 @@ import appPollsManager from './appPollsManager';
import appProfileManager from "./appProfileManager";
import appStickersManager from './appStickersManager';
import appUsersManager from "./appUsersManager";
import { months } from '../../helpers/date';
//console.log('appImManager included33!');
@ -1542,8 +1543,6 @@ export class AppImManager { @@ -1542,8 +1543,6 @@ export class AppImManager {
if(today.getTime() == date.getTime()) {
str = 'Today';
} else {
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
str = months[date.getMonth()] + ' ' + date.getDate();
if(date.getFullYear() != today.getFullYear()) {

Loading…
Cancel
Save