Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

reactions: Add ReactionEvent TypedDict.

Sanket Srivastavae836d3e930a3
diff --git a/zerver/actions/reactions.py b/zerver/actions/reactions.py
index efa65e89bd4..dbd00b52936 100644
--- a/zerver/actions/reactions.py
+++ b/zerver/actions/reactions.py
@@ -1,4 +1,4 @@
-from typing import Any
+from typing import Literal
from typing_extensions import TypedDict
@@ -25,8 +25,22 @@ class ReactionEventUserDict(TypedDict):
full_name: str
+class ReactionEvent(TypedDict):
+ type: Literal["reaction"]
+ op: Literal["add", "remove"]
+ user_id: int
+ user: ReactionEventUserDict
+ message_id: int
+ emoji_name: str
+ emoji_code: str
+ reaction_type: str
+
+
def notify_reaction_update(
- user_profile: UserProfile, message: Message, reaction: Reaction, op: str
+ user_profile: UserProfile,
+ message: Message,
+ reaction: Reaction,
+ op: Literal["add", "remove"],
) -> None:
user_dict: ReactionEventUserDict = {
"user_id": user_profile.id,
@@ -34,7 +48,7 @@ def notify_reaction_update(
"full_name": user_profile.full_name,
}
- event: dict[str, Any] = {
+ event: ReactionEvent = {
"type": "reaction",
"op": op,
"user_id": user_profile.id,
diff --git a/zerver/tests/test_reactions.py b/zerver/tests/test_reactions.py
index be4700b66d3..5ea8e1b9b3b 100644
--- a/zerver/tests/test_reactions.py
+++ b/zerver/tests/test_reactions.py
@@ -1255,4 +1255,4 @@ class ReactionAPIEventTest(EmojiReactionBase):
m.side_effect = AssertionError(
"Events should be sent only after the transaction commits."
)
- notify_reaction_update(hamlet, message, reaction, "stuff")
+ notify_reaction_update(hamlet, message, reaction, "add")