mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-27 11:09:20 +03:00
Momentor.reload to CustomEvent
This commit is contained in:
parent
9f1ea1a0fd
commit
efc2dd89e1
4 changed files with 23 additions and 38 deletions
|
|
@ -23,7 +23,6 @@ import { $htmlCL, leftPanelDisabled, bMobileDevice } from 'Common/Globals';
|
|||
|
||||
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
||||
import { runHook } from 'Common/Plugins';
|
||||
import { reload as momentReload } from 'Common/Momentor';
|
||||
|
||||
import {
|
||||
initMessageFlagsFromCache,
|
||||
|
|
@ -1141,7 +1140,7 @@ class AppUser extends AbstractApp {
|
|||
this.bootstartLoginScreen();
|
||||
}
|
||||
|
||||
setInterval(momentReload, 60000);
|
||||
setInterval(() => dispatchEvent(new CustomEvent('reload-time')), 60000);
|
||||
|
||||
runHook('rl-start-screens');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,35 +1,26 @@
|
|||
import { i18n } from 'Common/Translator';
|
||||
|
||||
let d,
|
||||
_moment = null,
|
||||
momentNow = () => {
|
||||
if (!d) {
|
||||
d = setTimeout(()=>d=0, 500);
|
||||
_moment = new Date();
|
||||
}
|
||||
return _moment;
|
||||
};
|
||||
|
||||
export function format(timeStampInUTC, formatStr) {
|
||||
const now = Date.now() / 1000;
|
||||
const now = Date.now(),
|
||||
time = 0 < timeStampInUTC ? Math.min(now, timeStampInUTC * 1000) : (0 === timeStampInUTC ? now : 0);
|
||||
|
||||
timeStampInUTC = 0 < timeStampInUTC ? Math.min(now, timeStampInUTC) : (0 === timeStampInUTC ? now : 0);
|
||||
|
||||
if (31536000 < timeStampInUTC) {
|
||||
const m = new Date(timeStampInUTC * 1000);
|
||||
if (31536000000 < time) {
|
||||
const m = new Date(time);
|
||||
switch (formatStr) {
|
||||
case 'FROMNOW':
|
||||
return m.fromNow();
|
||||
case 'SHORT':
|
||||
if (4 >= (now - timeStampInUTC) / 3600)
|
||||
case 'SHORT': {
|
||||
if (4 >= (now - time) / 3600000)
|
||||
return m.fromNow();
|
||||
if (momentNow().format('Ymd') === m.format('Ymd'))
|
||||
const ymd = m.format('Ymd'), date = new Date;
|
||||
if (date.format('Ymd') === ymd)
|
||||
return i18n('MESSAGE_LIST/TODAY_AT', {TIME: m.format('LT')});
|
||||
if (new Date((now - 86400) * 1000).format('Ymd') === m.format('Ymd'))
|
||||
if (new Date(now - 86400000).format('Ymd') === ymd)
|
||||
return i18n('MESSAGE_LIST/YESTERDAY_AT', {TIME: m.format('LT')});
|
||||
if (momentNow().getFullYear() === m.getFullYear())
|
||||
if (date.getFullYear() === m.getFullYear())
|
||||
return m.format('d M.');
|
||||
return m.format('LL');
|
||||
}
|
||||
case 'FULL':
|
||||
return m.format('LLL');
|
||||
default:
|
||||
|
|
@ -63,11 +54,7 @@ export function timeToNode(element, time) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
export function reload() {
|
||||
setTimeout(() =>
|
||||
addEventListener('reload-time', () => setTimeout(() =>
|
||||
document.querySelectorAll('[data-bind*="moment:"]').forEach(element => timeToNode(element))
|
||||
, 1);
|
||||
}
|
||||
, 1)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import ko from 'ko';
|
|||
import { Notification, UploadErrorCode } from 'Common/Enums';
|
||||
import { pInt } from 'Common/Utils';
|
||||
import { $html, $htmlCL } from 'Common/Globals';
|
||||
import { reload as momentorReload } from 'Common/Momentor';
|
||||
import { langLink } from 'Common/Links';
|
||||
|
||||
let I18N_DATA = window.rainloopI18N || {};
|
||||
|
|
@ -148,7 +147,7 @@ const reloadData = () => {
|
|||
|
||||
i18nToNodes(document);
|
||||
|
||||
momentorReload();
|
||||
dispatchEvent(new CustomEvent('reload-time'));
|
||||
trigger(!trigger());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue