Add timestamp utilities with helpful names
This commit is contained in:
parent
9fa3359477
commit
a75402d290
8 changed files with 71 additions and 17 deletions
|
@ -17,8 +17,10 @@ import ProvisioningCipher from './ProvisioningCipher';
|
|||
import WebSocketResource, {
|
||||
IncomingWebSocketRequest,
|
||||
} from './WebsocketResources';
|
||||
import { isMoreRecentThan, isOlderThan } from '../util/timestamp';
|
||||
|
||||
const ARCHIVE_AGE = 30 * 24 * 60 * 60 * 1000;
|
||||
const PREKEY_ROTATION_AGE = 24 * 60 * 60 * 1000;
|
||||
|
||||
function getIdentifier(id: string) {
|
||||
if (!id || !id.length) {
|
||||
|
@ -321,10 +323,9 @@ export default class AccountManager extends EventTarget {
|
|||
existingKeys.sort((a, b) => (b.created_at || 0) - (a.created_at || 0));
|
||||
const confirmedKeys = existingKeys.filter(key => key.confirmed);
|
||||
|
||||
const ONE_DAY_AGO = Date.now() - 24 * 60 * 60 * 1000;
|
||||
if (
|
||||
confirmedKeys.length >= 3 &&
|
||||
confirmedKeys[0].created_at > ONE_DAY_AGO
|
||||
isMoreRecentThan(confirmedKeys[0].created_at, PREKEY_ROTATION_AGE)
|
||||
) {
|
||||
window.log.warn(
|
||||
'rotateSignedPreKey: 3+ confirmed keys, most recent is less than a day old. Cancelling rotation.'
|
||||
|
@ -437,9 +438,8 @@ export default class AccountManager extends EventTarget {
|
|||
return;
|
||||
}
|
||||
const createdAt = key.created_at || 0;
|
||||
const age = Date.now() - createdAt;
|
||||
|
||||
if (age > ARCHIVE_AGE) {
|
||||
if (isOlderThan(createdAt, ARCHIVE_AGE)) {
|
||||
window.log.info(
|
||||
'Removing confirmed signed prekey:',
|
||||
key.keyId,
|
||||
|
@ -463,8 +463,7 @@ export default class AccountManager extends EventTarget {
|
|||
}
|
||||
|
||||
const createdAt = key.created_at || 0;
|
||||
const age = Date.now() - createdAt;
|
||||
if (age > ARCHIVE_AGE) {
|
||||
if (isOlderThan(createdAt, ARCHIVE_AGE)) {
|
||||
window.log.info(
|
||||
'Removing unconfirmed signed prekey:',
|
||||
key.keyId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue