From b2f2fa270ececc877f1734fff544b3e53ea901a2 Mon Sep 17 00:00:00 2001 From: Hoffelhas Date: Sun, 8 Jan 2023 17:11:47 +0100 Subject: [PATCH] Bugfix where manually changing the order of sequential tasks would not remove old labels. --- autodoist.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/autodoist.py b/autodoist.py index be1dd1b..4b5ef13 100644 --- a/autodoist.py +++ b/autodoist.py @@ -1017,7 +1017,13 @@ def autodoist_magic(args, api, connection): hierarchy_types = [task_type, section_type, project_type] hierarchy_boolean = [type(x) != type(None) - for x in hierarchy_types] + for x in hierarchy_types] + + # If task has no type, but has a label, most likely the order has been changed by user. Remove data. + if not True in hierarchy_boolean and next_action_label in task.labels: + remove_label(task, next_action_label, overview_task_ids, overview_task_labels) + db_update_value(connection, task, 'task_type', None) + db_update_value(connection, task, 'parent_type', None) # If it is a parentless task, set task type based on hierarchy if task.parent_id == 0: @@ -1043,6 +1049,10 @@ def autodoist_magic(args, api, connection): if not first_found[1]: add_label(connection, task, dominant_type, next_action_label, overview_task_ids, overview_task_labels) + elif next_action_label in task.labels: + # Probably the task has been manually moved, so if it has a label, let's remove it. + remove_label(task, next_action_label, overview_task_ids, overview_task_labels) + elif dominant_type[1] == 'p': add_label(connection, task, dominant_type, next_action_label, overview_task_ids, overview_task_labels) @@ -1051,6 +1061,10 @@ def autodoist_magic(args, api, connection): if dominant_type[1] == 's': if not first_found[1]: add_label(connection, task, dominant_type, next_action_label, overview_task_ids, overview_task_labels) + + elif next_action_label in task.labels: + # Probably the task has been manually moved, so if it has a label, let's remove it. + remove_label(task, next_action_label, overview_task_ids, overview_task_labels) elif dominant_type[1] == 'p': add_label(connection, task, dominant_type, next_action_label, overview_task_ids, overview_task_labels) @@ -1060,6 +1074,10 @@ def autodoist_magic(args, api, connection): if not first_found[1]: add_label(connection, task, dominant_type, next_action_label, overview_task_ids, overview_task_labels) + elif next_action_label in task.labels: + # Probably the task has been manually moved, so if it has a label, let's remove it. + remove_label(task, next_action_label, overview_task_ids, overview_task_labels) + elif dominant_type[0] == 'x' and dominant_type[1] == 'p': add_label(connection, task, dominant_type, next_action_label, overview_task_ids, overview_task_labels) @@ -1068,6 +1086,10 @@ def autodoist_magic(args, api, connection): if not first_found[1]: add_label(connection, task, dominant_type, next_action_label, overview_task_ids, overview_task_labels) + if next_action_label in task.labels: + # Probably the task has been manually moved, so if it has a label, let's remove it. + remove_label(task, next_action_label, overview_task_ids, overview_task_labels) + elif dominant_type[1] == 'x' and dominant_type[2] == 'p': add_label(connection, task, dominant_type, next_action_label, overview_task_ids, overview_task_labels) @@ -1099,6 +1121,9 @@ def autodoist_magic(args, api, connection): if child_task.content.startswith('*'): continue + # Clean up for good measure. + remove_label(child_task, next_action_label, overview_task_ids, overview_task_labels) + # Pass task_type down to the children db_update_value( connection, child_task, 'parent_type', dominant_type)