Skip to content

Commit 2fd6254

Browse files
committed
bugfix: boxes: Set propagate_mode to change_one if topic unchanged.
The intent of the edit/update message API has recently been clarified that if the topic is unchanged (even if sent) that the propagate_mode should be set to change_one. This was previously not enforced by the server but was changed to do so in zulip/zulip@e231a03 Since our propagate_mode defaults to change_later via the UI element, the above change to the server leads to errors upon attempting content-only edits. To resolve this, the original topic is added to the new tuple form of msg_edit_state, allowing detection of whether the topic has changed and setting of propagate_mode as appropriate. The decision to use change_one is dependent upon the trimmed new topic since otherwise the edit can confusingly fail since trimming is checked on the server end and results in the same propagate error message. Tests updated.
1 parent 91bb72c commit 2fd6254

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

tests/ui/test_ui_tools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,6 +2306,7 @@ def test_keypress_EDIT_MESSAGE(
23062306

23072307
if expect_editing_to_succeed:
23082308
assert write_box.msg_edit_state.message_id == varied_message["id"]
2309+
assert write_box.msg_edit_state.old_topic == varied_message["subject"]
23092310
write_box.msg_write_box.set_edit_text.assert_called_once_with(
23102311
"Edit this message"
23112312
)

tests/ui_tools/test_boxes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ def test__process_typeaheads(
846846
)
847847
@pytest.mark.parametrize(
848848
"msg_edit_state",
849-
[_MessageEditState(message_id=10), None],
849+
[_MessageEditState(message_id=10, old_topic="old topic"), None],
850850
ids=["update_message", "send_message"],
851851
)
852852
@pytest.mark.parametrize("key", keys_for_command("SEND_MESSAGE"))
@@ -1065,7 +1065,9 @@ def test_keypress_CYCLE_COMPOSE_FOCUS(
10651065
if message_being_edited:
10661066
mocker.patch(BOXES + ".EditModeButton")
10671067
write_box.stream_box_edit_view(stream_id)
1068-
write_box.msg_edit_state = _MessageEditState(message_id=10)
1068+
write_box.msg_edit_state = _MessageEditState(
1069+
message_id=10, old_topic="some old topic"
1070+
)
10691071
else:
10701072
write_box.stream_box_view(stream_id)
10711073
else:

zulipterminal/ui_tools/boxes.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
class _MessageEditState(NamedTuple):
5757
message_id: int
58+
old_topic: str
5859

5960

6061
class WriteBox(urwid.Pile):
@@ -543,9 +544,16 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
543544
topic = self.title_write_box.edit_text
544545

545546
if self.msg_edit_state is not None:
547+
trimmed_topic = topic.strip()
548+
# Trimmed topic must be compared since that is server check
549+
if trimmed_topic == self.msg_edit_state.old_topic:
550+
propagate_mode = "change_one" # No change in topic
551+
else:
552+
propagate_mode = self.edit_mode_button.mode
553+
546554
args = dict(
547555
message_id=self.msg_edit_state.message_id,
548-
topic=topic,
556+
topic=topic, # NOTE: Send untrimmed topic always for now
549557
propagate_mode=self.edit_mode_button.mode,
550558
)
551559
if self.msg_body_edit_enabled:
@@ -1616,7 +1624,9 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
16161624
msg_id = self.message["id"]
16171625
msg = self.model.client.get_raw_message(msg_id)["raw_content"]
16181626
write_box = self.model.controller.view.write_box
1619-
write_box.msg_edit_state = _MessageEditState(message_id=msg_id)
1627+
write_box.msg_edit_state = _MessageEditState(
1628+
message_id=msg_id, old_topic=self.message["subject"]
1629+
)
16201630
write_box.msg_write_box.set_edit_text(msg)
16211631
write_box.msg_write_box.set_edit_pos(len(msg))
16221632
write_box.msg_body_edit_enabled = msg_body_edit_enabled

0 commit comments

Comments
 (0)