Compare commits

...

1 Commits
17.1 ... 17.2

Author SHA1 Message Date
125da84f4e [tasks] Fix emacs scrobbling of tasks 2025-06-27 11:32:09 -04:00
3 changed files with 20 additions and 8 deletions

View File

@ -409,7 +409,7 @@ def todoist_scrobble_task(
user_id: int, user_id: int,
started: bool = False, started: bool = False,
stopped: bool = False, stopped: bool = False,
context_list: list = [], context_list: list[str] = [],
) -> Scrobble: ) -> Scrobble:
title = get_title_from_labels(todoist_task.get("todoist_label_list", []), context_list) title = get_title_from_labels(todoist_task.get("todoist_label_list", []), context_list)
task = Task.find_or_create(title) task = Task.find_or_create(title)

View File

@ -1,11 +1,12 @@
import logging import logging
from django.conf import settings
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def get_title_from_labels(labels: list[str], user_context_labels: list[str] = []) -> str: def get_title_from_labels(labels: list[str], user_context_labels: list[str] = []) -> str:
title = "Unknown" title = "Unknown"
task_context_labels: list = user_context_labels or DEFAULT_TASK_CONTEXT_LABELS task_context_labels: list = user_context_labels or settings.DEFAULT_TASK_CONTEXT_TAG_LIST
for label in labels: for label in labels:
# TODO We may also want to take a user list of labels instead # TODO We may also want to take a user list of labels instead
if label in task_context_labels: if label in task_context_labels:

View File

@ -71,9 +71,9 @@ def todoist_webhook(request):
"updated_at": task_data.get("updated_at"), "updated_at": task_data.get("updated_at"),
"details": task_data.get("description"), "details": task_data.get("description"),
"notes": event_data.get("content"), "notes": event_data.get("content"),
"is_deleted": True "is_deleted": (
if event_data.get("is_deleted") == "true" True if event_data.get("is_deleted") == "true" else False
else False, ),
} }
if (is_added and not todoist_note) or (is_updated and not todoist_task): if (is_added and not todoist_note) or (is_updated and not todoist_task):
@ -90,12 +90,17 @@ def todoist_webhook(request):
) )
return Response({}, status=status.HTTP_304_NOT_MODIFIED) return Response({}, status=status.HTTP_304_NOT_MODIFIED)
user_profile = UserProfile.objects.filter(todoist_user_id=post_data.get("user_id")).first() user_profile = UserProfile.objects.filter(
todoist_user_id=post_data.get("user_id", None)
).first()
scrobble = None scrobble = None
if todoist_task: if todoist_task:
scrobble = todoist_scrobble_task( scrobble = todoist_scrobble_task(
todoist_task, user_profile.user_id, stopped=task_stopped, context_list=user_profile.task_context_tags todoist_task,
user_profile.user_id,
stopped=task_stopped,
context_list=user_profile.task_context_tags,
) )
if todoist_note: if todoist_note:
@ -139,10 +144,16 @@ def emacs_webhook(request):
if not user_id: if not user_id:
user_id = 1 user_id = 1
user_profile = UserProfile.objects.filter(user_id=user_id)
scrobble = None scrobble = None
if post_data.get("source_id"): if post_data.get("source_id"):
scrobble = emacs_scrobble_task( scrobble = emacs_scrobble_task(
post_data, user_id, started=task_in_progress, stopped=task_stopped post_data,
user_id,
started=task_in_progress,
stopped=task_stopped,
context_list=user_profile.task_context_tags,
) )
if not scrobble: if not scrobble: