Skip to content

Commit

Permalink
Fix: Try actual dates for Checkpoints (#127)
Browse files Browse the repository at this point in the history
* Fix: Try actual dates for Checkpoints
  • Loading branch information
thesamim authored Apr 24, 2024
1 parent 3305cb2 commit fcd4425
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "tickticksync",
"name": "TickTickSync",
"version": "1.0.28",
"version": "1.0.29",
"minAppVersion": "1.0.0",
"description": "Sync TickTick tasks to Obsidian, and Obsidian tasks to TickTick",
"author": "thesamim",
Expand Down
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class TickTickSync extends Plugin {


if ((!markDownView) || !(editor) || (editor) && !(editor.hasFocus())) {
(console.log(`editor is not focused`))
// (console.log(`editor is not focused`))
return;
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "tickticksync",
"name": "TickTickSync",
"version": "1.0.28",
"version": "1.0.29",
"minAppVersion": "1.0.0",
"description": "Sync TickTick tasks to Obsidian, and Obsidian tasks to TickTick",
"author": "thesamim",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tickticksync",
"version": "1.0.28",
"version": "1.0.29",
"description": "Sync TickTick tasks to Obsidian, and Obsidian tasks to TickTick",
"main": "main.js",
"scripts": {
Expand Down
12 changes: 10 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export class Tick {
this.loginUrl = `${protocol}${ticktickServer}${apiVersion}`;
this.originUrl = `${protocol}${ticktickServer}`;
}
this.checkpoint = 0;
//TickTick was launched in 2013. Hoping this catches all the task for everyone.
let dtDate = new Date("2013-01-01T00:00:00.000+0000")
console.log("Starting Checkpoint date: ", dtDate, "Checkpoint", dtDate.getTime())
this.checkpoint = dtDate.getTime();
}


Expand Down Expand Up @@ -632,8 +635,13 @@ private createLoginRequestOptions(url: string, body: JSON) {
}
}
private getNextCheckPoint() {
let dtDate = new Date(this.checkpoint)
console.log("Date: ", dtDate)
dtDate.setDate(dtDate.getDate() - 15);
console.log("Date: ", dtDate)
console.log("Attempted Checkpoint: ", dtDate.getTime())
this.checkpoint = dtDate.getTime();
console.warn("Check point has been changed.", this.checkpoint);
this.checkpoint += 1;
return this.checkpoint
}
}
30 changes: 21 additions & 9 deletions src/syncModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -957,10 +957,13 @@ export class SyncMan {
}
let bModifiedFileSystem = false;
let allTaskDetails = await this.plugin.tickTickRestAPI?.getAllTasks();
console.log("All task details have been saved.", allTaskDetails);

// console.log("All task details have been saved.", allTaskDetails);
let tasksFromTickTic = allTaskDetails.update;
let deletedTasks = allTaskDetails.delete;
// this.dumpArray("tick Tick ", tasksFromTickTic)
// this.dumpArray("deleted ", deletedTasks)


//TODO: Filtering deleted tasks would take an act of congress. Just warn the user in Readme.
if (this.plugin.settings.SyncTag && this.plugin.settings.SyncProject) {
let hasTag;
Expand Down Expand Up @@ -990,12 +993,20 @@ export class SyncMan {
}
// this.dumpArray('== remote:', tasksFromTickTic);
let tasksInCache = await this.plugin.cacheOperation?.loadTasksFromCache()
// this.dumpArray("cache", tasksInCache)

if (this.plugin.settings.debugMode) {
console.log("We have: ", tasksFromTickTic.length, " tasks on " + this.plugin.tickTickRestAPI?.api?.apiUrl)
console.log("There are: ", tasksInCache.length, " tasks in Cache.");
}


if (this.plugin.settings.debugMode) {
const closedTasks = tasksFromTickTic.filter(task => task.status != 0);
const openTasks = tasksFromTickTic.filter(task => task.status === 0);
console.log('openTasks', openTasks.length, 'closedTasks', closedTasks.length);
}

tasksFromTickTic = tasksFromTickTic.sort((a, b) => (a.id > b.id) ? 1 : ((b.id > a.id) ? -1 : 0))
// console.log("num remote tasks: ", tasksFromTickTic.length)

Expand Down Expand Up @@ -1028,6 +1039,7 @@ export class SyncMan {
}



// Check for deleted tasks in TickTick
const deletedTickTickTasks = tasksInCache.filter(task => !tasksFromTickTic.some(t => t.id === task.id));
// this.dumpArray('deletedTickTickTasks Deleted tasks in TickTick:', deletedTickTickTasks);
Expand Down Expand Up @@ -1145,14 +1157,14 @@ export class SyncMan {
dumpArray(which: string, arrayIn: ITask[]) {
console.log(which)
arrayIn.forEach(item => {
if (item.id == '661933d3a8876ef48c564ba4') {
console.log(' ',
item.id, '--',
// item.title,
// item.parentId,
// item.childIds,
'modification time: ', item.modifiedTime);
}
item);
// console.log(' ',
// item.id, '--',
// // item.title,
// // item.parentId,
// // item.childIds,
// 'modification time: ', item.modifiedTime);
}
)

Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"1.0.25": "1.0.0",
"1.0.26": "1.0.0",
"1.0.27": "1.0.0",
"1.0.28": "1.0.0"
"1.0.28": "1.0.0",
"1.0.29": "1.0.0"
}

0 comments on commit fcd4425

Please sign in to comment.