Skip to content

Commit 42863b0

Browse files
committed
model: Improve reporting upon moving/splitting topic.
1 parent ef12257 commit 42863b0

File tree

2 files changed

+52
-14
lines changed

2 files changed

+52
-14
lines changed

tests/model/test_model.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -834,78 +834,102 @@ def test_update_private_message(
834834
],
835835
)
836836
@pytest.mark.parametrize(
837-
"req, old_topic, footer_updated",
837+
"req, old_topic, stream_name, footer_updated, expected_report_success",
838838
[
839-
(
839+
case(
840840
{
841841
"message_id": 1,
842842
"propagate_mode": "change_one",
843843
"content": "hi!",
844844
"topic": "Some topic",
845845
},
846846
"Some topic",
847+
"stream",
847848
False,
849+
"You changed one message's topic from #stream > Some topic to #stream > Some topic.",
848850
),
849-
(
851+
case(
850852
{
851853
"message_id": 1,
852854
"propagate_mode": "change_one",
853855
"topic": "Topic change",
854856
},
855857
"Old topic",
858+
"stream",
856859
True,
860+
"You changed one message's topic from #stream > Old topic to #stream > Topic change.",
857861
),
858-
(
859-
{"message_id": 1, "propagate_mode": "change_all", "topic": "Old topic"},
862+
case(
863+
{
864+
"message_id": 1,
865+
"propagate_mode": "change_all",
866+
"topic": "Old topic",
867+
},
860868
"Old topic",
869+
"stream",
861870
False,
871+
"You changed all messages' topic from #stream > Old topic to #stream > Old change.",
862872
),
863-
(
873+
case(
864874
{
865875
"message_id": 1,
866876
"propagate_mode": "change_later",
867877
"content": ":smile:",
868878
"topic": "terminal",
869879
},
870880
"terminal",
881+
"stream",
871882
False,
883+
"You changed some messages' topic from #stream > terminal to #stream > terminal.",
872884
),
873-
(
885+
case(
874886
{
875887
"message_id": 1,
876888
"propagate_mode": "change_one",
877889
"content": "Hey!",
878890
"topic": "grett",
879891
},
880892
"greet",
893+
"stream",
881894
True,
895+
"You changed one message's topic from #stream > greet to #stream > grett.",
882896
),
883-
(
897+
case(
884898
{
885899
"message_id": 1,
886900
"propagate_mode": "change_all",
887901
"content": "Lets party!",
888902
"topic": "party",
889903
},
890904
"lets_party",
905+
"stream",
891906
True,
907+
"You changed all messages' topic from #stream > lets_party to #stream > party.",
892908
),
893909
],
894910
)
895911
def test_update_stream_message(
896-
self, mocker, model, response, return_value, req, old_topic, footer_updated
912+
self,
913+
mocker,
914+
model,
915+
response,
916+
return_value,
917+
req,
918+
old_topic,
919+
stream_name,
920+
footer_updated,
921+
expected_report_success,
897922
):
898923
self.client.update_message = mocker.Mock(return_value=response)
899924
model.index["messages"][req["message_id"]]["subject"] = old_topic
900-
925+
model.index["messages"][req["message_id"]]["display_recipient"] = stream_name
901926
result = model.update_stream_message(**req)
902-
903927
self.client.update_message.assert_called_once_with(req)
904928
assert result == return_value
905929
self.display_error_if_present.assert_called_once_with(response, self.controller)
906930
report_success = model.controller.report_success
907931
if result and footer_updated:
908-
report_success.assert_called_once_with("You changed a message's topic.")
932+
report_success.assert_called_once_with(expected_report_success)
909933
else:
910934
report_success.assert_not_called()
911935

zulipterminal/model.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,24 @@ def update_stream_message(
576576
response = self.client.update_message(request)
577577
display_error_if_present(response, self.controller)
578578
if response["result"] == "success":
579-
old_topic = self.index["messages"][message_id].get("subject", None)
579+
get_message = self.index["messages"][message_id]
580+
old_topic = get_message.get("subject", None)
580581
new_topic = request["topic"]
582+
stream_name = get_message.get("display_recipient", None)
583+
584+
recent_moved_msgs = ""
581585
if old_topic != new_topic:
582-
self.controller.report_success("You changed a message's topic.")
586+
if propagate_mode == "change_one":
587+
recent_moved_msgs = "one"
588+
one_message = f"You changed {recent_moved_msgs} message's topic from #{stream_name} > {old_topic} to #{stream_name} > {new_topic}."
589+
self.controller.report_success(one_message)
590+
else:
591+
if propagate_mode == "change_all":
592+
recent_moved_msgs = "all"
593+
if propagate_mode == "change_later":
594+
recent_moved_msgs = "some"
595+
some_all_messages = f"You changed {recent_moved_msgs} messages' topic from #{stream_name} > {old_topic} to #{stream_name} > {new_topic}."
596+
self.controller.report_success(some_all_messages)
583597

584598
return response["result"] == "success"
585599

0 commit comments

Comments
 (0)