Skip to content

Commit 59439d3

Browse files
committed
model/boxes: Allow users to post stream messages without a topic.
This follows the convention used by other Zulip clients to automatically post a message without a topic to a topic named '(no topic)'. Also, while editing such topics, the topic name would be shown as empty to the user, even though in reality it is not. This is done to make it easier for users to set names to empty topics, as well as to follow the behaviour of other clients. Tests amended. Fixes #754.
1 parent 7efcc7f commit 59439d3

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

tests/model/test_model.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,26 @@ def test_send_private_message(self, mocker, model,
395395
({'result': 'success'}, True),
396396
({'result': 'some_failure'}, False),
397397
])
398+
@pytest.mark.parametrize(['topic_set_by_user',
399+
'topic_sent_to_server'], [
400+
('bar', 'bar'),
401+
('', '(no topic)'),
402+
], ids=[
403+
'message_with_topic',
404+
'message_with_no_topic',
405+
])
398406
def test_send_stream_message(self, mocker, model,
399407
response, return_value,
400-
content="hi!",
401-
stream="foo", topic="bar"):
408+
topic_sent_to_server,
409+
topic_set_by_user, content="hi!",
410+
stream="foo"):
402411
self.client.send_message = mocker.Mock(return_value=response)
403412

404-
result = model.send_stream_message(stream, topic, content)
413+
result = model.send_stream_message(stream, topic_set_by_user,
414+
content)
405415

406-
req = dict(type='stream', to=stream, subject=topic, content=content)
416+
req = dict(type='stream', to=stream, subject=topic_sent_to_server,
417+
content=content)
407418
self.client.send_message.assert_called_once_with(req)
408419

409420
assert result == return_value
@@ -433,16 +444,22 @@ def test_update_private_message(self, mocker, model,
433444
({'result': 'success'}, True),
434445
({'result': 'some_failure'}, False),
435446
])
447+
@pytest.mark.parametrize('topic_set_by_user, topic_sent_to_server', [
448+
('bar', 'bar'),
449+
('', '(no topic)'),
450+
], ids=[
451+
'message_with_topic',
452+
'message_with_no_topic',
453+
])
436454
def test_update_stream_message(self, mocker, model,
437455
response, return_value,
438-
content="hi!",
439-
subject='Hello',
440-
msg_id=1):
456+
topic_set_by_user, topic_sent_to_server,
457+
content="hi!", msg_id=1):
441458
self.client.update_message = mocker.Mock(return_value=response)
442459

443-
result = model.update_stream_message(subject, msg_id, content)
460+
result = model.update_stream_message(topic_set_by_user, msg_id, content)
444461

445-
req = dict(subject=subject, propagate_mode="change_one",
462+
req = dict(subject=topic_sent_to_server, propagate_mode="change_one",
446463
message_id=msg_id, content=content)
447464
self.client.update_message.assert_called_once_with(req)
448465

zulipterminal/model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ def send_private_message(self, recipients: str,
310310

311311
def send_stream_message(self, stream: str, topic: str,
312312
content: str) -> bool:
313+
if topic == '':
314+
topic = '(no topic)'
313315
request = {
314316
'type': 'stream',
315317
'to': stream,
@@ -331,6 +333,8 @@ def update_private_message(self, msg_id: int, content: str) -> bool:
331333

332334
def update_stream_message(self, topic: str, msg_id: int,
333335
content: str) -> bool:
336+
if topic == '':
337+
topic = '(no topic)'
334338
request = {
335339
"message_id": msg_id,
336340
"content": content,

zulipterminal/ui_tools/boxes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def stream_box_view(self, caption: str='', title: str='') -> None:
7575
caption="Stream: ",
7676
edit_text=caption
7777
)
78+
if title == '(no topic)':
79+
title = ''
7880
self.title_write_box = ReadlineEdit(caption="Topic: ",
7981
edit_text=title)
8082

0 commit comments

Comments
 (0)