You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
Desktop: Fixes #3729: Fix lock issue when device does not have the right time
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
import { Dirnames } from './utils/types';
|
||||
import ntpDate from 'lib/ntpDate';
|
||||
|
||||
const JoplinError = require('lib/JoplinError');
|
||||
const { time } = require('lib/time-utils');
|
||||
const { fileExtension, filename } = require('lib/path-utils.js');
|
||||
@ -98,8 +100,8 @@ export default class LockHandler {
|
||||
return output;
|
||||
}
|
||||
|
||||
private lockIsActive(lock:Lock):boolean {
|
||||
return Date.now() - lock.updatedTime < this.lockTtl;
|
||||
private lockIsActive(lock:Lock, currentDate:Date):boolean {
|
||||
return currentDate.getTime() - lock.updatedTime < this.lockTtl;
|
||||
}
|
||||
|
||||
async hasActiveLock(lockType:LockType, clientType:string = null, clientId:string = null) {
|
||||
@ -112,11 +114,12 @@ export default class LockHandler {
|
||||
// of that type instead.
|
||||
async activeLock(lockType:LockType, clientType:string = null, clientId:string = null) {
|
||||
const locks = await this.locks(lockType);
|
||||
const currentDate = await ntpDate();
|
||||
|
||||
if (lockType === LockType.Exclusive) {
|
||||
const activeLocks = locks
|
||||
.slice()
|
||||
.filter((lock:Lock) => this.lockIsActive(lock))
|
||||
.filter((lock:Lock) => this.lockIsActive(lock, currentDate))
|
||||
.sort((a:Lock, b:Lock) => {
|
||||
if (a.updatedTime === b.updatedTime) {
|
||||
return a.clientId < b.clientId ? -1 : +1;
|
||||
@ -134,7 +137,7 @@ export default class LockHandler {
|
||||
for (const lock of locks) {
|
||||
if (clientType && lock.clientType !== clientType) continue;
|
||||
if (clientId && lock.clientId !== clientId) continue;
|
||||
if (this.lockIsActive(lock)) return lock;
|
||||
if (this.lockIsActive(lock, currentDate)) return lock;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user