Repository: zulip/zulip-terminal
Issue: Can't edit messages: "Time limit for editing the message body..."

I am running `zulip-term` from docker (https://github.com/zulip/zulip-terminal/blob/main/docker/Dockerfile.buster) and I am not able to edit messages I have sent, even if it is directly after. I see the error
```
Time limit for editing the message body exceeded
```
but I can go to the browser client and edit the message just fine.

Worth noting also that https://julialang.zulipchat.com, where I noticed this, doesn't enforce any time limit on edits.

cc @MasonProtter

Changed files:
tests/ui/test_ui_tools.py, zulipterminal/ui_tools/boxes.py

diff --git a/tests/ui/test_ui_tools.py b/tests/ui/test_ui_tools.py
index 29f36d3..4e0b362 100644
--- a/tests/ui/test_ui_tools.py
+++ b/tests/ui/test_ui_tools.py
@@ -1901,20 +1901,24 @@ class TestMessageBox:
     @pytest.mark.parametrize(['to_vary_in_each_message',
                               'realm_editing_allowed',
                               'msg_body_edit_enabled',
+                              'msg_body_edit_limit',
                               'expect_editing_to_succeed'], [
-        ({'sender_id': 2, 'timestamp': 45}, True, True, False),
-        ({'sender_id': 1, 'timestamp': 1}, True, False, True),
-        ({'sender_id': 1, 'timestamp': 45}, False, True, False),
-        ({'sender_id': 1, 'timestamp': 45}, True, True, True),
+        ({'sender_id': 2, 'timestamp': 45}, True, True, 60, False),
+        ({'sender_id': 1, 'timestamp': 1}, True, False, 60, True),
+        ({'sender_id': 1, 'timestamp': 45}, False, True, 60, False),
+        ({'sender_id': 1, 'timestamp': 45}, True, True, 60, True),
+        ({'sender_id': 1, 'timestamp': 1}, True, True, 0, True),
     ], ids=['msg_sent_by_other_user',
             'topic_edit_only_after_time_limit',
             'editing_not_allowed',
-            'all_conditions_met'])
+            'all_conditions_met',
+            'no_msg_body_edit_limit'])
     def test_keypress_EDIT_MESSAGE(self, mocker, message_fixture, widget_size,
                                    expect_editing_to_succeed,
                                    to_vary_in_each_message,
                                    realm_editing_allowed,
                                    msg_body_edit_enabled,
+                                   msg_body_edit_limit,
                                    key):
         varied_message = dict(message_fixture, **to_vary_in_each_message)
         msg_box = MessageBox(varied_message, self.model, message_fixture)
@@ -1922,7 +1926,7 @@ class TestMessageBox:
         msg_box.model.user_id = 1
         msg_box.model.initial_data = {
             'realm_allow_message_editing': realm_editing_allowed,
-            'realm_message_content_edit_limit_seconds': 60,
+            'realm_message_content_edit_limit_seconds': msg_body_edit_limit,
         }
         msg_box.model.client.get_raw_message.return_value = {
             'raw_content': "Edit this message"
@@ -1931,9 +1935,10 @@ class TestMessageBox:
         write_box.msg_edit_id = None
         write_box.msg_body_edit_enabled = None
         mocker.patch("zulipterminal.ui_tools.boxes.time", return_value=100)
-        # private messages cannot be edited after time-limit.
+        # private messages cannot be edited after time-limit, if there is one.
         if (varied_message['type'] == 'private'
-                and varied_message['timestamp'] == 1):
+                and varied_message['timestamp'] == 1
+                and msg_body_edit_limit > 0):
             expect_editing_to_succeed = False
 
         msg_box.keypress(size, key)
diff --git a/zulipterminal/ui_tools/boxes.py b/zulipterminal/ui_tools/boxes.py
index e71a581..bb16aa9 100644
--- a/zulipterminal/ui_tools/boxes.py
+++ b/zulipterminal/ui_tools/boxes.py
@@ -1518,23 +1518,26 @@ class MessageBox(urwid.Pile):
                     " Editing sent message is disabled.", 3)
                 return key
             # Check if message is still editable, i.e. within
-            # the time limit.
-            time_since_msg_sent = time() - self.message['timestamp']
-            edit_time_limit = self.model.initial_data[
-                    'realm_message_content_edit_limit_seconds']
+            # the time limit. A limit of 0 signifies no limit
+            # on message body editing.
             msg_body_edit_enabled = True
-            if time_since_msg_sent >= edit_time_limit:
-                if self.message['type'] == 'private':
-                    self.model.controller.view.set_footer_text(
-                            " Time Limit for editing the message has"
-                            " been exceeded.", 3)
-                    return key
-                elif self.message['type'] == 'stream':
-                    self.model.controller.view.set_footer_text(
-                            " Only topic editing allowed."
-                            " Time Limit for editing the message body has"
-                            " been exceeded.", 3)
-                    msg_body_edit_enabled = False
+            if self.model.initial_data[
+                    'realm_message_content_edit_limit_seconds'] > 0:
+                time_since_msg_sent = time() - self.message['timestamp']
+                edit_time_limit = self.model.initial_data[
+                        'realm_message_content_edit_limit_seconds']
+                if time_since_msg_sent >= edit_time_limit:
+                    if self.message['type'] == 'private':
+                        self.model.controller.view.set_footer_text(
+                                " Time Limit for editing the message has"
+                                " been exceeded.", 3)
+                        return key
+                    elif self.message['type'] == 'stream':
+                        self.model.controller.view.set_footer_text(
+                                " Only topic editing allowed."
+                                " Time Limit for editing the message body has"
+                                " been exceeded.", 3)
+                        msg_body_edit_enabled = False
 
             if self.message['type'] == 'private':
                 self.keypress(size, 'enter')