Skip to content

Commit 8a5347a

Browse files
committed
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, or a topic with only whitespaces, to a topic named '(no topic)'. Test added. Fixes #754.
1 parent 6bfa1ca commit 8a5347a

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

tests/ui_tools/test_boxes.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,47 @@ def test_generic_autocomplete_emojis(self, write_box, text,
234234
typeahead_string = write_box.generic_autocomplete(text, state)
235235
assert typeahead_string == required_typeahead
236236

237+
@pytest.mark.parametrize('topic_entered_by_user, topic_sent_to_server', [
238+
('', '(no topic)'),
239+
('hello', 'hello'),
240+
(' ', '(no topic)'),
241+
], ids=[
242+
'empty_topic',
243+
'non_empty_topic',
244+
'topic_with_whitespace',
245+
])
246+
@pytest.mark.parametrize('msg_edit_id', [10, None], ids=[
247+
'update_message',
248+
'send_message',
249+
])
250+
@pytest.mark.parametrize('key', keys_for_command('SEND_MESSAGE'))
251+
def test_keypress_SEND_MESSAGE_no_topic(self, mocker, write_box,
252+
msg_edit_id, topic_entered_by_user,
253+
topic_sent_to_server, key):
254+
write_box.stream_write_box = mocker.Mock()
255+
write_box.msg_write_box = mocker.Mock()
256+
write_box.title_write_box = mocker.Mock()
257+
write_box.msg_write_box.edit_text = ''
258+
write_box.to_write_box = None
259+
size = (20,)
260+
write_box.msg_edit_id = msg_edit_id
261+
write_box.title_write_box.edit_text = topic_entered_by_user
262+
263+
write_box.keypress(size, key)
264+
265+
if msg_edit_id:
266+
write_box.model.update_stream_message.assert_called_once_with(
267+
topic=topic_sent_to_server,
268+
content=write_box.msg_write_box.edit_text,
269+
msg_id=msg_edit_id,
270+
)
271+
else:
272+
write_box.model.send_stream_message.assert_called_once_with(
273+
stream=write_box.stream_write_box.edit_text,
274+
topic=topic_sent_to_server,
275+
content=write_box.msg_write_box.edit_text
276+
)
277+
237278
@pytest.mark.parametrize(['key', 'current_typeahead_mode',
238279
'expected_typeahead_mode',
239280
'expect_footer_was_reset'], [

zulipterminal/ui_tools/boxes.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from collections import OrderedDict, defaultdict
23
from datetime import date, datetime
34
from sys import platform
@@ -198,16 +199,21 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
198199

199200
if is_command_key('SEND_MESSAGE', key):
200201
if not self.to_write_box:
202+
if re.fullmatch(r'\s*', self.title_write_box.edit_text):
203+
topic = '(no topic)'
204+
else:
205+
topic = self.title_write_box.edit_text
206+
201207
if self.msg_edit_id:
202208
success = self.model.update_stream_message(
203-
topic=self.title_write_box.edit_text,
209+
topic=topic,
204210
content=self.msg_write_box.edit_text,
205211
msg_id=self.msg_edit_id,
206212
)
207213
else:
208214
success = self.model.send_stream_message(
209215
stream=self.stream_write_box.edit_text,
210-
topic=self.title_write_box.edit_text,
216+
topic=topic,
211217
content=self.msg_write_box.edit_text
212218
)
213219
else:

0 commit comments

Comments
 (0)