ソースを参照

Clear all "isTyping" flags when connection is lost

Danilo Bargen 7 年 前
コミット
d55847fac0

+ 3 - 0
src/controllers/status.ts

@@ -109,6 +109,9 @@ export class StatusController {
                 if (oldValue === 'ok' && isWebrtc) {
                     this.scheduleStatusBar();
                 }
+                if (this.stateService.wasConnected) {
+                    this.webClientService.clearIsTypingFlags();
+                }
                 if (this.stateService.wasConnected && isRelayedData) {
                     this.reconnectIos();
                 }

+ 7 - 0
src/services/webclient.ts

@@ -3163,4 +3163,11 @@ export class WebClientService {
         };
         contacts.sort(compareFunc);
     }
+
+    /**
+     * Clear all "is typing" flags.
+     */
+    public clearIsTypingFlags(): void {
+        this.typing.clearAll();
+    }
 }

+ 1 - 0
src/threema.d.ts

@@ -822,6 +822,7 @@ declare namespace threema {
         interface Typing {
             setTyping(receiver: ContactReceiver): void;
             unsetTyping(receiver: ContactReceiver): void;
+            clearAll(): void;
             isTyping(receiver: ContactReceiver): boolean;
         }
 

+ 14 - 2
src/threema/container.ts

@@ -31,7 +31,7 @@ type MessageConverter = (data: threema.Message) => threema.Message;
  *
  * Only strings can be stored in this set.
  */
-class StringHashSet {
+export class StringHashSet {
     private setObj = {};
     private val = {};
 
@@ -47,7 +47,7 @@ class StringHashSet {
         delete this.setObj[str];
     }
 
-    public values() {
+    public values(): string[] {
         const values = [];
         for (const i in this.setObj) {
             if (this.setObj[i] === this.val) {
@@ -56,6 +56,14 @@ class StringHashSet {
         }
         return values;
     }
+
+    public clearAll(): void {
+        for (const element in this.setObj) {
+            if (this.setObj.hasOwnProperty(element)) {
+                this.remove(element);
+            }
+        }
+    }
 }
 
 /**
@@ -728,6 +736,10 @@ class Typing implements threema.Container.Typing {
         this.set.remove(this.getReceiverUid(receiver));
     }
 
+    public clearAll(): void {
+        this.set.clearAll();
+    }
+
     public isTyping(receiver: threema.ContactReceiver): boolean {
         return this.set.contains(this.getReceiverUid(receiver));
     }

+ 13 - 1
tests/ts/containers.ts

@@ -21,7 +21,7 @@
 /// <reference path="../../src/threema.d.ts" />
 
 import {ReceiverService} from '../../src/services/receiver';
-import {Conversations} from '../../src/threema/container';
+import {Conversations, StringHashSet} from '../../src/threema/container';
 
 function getConversations(): Conversations {
     const receiverService = new ReceiverService();
@@ -140,4 +140,16 @@ describe('Container', () => {
         });
     });
 
+    describe('StringHashSet', () => {
+        it('clearAll', function() {
+            const shs = new StringHashSet();
+            shs.add('hello');
+            shs.add('hello');
+            shs.add('bye');
+            expect(shs.values()).toEqual(['hello', 'bye']);
+            shs.clearAll();
+            expect(shs.values()).toEqual([]);
+        });
+    });
+
 });