Browse Source

[tasks] We only care about in-progress for scrobbling

Colin Powell 8 months ago
parent
commit
de6e9ce2d6
2 changed files with 9 additions and 7 deletions
  1. 8 3
      vrobbler/apps/scrobbles/scrobblers.py
  2. 1 4
      vrobbler/apps/tasks/webhooks.py

+ 8 - 3
vrobbler/apps/scrobbles/scrobblers.py

@@ -353,6 +353,14 @@ def todoist_scrobble_task(todoist_task: dict, user_id: int) -> Scrobble:
     title = " ".join([prefix.capitalize(), suffix.capitalize()])
 
     task = Task.find_or_create(title)
+
+    # is_complete = "completed" in todoist_task["todoist_event"]
+    is_no_longer_in_progress = (
+        "inprogress" not in todoist_task["todoist_label_list"]
+    )
+    if is_no_longer_in_progress:
+        scrobble = todoist_scrobble_task_finish(todoist_task, user_id)
+
     in_progress_scrobble = Scrobble.objects.filter(
         in_progress=True,
         log__todoist_id=todoist_task.get("todoist_id"),
@@ -361,9 +369,6 @@ def todoist_scrobble_task(todoist_task: dict, user_id: int) -> Scrobble:
     if in_progress_scrobble:
         return in_progress_scrobble
 
-    if "inprogress" not in todoist_task["todoist_label_list"]:
-        return todoist_scrobble_task_finish(todoist_task, user_id)
-
     # TODO Should use updated_at from TOdoist, but parsing isn't working
     scrobble_dict = {
         "user_id": user_id,

+ 1 - 4
vrobbler/apps/tasks/webhooks.py

@@ -60,10 +60,7 @@ def todoist_webhook(request):
     if not user_id:
         user_id = 1
 
-    if "completed" in todoist_task["todoist_event"]:
-        scrobble = todoist_scrobble_task_finish(todoist_task, user_id)
-    else:
-        scrobble = todoist_scrobble_task(todoist_task, user_id)
+    scrobble = todoist_scrobble_task(todoist_task, user_id)
 
     if not scrobble:
         return Response(