Przeglądaj źródła

Fix typing indicator on focus loss (#992)

Sends stopTyping message if window loses focus.

Fixes #924

Co-authored-by: Danilo Bargen <danilo.bargen@threema.ch>
Dennis Heer 5 lat temu
rodzic
commit
995cbf4165
1 zmienionych plików z 13 dodań i 6 usunięć
  1. 13 6
      src/directives/compose_area.ts

+ 13 - 6
src/directives/compose_area.ts

@@ -721,18 +721,25 @@ export default [
 
                 updateView();
 
-                // Listen to broadcasts
+                // Callbacks to unsubscribe listeners in $destroy
                 const unsubscribeListeners = [];
+
+                // Send "stop typing" message when switching tab or window
+                const stopTypingOnBlur = () => stopTyping();
+                window.addEventListener('blur', stopTypingOnBlur);
+                unsubscribeListeners.push(() => window.removeEventListener('blur', stopTypingOnBlur));
+
+                // Listen to broadcasts
                 unsubscribeListeners.push($rootScope.$on('onQuoted', (event: ng.IAngularEvent, args: any) => {
                     composeArea.focus();
                 }));
 
-                // When switching chat, send stopTyping message
+                // When closing the chat view...
                 scope.$on('$destroy', () => {
-                    unsubscribeListeners.forEach((u) => {
-                        // Unsubscribe
-                        u();
-                    });
+                    // ...unsubscribe listeners...
+                    unsubscribeListeners.forEach((u) => u());
+
+                    // ...and send "stop typing" message.
                     stopTyping();
                 });
             },