Sfoglia il codice sorgente

Bug fixes for the resume functionality

Fix don't resume if not on a child of the 'messenger' state
Fix don't resume if the client info has never been received
Fix reset the client info object if closing a session
Lennart Grahl 7 anni fa
parent
commit
725e9e5c65
2 ha cambiato i file con 11 aggiunte e 7 eliminazioni
  1. 4 4
      src/protocol/cache.ts
  2. 7 3
      src/services/webclient.ts

+ 4 - 4
src/protocol/cache.ts

@@ -87,15 +87,15 @@ export class ChunkCache {
 
         // Calculate the slice start index for the chunk cache
         // Important: Our sequence number is one chunk ahead!
-        const endOffset = theirSequenceNumber + 1 - this._sequenceNumber.get();
-        if (endOffset > 0) {
+        const beginOffset = theirSequenceNumber + 1 - this._sequenceNumber.get();
+        if (beginOffset > 0) {
             throw new Error('Remote travelled through time and acknowledged a chunk which is in the future');
-        } else if (-endOffset > this.cache.length) {
+        } else if (-beginOffset > this.cache.length) {
             throw new Error('Remote travelled back in time and acknowledged a chunk it has already acknowledged');
         }
 
         // Slice our cache & recalculate size
-        this.cache = endOffset === 0 ? [] : this.cache.slice(endOffset);
+        this.cache = beginOffset === 0 ? [] : this.cache.slice(beginOffset);
         this._byteLength = this.cache
             .filter((chunk) => chunk !== null)
             .reduce((sum, chunk) => sum + chunk.byteLength, 0);

+ 7 - 3
src/services/webclient.ts

@@ -216,7 +216,7 @@ export class WebClientService {
     private drafts: threema.Container.Drafts;
     private pcHelper: PeerConnectionHelper = null;
     private trustedKeyStore: TrustedKeyStoreService;
-    public clientInfo: threema.ClientInfo;
+    public clientInfo: threema.ClientInfo = null;
     public version = null;
     private batteryStatusTimeout: ng.IPromise<void> = null;
 
@@ -779,11 +779,14 @@ export class WebClientService {
 
         // Redirect to the conversation overview in case resuming was enabled
         // but the session could not be resumed
-        if (resumeSession && !sessionWasResumed) {
+        if (resumeSession && !sessionWasResumed && this.clientInfo !== null) {
             this.$rootScope.$apply(() => {
                 // TODO: Remove this conditional once we have session
                 //       resumption for Android!
-                if (this.chosenTask === threema.ChosenTask.RelayedData) {
+                if (this.chosenTask !== threema.ChosenTask.RelayedData) {
+                    return;
+                }
+                if (this.$state.includes('messenger')) {
                     this.$state.go('messenger.home');
                 }
             });
@@ -1015,6 +1018,7 @@ export class WebClientService {
 
         // Invalidate and clear caches
         if (close) {
+            this.clientInfo = null;
             this.previousConnectionId = null;
             this.currentConnectionId = null;
             this.previousIncomingChunkSequenceNumber = null;