Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
reactions: Add error code for duplicate addition/removal.
Alex Vandiver871a668dd25d
diff --git a/version.py b/version.pyindex 5b4f60e63c6..7b47b9c9723 100644--- a/version.py+++ b/version.py@@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"# Changes should be accompanied by documentation explaining what the# new level means in api_docs/changelog.md, as well as "**Changes**"# entries in the endpoint's documentation in `zulip.yaml`.-API_FEATURE_LEVEL = 192+API_FEATURE_LEVEL = 193# Bump the minor PROVISION_VERSION to indicate that folks should provision# only when going from an old version of the code to a newer version. Bumpdiff --git a/zerver/actions/reactions.py b/zerver/actions/reactions.pyindex e8b378966c4..2247c3b13c4 100644--- a/zerver/actions/reactions.py+++ b/zerver/actions/reactions.py@@ -1,10 +1,8 @@from typing import Any, Dict, Optional-from django.utils.translation import gettext as _-from zerver.actions.create_user import create_historical_user_messagesfrom zerver.lib.emoji import check_emoji_request, get_emoji_data-from zerver.lib.exceptions import JsonableError+from zerver.lib.exceptions import ReactionExistsErrorfrom zerver.lib.message import access_message, update_to_dict_cachefrom zerver.lib.stream_subscription import subscriber_ids_with_stream_history_accessfrom zerver.models import Message, Reaction, Recipient, Stream, UserMessage, UserProfile@@ -115,7 +113,7 @@ def check_add_reaction(emoji_code=emoji_code,reaction_type=reaction_type,).exists():- raise JsonableError(_("Reaction already exists."))+ raise ReactionExistsErrorquery = Reaction.objects.filter(message=message, emoji_code=emoji_code, reaction_type=reaction_typediff --git a/zerver/lib/exceptions.py b/zerver/lib/exceptions.pyindex 51d57f557bc..f736052fbcb 100644--- a/zerver/lib/exceptions.py+++ b/zerver/lib/exceptions.py@@ -40,6 +40,8 @@ class ErrorCode(Enum):UNAUTHORIZED = auto()REQUEST_TIMEOUT = auto()MOVE_MESSAGES_TIME_LIMIT_EXCEEDED = auto()+ REACTION_ALREADY_EXISTS = auto()+ REACTION_DOES_NOT_EXIST = auto()class JsonableError(Exception):@@ -503,3 +505,25 @@ class MessageMoveError(JsonableError):return _("You only have permission to move the {total_messages_allowed_to_move}/{total_messages_in_topic} most recent messages in this topic.")+++class ReactionExistsError(JsonableError):+ code = ErrorCode.REACTION_ALREADY_EXISTS++ def __init__(self) -> None:+ pass++ @staticmethod+ def msg_format() -> str:+ return _("Reaction already exists.")+++class ReactionDoesNotExistError(JsonableError):+ code = ErrorCode.REACTION_DOES_NOT_EXIST++ def __init__(self) -> None:+ pass++ @staticmethod+ def msg_format() -> str:+ return _("Reaction doesn't exist.")diff --git a/zerver/views/reactions.py b/zerver/views/reactions.pyindex 1df333c8bde..316d82eb0d5 100644--- a/zerver/views/reactions.py+++ b/zerver/views/reactions.py@@ -6,7 +6,7 @@ from django.utils.translation import gettext as _from zerver.actions.reactions import check_add_reaction, do_remove_reactionfrom zerver.lib.emoji import get_emoji_data-from zerver.lib.exceptions import JsonableError+from zerver.lib.exceptions import JsonableError, ReactionDoesNotExistErrorfrom zerver.lib.message import access_messagefrom zerver.lib.request import REQ, has_request_variablesfrom zerver.lib.response import json_success@@ -65,7 +65,7 @@ def remove_reaction(emoji_code=emoji_code,reaction_type=reaction_type,).exists():- raise JsonableError(_("Reaction doesn't exist."))+ raise ReactionDoesNotExistError# Unlike adding reactions, while deleting a reaction, we don't# check whether the provided (emoji_type, emoji_code) pair is