From 149d7ae97eeececde6e3772e1fac699f82058204 Mon Sep 17 00:00:00 2001 From: Misha Tomilov Date: Tue, 10 Dec 2024 14:49:59 +0100 Subject: [PATCH] Render replies differently than annotations (#12) --- src/slack_annotations/format.py | 7 ++++++ tests/unit/slack_annotations/format_test.py | 24 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/slack_annotations/format.py b/src/slack_annotations/format.py index 6e9b6d4..e10b363 100644 --- a/src/slack_annotations/format.py +++ b/src/slack_annotations/format.py @@ -101,6 +101,13 @@ def _build_annotation_fields(annotation: dict[str, Any]) -> list[dict[str, Any]] }, {"type": "plain_text", "text": quote}, ] + elif annotation.get("references"): + fields = [ + { + "type": "mrkdwn", + "text": f"*Reply* (<{incontext_link}|in-context link>):", + }, + ] else: fields = [ { diff --git a/tests/unit/slack_annotations/format_test.py b/tests/unit/slack_annotations/format_test.py index 125ee43..f6ae938 100644 --- a/tests/unit/slack_annotations/format_test.py +++ b/tests/unit/slack_annotations/format_test.py @@ -119,3 +119,27 @@ def test_page_note(self): {"type": "plain_text", "text": "(None)"}, ], } + + def test_reply(self): + annotation = { + "user": "acct:test_user_1@hypothes.is", + "uri": "https://example.com/", + "links": {"incontext": "https://hyp.is/test_annotation_id_1/example.com/"}, + "user_info": {"display_name": None}, + "references": ["test_annotation_id_2"], + } + + assert _format_annotation(annotation) == { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "`test_user_1` annotated https://example.com/:", + }, + "fields": [ + { + "type": "mrkdwn", + "text": "*Reply* ():", + }, + {"type": "plain_text", "text": "(None)"}, + ], + }