Skip to content

Commit e51c15c

Browse files
prah23neiljp
authored andcommitted
bugfix: boxes: Allow message body editing when limit doesn't exist.
This commit fixes a bug that doesn't let users edit the message body when the `realm_message_content_edit_limit_seconds` sent by the server is 0 for a realm. Prior to this commit, this configuration of 0 was treated as a complete restriction against message body editing, while the configuration actually signified no limit in message body editing. Fixes #1034.
1 parent 02eaab5 commit e51c15c

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

tests/ui/test_ui_tools.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,28 +1901,32 @@ def test_keypress_STREAM_MESSAGE(self, mocker, msg_box, widget_size,
19011901
@pytest.mark.parametrize(['to_vary_in_each_message',
19021902
'realm_editing_allowed',
19031903
'msg_body_edit_enabled',
1904+
'msg_body_edit_limit',
19041905
'expect_editing_to_succeed'], [
1905-
({'sender_id': 2, 'timestamp': 45}, True, True, False),
1906-
({'sender_id': 1, 'timestamp': 1}, True, False, True),
1907-
({'sender_id': 1, 'timestamp': 45}, False, True, False),
1908-
({'sender_id': 1, 'timestamp': 45}, True, True, True),
1906+
({'sender_id': 2, 'timestamp': 45}, True, True, 60, False),
1907+
({'sender_id': 1, 'timestamp': 1}, True, False, 60, True),
1908+
({'sender_id': 1, 'timestamp': 45}, False, True, 60, False),
1909+
({'sender_id': 1, 'timestamp': 45}, True, True, 60, True),
1910+
({'sender_id': 1, 'timestamp': 1}, True, True, 0, True),
19091911
], ids=['msg_sent_by_other_user',
19101912
'topic_edit_only_after_time_limit',
19111913
'editing_not_allowed',
1912-
'all_conditions_met'])
1914+
'all_conditions_met',
1915+
'no_msg_body_edit_limit'])
19131916
def test_keypress_EDIT_MESSAGE(self, mocker, message_fixture, widget_size,
19141917
expect_editing_to_succeed,
19151918
to_vary_in_each_message,
19161919
realm_editing_allowed,
19171920
msg_body_edit_enabled,
1921+
msg_body_edit_limit,
19181922
key):
19191923
varied_message = dict(message_fixture, **to_vary_in_each_message)
19201924
msg_box = MessageBox(varied_message, self.model, message_fixture)
19211925
size = widget_size(msg_box)
19221926
msg_box.model.user_id = 1
19231927
msg_box.model.initial_data = {
19241928
'realm_allow_message_editing': realm_editing_allowed,
1925-
'realm_message_content_edit_limit_seconds': 60,
1929+
'realm_message_content_edit_limit_seconds': msg_body_edit_limit,
19261930
}
19271931
msg_box.model.client.get_raw_message.return_value = {
19281932
'raw_content': "Edit this message"
@@ -1931,9 +1935,10 @@ def test_keypress_EDIT_MESSAGE(self, mocker, message_fixture, widget_size,
19311935
write_box.msg_edit_id = None
19321936
write_box.msg_body_edit_enabled = None
19331937
mocker.patch("zulipterminal.ui_tools.boxes.time", return_value=100)
1934-
# private messages cannot be edited after time-limit.
1938+
# private messages cannot be edited after time-limit, if there is one.
19351939
if (varied_message['type'] == 'private'
1936-
and varied_message['timestamp'] == 1):
1940+
and varied_message['timestamp'] == 1
1941+
and msg_body_edit_limit > 0):
19371942
expect_editing_to_succeed = False
19381943

19391944
msg_box.keypress(size, key)

zulipterminal/ui_tools/boxes.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,23 +1518,26 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
15181518
" Editing sent message is disabled.", 3)
15191519
return key
15201520
# Check if message is still editable, i.e. within
1521-
# the time limit.
1522-
time_since_msg_sent = time() - self.message['timestamp']
1523-
edit_time_limit = self.model.initial_data[
1524-
'realm_message_content_edit_limit_seconds']
1521+
# the time limit. A limit of 0 signifies no limit
1522+
# on message body editing.
15251523
msg_body_edit_enabled = True
1526-
if time_since_msg_sent >= edit_time_limit:
1527-
if self.message['type'] == 'private':
1528-
self.model.controller.view.set_footer_text(
1529-
" Time Limit for editing the message has"
1530-
" been exceeded.", 3)
1531-
return key
1532-
elif self.message['type'] == 'stream':
1533-
self.model.controller.view.set_footer_text(
1534-
" Only topic editing allowed."
1535-
" Time Limit for editing the message body has"
1536-
" been exceeded.", 3)
1537-
msg_body_edit_enabled = False
1524+
if self.model.initial_data[
1525+
'realm_message_content_edit_limit_seconds'] > 0:
1526+
time_since_msg_sent = time() - self.message['timestamp']
1527+
edit_time_limit = self.model.initial_data[
1528+
'realm_message_content_edit_limit_seconds']
1529+
if time_since_msg_sent >= edit_time_limit:
1530+
if self.message['type'] == 'private':
1531+
self.model.controller.view.set_footer_text(
1532+
" Time Limit for editing the message has"
1533+
" been exceeded.", 3)
1534+
return key
1535+
elif self.message['type'] == 'stream':
1536+
self.model.controller.view.set_footer_text(
1537+
" Only topic editing allowed."
1538+
" Time Limit for editing the message body has"
1539+
" been exceeded.", 3)
1540+
msg_body_edit_enabled = False
15381541

15391542
if self.message['type'] == 'private':
15401543
self.keypress(size, 'enter')

0 commit comments

Comments
 (0)