Skip to content

Commit ea89e95

Browse files
neiljptimabbott
authored andcommitted
api: Add Literal types for various important message flags.
With some copy-editing by tabbott.
1 parent 113f9cb commit ea89e95

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

zulip/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def recur_expand(target_root: Any, dir: Any) -> Generator[Tuple[str, List[str]],
7171
"matrix_client",
7272
"distro",
7373
"click",
74+
"typing_extensions>=3.7",
7475
],
7576
)
7677

zulip/zulip/__init__.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import distro
3030
import requests
31+
from typing_extensions import Literal
3132

3233
__version__ = "0.8.1"
3334

@@ -44,6 +45,38 @@
4445

4546
API_VERSTRING = "v1/"
4647

48+
# An optional parameter to `move_topic` and `update_message` actions
49+
# See eg. https://zulip.com/api/update-message#parameter-propagate_mode
50+
EditPropagateMode = Literal["change_one", "change_all", "change_later"]
51+
52+
# Generally a `reaction_type` is present whenever an emoji is specified:
53+
# - Optional parameters to actions: `add_reaction`, `remove_reaction`
54+
# - Events: "user_status", "reaction", "message", "update_message"
55+
# - Inside each reaction in the `reactions` field of returned message objects.
56+
EmojiType = Literal["realm_emoji", "unicode_emoji", "zulip_extra_emoji"]
57+
58+
# Message flags which may be directly modified by the current user:
59+
# - Updated by `update_message_flags` (and for the `read` flag, also
60+
# the `mark_all_as_read`, `mark_stream_as_read`, and
61+
# `mark_topic_as_read` actions.
62+
# - User is notified of changes via `update_message_flags` events.
63+
# See subset of https://zulip.com/api/update-message-flags#available-flags
64+
ModifiableMessageFlag = Literal["read", "starred", "collapsed"]
65+
66+
# All possible message flags.
67+
# - Generally present in `flags` object of returned message objects.
68+
# - User is notified of changes via "update_message_flags" and `update_message`
69+
# events. The latter is important for clients to learn when a message is
70+
# edited to mention the current user or contain an alert word.
71+
# See https://zulip.com/api/update-message-flags#available-flags
72+
MessageFlag = Literal[
73+
ModifiableMessageFlag,
74+
"mentioned",
75+
"wildcard_mentioned",
76+
"has_alert_word",
77+
"historical",
78+
]
79+
4780

4881
class CountingBackoff:
4982
def __init__(
@@ -1638,7 +1671,7 @@ def move_topic(
16381671
topic: str,
16391672
new_topic: Optional[str] = None,
16401673
message_id: Optional[int] = None,
1641-
propagate_mode: str = "change_all",
1674+
propagate_mode: EditPropagateMode = "change_all",
16421675
notify_old_topic: bool = True,
16431676
notify_new_topic: bool = True,
16441677
) -> Dict[str, Any]:

0 commit comments

Comments
 (0)