From 82472b1950800a1e48ab891c1f8e588af134f546 Mon Sep 17 00:00:00 2001 From: Andrew Shu Date: Tue, 19 Aug 2025 18:52:27 -0700 Subject: [PATCH 1/3] Minor style changes to API topic.py --- tildes/tildes/views/api/beta/topic.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tildes/tildes/views/api/beta/topic.py b/tildes/tildes/views/api/beta/topic.py index b8c87f3..02a40f7 100644 --- a/tildes/tildes/views/api/beta/topic.py +++ b/tildes/tildes/views/api/beta/topic.py @@ -60,8 +60,7 @@ def get_topics(request: Request) -> dict: # noqa # Parse parameters where necessary try: - period = ShortTimePeriod(allow_none=True) - period = period.deserialize(period_raw) + period = ShortTimePeriod(allow_none=True).deserialize(period_raw) except ValidationError as exc: return build_error_response(str(exc), field="period") @@ -128,11 +127,10 @@ def get_topic(request: Request) -> dict: f"Invalid order value: {comment_order_raw}", field="order", ) + elif request.user and request.user.comment_sort_order_default: + comment_order = request.user.comment_sort_order_default else: - if request.user and request.user.comment_sort_order_default: - comment_order = request.user.comment_sort_order_default - else: - comment_order = CommentTreeSortOption.RELEVANCE + comment_order = CommentTreeSortOption.RELEVANCE try: topic_id = id36_to_id(topic_id36) @@ -157,15 +155,17 @@ def get_topic(request: Request) -> dict: tree = CommentTree(comments, comment_order, request.user) tree.collapse_from_labels() - if request.user: - # collapse old comments if the user has a previous visit to the topic - # (and doesn't have that behavior disabled) - if topic.last_visit_time and request.user.collapse_old_comments: - tree.uncollapse_new_comments(topic.last_visit_time) - tree.finalize_collapsing_maximized() + # collapse old comments if the user has a previous visit to the topic + # (and doesn't have that behavior disabled) + if request.user and topic.last_visit_time and request.user.collapse_old_comments: + tree.uncollapse_new_comments(topic.last_visit_time) + tree.finalize_collapsing_maximized() commentsjson = comment_subtree_to_dict(request, tree.tree) # Construct the final response JSON object - response = {"topic": topic_to_dict(topic), "comments": commentsjson} + response = { + "topic": topic_to_dict(topic), + "comments": commentsjson, + } return response From f7e1d4f294378c6d5356289867cb53cbd8d03c36 Mon Sep 17 00:00:00 2001 From: Andrew Shu Date: Tue, 19 Aug 2025 19:03:37 -0700 Subject: [PATCH 2/3] Mark some Topic API properties as nonnull voted, bookmarked, and ignored cannot be None. see TopicQuery._process_result() in tildes/models/topic/topic_query.py --- tildes/openapi_beta.yaml | 3 --- tildes/tildes/models/topic/topic_query.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tildes/openapi_beta.yaml b/tildes/openapi_beta.yaml index 5204d74..8c3c0f0 100644 --- a/tildes/openapi_beta.yaml +++ b/tildes/openapi_beta.yaml @@ -316,13 +316,10 @@ components: nullable: true voted: type: boolean - nullable: true bookmarked: type: boolean - nullable: true ignored: type: boolean - nullable: true official: type: boolean tags: diff --git a/tildes/tildes/models/topic/topic_query.py b/tildes/tildes/models/topic/topic_query.py index 88694f9..0eb0d72 100644 --- a/tildes/tildes/models/topic/topic_query.py +++ b/tildes/tildes/models/topic/topic_query.py @@ -142,7 +142,7 @@ class TopicQuery(PaginatedQuery): topic.bookmark_created_time = None topic.last_visit_time = None topic.comments_since_last_visit = None - topic.user_bookmarked = None + topic.user_bookmarked = False topic.user_ignored = False else: topic = result.Topic From b4eaa2eed12c8108d33fed070b3eae8ca0abe488 Mon Sep 17 00:00:00 2001 From: Andrew Shu Date: Tue, 19 Aug 2025 19:31:41 -0700 Subject: [PATCH 3/3] Mark some Comments API properties as nonnull voted and bookmarked cannot be None. see CommentQuery._process_result() in tildes/models/comment/comment_query.py --- tildes/openapi_beta.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/tildes/openapi_beta.yaml b/tildes/openapi_beta.yaml index 8c3c0f0..436b571 100644 --- a/tildes/openapi_beta.yaml +++ b/tildes/openapi_beta.yaml @@ -387,10 +387,8 @@ components: nullable: true voted: type: boolean - nullable: true bookmarked: type: boolean - nullable: true depth: type: integer children: