Skip to content

Commit 6cd0fc8

Browse files
committed
api_types/model: Add types for updating messages and apply them.
1 parent 1cbbe58 commit 6cd0fc8

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

zulipterminal/api_types.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from typing import Any, Dict, List, Optional, Union
88

9-
from typing_extensions import Literal, TypedDict
9+
from typing_extensions import Literal, NotRequired, TypedDict
1010

1111
# These are documented in the zulip package (python-zulip-api repo)
1212
from zulip import EditPropagateMode # one/all/later
@@ -36,9 +36,38 @@ class StreamComposition(TypedDict):
3636
subject: str # TODO: Migrate to using topic
3737

3838

39+
# https://zulip.com/api/send-message
3940
Composition = Union[PrivateComposition, StreamComposition]
4041

4142

43+
class PrivateMessageUpdateRequest(TypedDict):
44+
message_id: int
45+
content: str
46+
47+
48+
class StreamMessageUpdateRequest(TypedDict):
49+
message_id: int
50+
51+
# May update combination of content for specified message
52+
# ...and/or topic of that message and potentially others (via mode)
53+
# ...but content and stream may not be changed together
54+
content: NotRequired[str]
55+
topic: NotRequired[str]
56+
propagate_mode: NotRequired[EditPropagateMode]
57+
58+
# Supported for stream moves in ZFL 9 (Zulip 3)
59+
# Default values if not passed in ZFL 152 (Zulip 6)
60+
send_notification_to_old_thread: NotRequired[bool]
61+
send_notification_to_new_thread: NotRequired[bool]
62+
63+
# TODO: Implement message moves between streams
64+
# stream_id: int
65+
66+
67+
# https://zulip.com/api/update-message
68+
MessageUpdateRequest = Union[PrivateMessageUpdateRequest, StreamMessageUpdateRequest]
69+
70+
4271
class Message(TypedDict, total=False):
4372
id: int
4473
sender_id: int

zulipterminal/model.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
EditPropagateMode,
3535
Event,
3636
PrivateComposition,
37+
PrivateMessageUpdateRequest,
3738
RealmEmojiData,
3839
RealmUser,
3940
StreamComposition,
41+
StreamMessageUpdateRequest,
4042
Subscription,
4143
)
4244
from zulipterminal.config.keys import primary_key_for_command
@@ -561,7 +563,7 @@ def send_stream_message(self, stream: str, topic: str, content: str) -> bool:
561563
return message_was_sent
562564

563565
def update_private_message(self, msg_id: int, content: str) -> bool:
564-
request = {
566+
request: PrivateMessageUpdateRequest = {
565567
"message_id": msg_id,
566568
"content": content,
567569
}
@@ -578,7 +580,7 @@ def update_stream_message(
578580
notify_old: bool = False,
579581
notify_new: bool = False,
580582
) -> bool:
581-
request = {
583+
request: StreamMessageUpdateRequest = {
582584
"message_id": message_id,
583585
"propagate_mode": propagate_mode,
584586
"topic": topic,

0 commit comments

Comments
 (0)