Skip to content

Commit

Permalink
bugfix: boxes: Send typing 'stop' event only after prior 'start' event.
Browse files Browse the repository at this point in the history
This commit adds an extra check before sending typing 'stop' events
through the 'sent_start_typing_status' boolean which indicates whether a
'start' event has already been sent. This avoids sending unnecessary
'stop' events.

Test updated.
  • Loading branch information
prah23 authored and neiljp committed Jul 10, 2021
1 parent 8cd7940 commit 9edc43e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/ui_tools/test_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_init(self, write_box):
assert write_box.model == self.view.model
assert write_box.view == self.view
assert write_box.msg_edit_state is None
assert not write_box.sent_start_typing_status

def test_not_calling_typing_method_without_recipients(self, mocker, write_box):
write_box.model.send_typing_status_by_user_ids = mocker.Mock()
Expand Down
12 changes: 10 additions & 2 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(self, view: Any) -> None:
self.send_next_typing_update = datetime.now()
self.last_key_update = datetime.now()
self.idle_status_tracking = False
self.sent_start_typing_status = False

# Constant indices into self.contents
# (CONTAINER=vertical, HEADER/MESSAGE=horizontal)
Expand All @@ -114,13 +115,19 @@ def set_editor_mode(self) -> None:
self.view.controller.enter_editor_mode_with(self)

def send_stop_typing_status(self) -> None:
# Send 'stop' updates only for PM narrows.
if self.to_write_box and self.recipient_user_ids:
# Send 'stop' updates only for PM narrows, when there are recipients
# to send to and a prior 'start' status has already been sent.
if (
self.to_write_box
and self.recipient_user_ids
and self.sent_start_typing_status
):
self.model.send_typing_status_by_user_ids(
self.recipient_user_ids, status="stop"
)
self.send_next_typing_update = datetime.now()
self.idle_status_tracking = False
self.sent_start_typing_status = False

def private_box_view(
self,
Expand Down Expand Up @@ -202,6 +209,7 @@ def on_type_send_status(edit: object, new_edit_text: str) -> None:
self.recipient_user_ids, status="start"
)
self.send_next_typing_update += start_period_delta
self.sent_start_typing_status = True
# Initiate tracker function only if it isn't already
# initiated.
if not self.idle_status_tracking:
Expand Down

0 comments on commit 9edc43e

Please sign in to comment.