Skip to content

Commit 5137a37

Browse files
committed
model: Improve reporting upon moving/spliting topic.
1 parent 431043e commit 5137a37

File tree

2 files changed

+73
-7
lines changed

2 files changed

+73
-7
lines changed

tests/model/test_model.py

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -834,78 +834,130 @@ def test_update_private_message(
834834
],
835835
)
836836
@pytest.mark.parametrize(
837-
"req, old_topic, footer_updated",
837+
"test_id, req, old_topic, new_topic, stream_name, propagate_mode, footer_updated",
838838
[
839839
(
840+
1,
840841
{
841842
"message_id": 1,
842843
"propagate_mode": "change_one",
843844
"content": "hi!",
844845
"topic": "Some topic",
845846
},
846847
"Some topic",
848+
"Some topic",
849+
"stream",
850+
"change_one",
847851
False,
848852
),
849853
(
854+
2,
850855
{
851856
"message_id": 1,
852857
"propagate_mode": "change_one",
853858
"topic": "Topic change",
854859
},
855860
"Old topic",
861+
"Topic change",
862+
"stream",
863+
"change_one",
856864
True,
857865
),
858866
(
859-
{"message_id": 1, "propagate_mode": "change_all", "topic": "Old topic"},
867+
3,
868+
{
869+
"message_id": 1,
870+
"propagate_mode": "change_all",
871+
"topic": "Old topic",
872+
},
873+
"Old topic",
860874
"Old topic",
875+
"stream",
876+
"change_one",
861877
False,
862878
),
863879
(
880+
4,
864881
{
865882
"message_id": 1,
866883
"propagate_mode": "change_later",
867884
"content": ":smile:",
868885
"topic": "terminal",
869886
},
870887
"terminal",
888+
"terminal",
889+
"stream",
890+
"change_later",
871891
False,
872892
),
873893
(
894+
5,
874895
{
875896
"message_id": 1,
876897
"propagate_mode": "change_one",
877898
"content": "Hey!",
878899
"topic": "grett",
879900
},
880901
"greet",
902+
"grett",
903+
"stream",
904+
"change_one",
881905
True,
882906
),
883907
(
908+
6,
884909
{
885910
"message_id": 1,
886911
"propagate_mode": "change_all",
887912
"content": "Lets party!",
888913
"topic": "party",
889914
},
890915
"lets_party",
916+
"party",
917+
"stream",
918+
"change_all",
891919
True,
892920
),
893921
],
894922
)
895923
def test_update_stream_message(
896-
self, mocker, model, response, return_value, req, old_topic, footer_updated
924+
self,
925+
mocker,
926+
model,
927+
response,
928+
return_value,
929+
test_id,
930+
req,
931+
old_topic,
932+
new_topic,
933+
stream_name,
934+
propagate_mode,
935+
footer_updated,
897936
):
898937
self.client.update_message = mocker.Mock(return_value=response)
899938
model.index["messages"][req["message_id"]]["subject"] = old_topic
939+
req["topic"] = new_topic
940+
model.index["messages"][req["message_id"]]["display_recipient"] = stream_name
941+
req["propagate_mode"] = propagate_mode
900942

901943
result = model.update_stream_message(**req)
902-
903944
self.client.update_message.assert_called_once_with(req)
904945
assert result == return_value
905946
self.display_error_if_present.assert_called_once_with(response, self.controller)
906947
report_success = model.controller.report_success
907948
if result and footer_updated:
908-
report_success.assert_called_once_with("You changed a message's topic.")
949+
if propagate_mode == "change_one":
950+
report_success.assert_called_once_with(
951+
f"You changed one message's topic from #{stream_name} > {old_topic} to #{stream_name} > {new_topic}."
952+
)
953+
elif propagate_mode == "change_later":
954+
report_success.assert_called_once_with(
955+
f"You changed some messages' topic from #{stream_name} > {old_topic} to #{stream_name} > {new_topic}."
956+
)
957+
else:
958+
report_success.assert_called_once_with(
959+
f"You changed all messages' topic from #{stream_name} > {old_topic} to #{stream_name} > {new_topic}."
960+
)
909961
else:
910962
report_success.assert_not_called()
911963

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"]
580+
old_topic = get_message[message_id].get("subject", None)
580581
new_topic = request["topic"]
582+
stream_name = get_message[message_id].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)