[tasks] Stop ignoring notes

This commit is contained in:
2024-11-01 11:16:24 -04:00
parent 3388471685
commit 4ed5117900

View File

@ -45,7 +45,7 @@ def todoist_webhook(request):
) )
is_added = todoist_event in ["added"] is_added = todoist_event in ["added"]
if is_item_type: if is_item_type and is_updated:
todoist_task = { todoist_task = {
"todoist_id": event_data.get("id"), "todoist_id": event_data.get("id"),
"todoist_label_list": event_data.get("labels"), "todoist_label_list": event_data.get("labels"),
@ -56,7 +56,7 @@ def todoist_webhook(request):
"description": event_data.get("content"), "description": event_data.get("content"),
"details": event_data.get("description"), "details": event_data.get("description"),
} }
if is_note_type: if is_note_type and is_added:
task_data = event_data.get("item", {}) task_data = event_data.get("item", {})
todoist_note = { todoist_note = {
"todoist_id": task_data.get("id"), "todoist_id": task_data.get("id"),
@ -70,7 +70,8 @@ def todoist_webhook(request):
if event_data.get("is_deleted") == "true" if event_data.get("is_deleted") == "true"
else False, else False,
} }
else:
if not todoist_note or todoist_event:
logger.info( logger.info(
"[todoist_webhook] ignoring wrong todoist type", "[todoist_webhook] ignoring wrong todoist type",
extra={ extra={
@ -80,26 +81,16 @@ def todoist_webhook(request):
) )
return Response({}, status=status.HTTP_304_NOT_MODIFIED) return Response({}, status=status.HTTP_304_NOT_MODIFIED)
if is_item_type and new_labels == old_labels:
logger.info(
"[todoist_webhook] ignoring item, labels unchanged",
extra={
"todoist_type": todoist_task["todoist_type"],
"todoist_event": todoist_task["todoist_event"],
},
)
return Response({}, status=status.HTTP_304_NOT_MODIFIED)
user_id = ( user_id = (
UserProfile.objects.filter(todoist_user_id=post_data.get("user_id")) UserProfile.objects.filter(todoist_user_id=post_data.get("user_id"))
.first() .first()
.user_id .user_id
) )
if todoist_task and is_updated: if todoist_task:
scrobble = todoist_scrobble_task(todoist_task, user_id) scrobble = todoist_scrobble_task(todoist_task, user_id)
if todoist_note and is_added: if todoist_note:
scrobble = todoist_scrobble_update_task(todoist_note, user_id) scrobble = todoist_scrobble_update_task(todoist_note, user_id)
if not scrobble: if not scrobble: