From 07322d78a06ff36044b406578b98265a2e4b55dd Mon Sep 17 00:00:00 2001 From: Greg Price Date: Mon, 21 Oct 2019 13:41:26 -0700 Subject: [PATCH] typing_status: Pull is_valid_conversation call up to top. This is intended as a pure refactor, making the data flow clearer in preparation for further changes. In particular, this makes it manifest that the calls to `get_recipient` and `is_valid_conversation` don't depend on anything else that has happened during the call to `handle_text_input`. This is indeed a pure refactor because * is_valid_conversation itself has no side effects, either in the implementation in typing.js or in any reasonable implementation, so calling it sooner doesn't affect anything else; * if we do reach it, the only potentially-side-effecting code it's moving before is a call to `stop_last_notification`, and that in turn (with the existing, or any reasonable, implementation of `notify_server_stop`) has no effect on the data consulted by the implementation of `is_valid_conversation`. --- static/shared/js/typing_status.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/static/shared/js/typing_status.js b/static/shared/js/typing_status.js index d9f3cb1dab..81466e0ca0 100644 --- a/static/shared/js/typing_status.js +++ b/static/shared/js/typing_status.js @@ -89,8 +89,9 @@ export function maybe_ping_server(worker, recipient) { export function handle_text_input(worker) { var new_recipient = worker.get_recipient(); - var current_recipient = state.current_recipient; + var conversation_is_valid = worker.is_valid_conversation(new_recipient); + var current_recipient = state.current_recipient; if (current_recipient) { // We need to use _.isEqual for comparisons; === doesn't work // on arrays. @@ -111,7 +112,7 @@ export function handle_text_input(worker) { stop_last_notification(worker); } - if (!worker.is_valid_conversation(new_recipient)) { + if (!conversation_is_valid) { // If we are not talking to somebody we care about, // then there is no more action to take. return;