From e3cd1ab37f5642819b8767f7482b2812d6689657 Mon Sep 17 00:00:00 2001 From: ColonistOne Date: Wed, 8 Apr 2026 15:20:22 +0100 Subject: [PATCH] Add emoji reaction methods for posts and comments Add react_post() and react_comment() to ColonyClient for toggling emoji reactions via POST /posts/{id}/react and POST /comments/{id}/react. Calling with the same emoji again removes the reaction (toggle behavior). Co-Authored-By: Claude Opus 4.6 (1M context) --- src/colony_sdk/client.py | 24 ++++++++++++++++++++++++ tests/test_api_methods.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/colony_sdk/client.py b/src/colony_sdk/client.py index 18151ed..f381a14 100644 --- a/src/colony_sdk/client.py +++ b/src/colony_sdk/client.py @@ -286,6 +286,30 @@ def vote_comment(self, comment_id: str, value: int = 1) -> dict: """Upvote (+1) or downvote (-1) a comment.""" return self._raw_request("POST", f"/comments/{comment_id}/vote", body={"value": value}) + # ── Reactions ──────────────────────────────────────────────────── + + def react_post(self, post_id: str, emoji: str) -> dict: + """Toggle an emoji reaction on a post. + + Calling again with the same emoji removes the reaction. + + Args: + post_id: The post UUID. + emoji: Emoji string (e.g. ``"👍"``, ``"🔥"``). + """ + return self._raw_request("POST", f"/posts/{post_id}/react", body={"emoji": emoji}) + + def react_comment(self, comment_id: str, emoji: str) -> dict: + """Toggle an emoji reaction on a comment. + + Calling again with the same emoji removes the reaction. + + Args: + comment_id: The comment UUID. + emoji: Emoji string (e.g. ``"👍"``, ``"🔥"``). + """ + return self._raw_request("POST", f"/comments/{comment_id}/react", body={"emoji": emoji}) + # ── Messaging ──────────────────────────────────────────────────── def send_message(self, username: str, body: str) -> dict: diff --git a/tests/test_api_methods.py b/tests/test_api_methods.py index d1161b8..591b217 100644 --- a/tests/test_api_methods.py +++ b/tests/test_api_methods.py @@ -496,6 +496,37 @@ def test_vote_comment(self, mock_urlopen: MagicMock) -> None: assert _last_body(mock_urlopen) == {"value": 1} +# --------------------------------------------------------------------------- +# Reactions +# --------------------------------------------------------------------------- + + +class TestReactions: + @patch("colony_sdk.client.urlopen") + def test_react_post(self, mock_urlopen: MagicMock) -> None: + mock_urlopen.return_value = _mock_response({"toggled": True}) + client = _authed_client() + + client.react_post("p1", "👍") + + req = _last_request(mock_urlopen) + assert req.get_method() == "POST" + assert req.full_url == f"{BASE}/posts/p1/react" + assert _last_body(mock_urlopen) == {"emoji": "👍"} + + @patch("colony_sdk.client.urlopen") + def test_react_comment(self, mock_urlopen: MagicMock) -> None: + mock_urlopen.return_value = _mock_response({"toggled": True}) + client = _authed_client() + + client.react_comment("c1", "🔥") + + req = _last_request(mock_urlopen) + assert req.get_method() == "POST" + assert req.full_url == f"{BASE}/comments/c1/react" + assert _last_body(mock_urlopen) == {"emoji": "🔥"} + + # --------------------------------------------------------------------------- # Messaging # ---------------------------------------------------------------------------