Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
Fix Typo in Readme
Handle the case of a file being deleted from another file manager.
  • Loading branch information
thesamim committed Nov 11, 2023
1 parent e8b7136 commit 3c04972
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The TickTickSync plugin automatically creates tasks in ticktick and synchronizes task state between Obsidian and ticktick.

The plugin works best when the [Tasks](https://github.com/obsidian-tasks-group/obsidian-tasks) is installed.
The plugin works best when the [Tasks](https://github.com/obsidian-tasks-group/obsidian-tasks) plugin is installed.

## Features
- Any task created in Obsidian and taged with #ticktick will be synchronized with TickTick
Expand Down
61 changes: 32 additions & 29 deletions src/syncModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class SyncMan {



async deletedTaskCheck(file_path: string|null): Promise<void> {
async deletedTaskCheck(file_path: string | null): Promise<void> {

let file
let currentFileValue
Expand Down Expand Up @@ -66,31 +66,36 @@ export class SyncMan {


//console.log(currentFileValue)
const currentFileValueWithOutFileMetadata = currentFileValue.replace(/^---[\s\S]*?---\n/, '');
const fileMetadata_TickTickTasks = fileMetadata.TickTickTasks;
const fileMetadata_TickTickCount = fileMetadata.TickTickCount;

const deleteTasksPromises = fileMetadata_TickTickTasks
.filter((taskId) => !currentFileValueWithOutFileMetadata.includes(taskId))
.map(async (taskId) => {
try {
var taskIds = [];
taskIds.push(taskId)
console.log(taskIds)
await this.deleteTasksByIds(taskIds);
} catch (error) {
console.error(`Failed to delete task ${taskId}: ${error}`);
}
});
if (currentFileValue) {
const currentFileValueWithOutFileMetadata = currentFileValue.replace(/^---[\s\S]*?---\n/, '');
const fileMetadata_TickTickTasks = fileMetadata.TickTickTasks;
const fileMetadata_TickTickCount = fileMetadata.TickTickCount;

const deleteTasksPromises = fileMetadata_TickTickTasks
.filter((taskId) => !currentFileValueWithOutFileMetadata.includes(taskId))
.map(async (taskId) => {
try {
var taskIds = [];
taskIds.push(taskId)
console.log(taskIds)
await this.deleteTasksByIds(taskIds);
} catch (error) {
console.error(`Failed to delete task ${taskId}: ${error}`);
}
});

const deletedTaskIds = await Promise.all(deleteTasksPromises);
const numDeletedTasks = deletedTaskIds.length
if (numDeletedTasks === 0) {
return;
const deletedTaskIds = await Promise.all(deleteTasksPromises);
const numDeletedTasks = deletedTaskIds.length
if (numDeletedTasks === 0) {
return;
}
//Let cacheOperation deal with metatadata management.
await this.plugin.cacheOperation?.deleteTaskFromCacheByIDs(deletedTaskIds)
//console.log(`Deleted ${deletedTaskAmount} tasks`)
} else {
//We had a file. The file is gone. Bad things will happen. Delete the metadata
this.plugin.cacheOperation?.deleteFilepathFromMetadata(filepath);
}
//Let cacheOperation deal with metatadata management.
await this.plugin.cacheOperation?.deleteTaskFromCacheByIDs(deletedTaskIds)
//console.log(`Deleted ${deletedTaskAmount} tasks`)

}

Expand Down Expand Up @@ -128,12 +133,12 @@ export class SyncMan {
await this.plugin.cacheOperation?.closeTaskToCacheByID(ticktick_id)

}
this.plugin.saveSettings()
this.plugin.saveSettings()

//ticktick id is saved to the end of the task
//TODO: Breaking SOC for now
const text_with_out_link = `${linetxt} %%[ticktick_id:: ${ticktick_id}]%%`;

const text = this.plugin.taskParser?.addTickTickLink(text_with_out_link, newTask.id)
const from = { line: cursor.line, ch: 0 };
const to = { line: cursor.line, ch: linetxt.length };
Expand Down Expand Up @@ -205,12 +210,10 @@ export class SyncMan {
for (let i = 0; i < lines.length; i++) {
const line = lines[i]
if (!this.plugin.taskParser?.hasTickTickId(line) && this.plugin.taskParser?.hasTickTickTag(line)) {
console.log('!!!!!Adding on fullTextNewTaskCheck')
//console.log(`current line is ${i}`)
//console.log(`line text: ${line}`)
// console.log(filepath)
const currentTask = await this.plugin.taskParser?.convertTextToTickTickTaskObject(line, filepath, i, content)
console.log("Adding because fullTextNewTaskCheck. ", currentTask.priority)
if (typeof currentTask === "undefined") {
continue
}
Expand Down Expand Up @@ -665,7 +668,7 @@ export class SyncMan {
new Notice("Failed to fetch resources from TickTick, please try again later", 5000)
throw new Error("Failed to fetch resources from TickTick");
}

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

0 comments on commit 3c04972

Please sign in to comment.