Sfoglia il codice sorgente

Update push handling

Fix push in case there are chunks pending that require immediate handling after the connection has been closed
Remove wakeup type from PushService.sendPush (obsoleted by connectionInfo)
Lennart Grahl 7 anni fa
parent
commit
e9a0e36465
3 ha cambiato i file con 27 aggiunte e 11 eliminazioni
  1. 5 2
      src/controllers/status.ts
  2. 3 2
      src/services/push.ts
  3. 19 7
      src/services/webclient.ts

+ 5 - 2
src/controllers/status.ts

@@ -29,7 +29,7 @@ import DisconnectReason = threema.DisconnectReason;
  *
  * It also controls auto-reconnecting and the connection status indicator bar.
  *
- * Status updates should be done through the status service.
+ * Status updates should be done through the state service.
  */
 export class StatusController {
 
@@ -275,9 +275,12 @@ export class StatusController {
             this.$state.go('welcome');
         };
 
+        // Only send a push if never left the 'welcome' page or if there are
+        // one or more cached chunks that require immediate sending.
+        const skipPush = !this.$state.includes('welcome') && !this.webClientService.immediateChunksPending;
+
         // Delay connecting a bit to wait for old websocket to close
         // TODO: Make this more robust and hopefully faster
-        const skipPush = !this.$state.includes('welcome');
         const startTimeout = 500;
         this.$log.debug(this.logTag, 'Stopping old connection');
         this.webClientService.stop({

+ 3 - 2
src/services/push.ts

@@ -74,7 +74,7 @@ export class PushService {
      * Send a push notification for the specified session (public permanent key
      * of the initiator). The promise is always resolved to a boolean.
      */
-    public async sendPush(session: Uint8Array, wakeupType: threema.WakeupType): Promise<boolean> {
+    public async sendPush(session: Uint8Array): Promise<boolean> {
         if (!this.isAvailable()) {
             return false;
         }
@@ -87,7 +87,8 @@ export class PushService {
             [PushService.ARG_TYPE]: this.pushType,
             [PushService.ARG_SESSION]: sessionHash,
             [PushService.ARG_VERSION]: this.version,
-            [PushService.ARG_WAKEUP_TYPE]: wakeupType,
+            // Note: Wakeup type has been obsoleted by connectionInfo
+            [PushService.ARG_WAKEUP_TYPE]: '0',
         };
         if (this.pushType === threema.PushTokenType.Apns) {
             // APNS token format: "<hex-deviceid>;<endpoint>;<bundle-id>"

+ 19 - 7
src/services/webclient.ts

@@ -338,6 +338,17 @@ export class WebClientService {
     get typing(): threema.Container.Typing {
         return this.typingInstance;
     }
+
+    /**
+     * Return whether there are chunks cached from a previous connection that
+     * require immediate sending.
+     */
+    get immediateChunksPending(): boolean {
+        // TODO: Apply the chunk **push** blacklist instead of the chunk cache
+        //       blacklist!
+        return this.previousChunkCache !== null && this.previousChunkCache.chunks.length > 0;
+    }
+
     /**
      * Return QR code payload.
      */
@@ -926,7 +937,7 @@ export class WebClientService {
      * Send a push message to wake up the peer.
      * The push message will only be sent if the last push is less than 2 seconds ago.
      */
-    private sendPush(wakeupType: threema.WakeupType): void {
+    private sendPush(): void {
         // Make sure not to flood the target device with pushes
         const minPushInterval = 2000;
         const now = new Date();
@@ -938,11 +949,10 @@ export class WebClientService {
         this.lastPush = now;
 
         // Actually send the push notification
-        this.pushService.sendPush(this.salty.permanentKeyBytes, wakeupType)
+        this.pushService.sendPush(this.salty.permanentKeyBytes)
             .catch(() => this.$log.warn(this.logTag, 'Could not notify app!'))
             .then(() => {
-                const wakeupTypeString = wakeupType === threema.WakeupType.FullReconnect ? 'reconnect' : 'wakeup';
-                this.$log.debug(this.logTag, 'Requested app', wakeupTypeString, 'via', this.pushTokenType, 'push');
+                this.$log.debug(this.logTag, 'Requested app wakeup via', this.pushTokenType, 'push');
                 this.$rootScope.$apply(() => {
                     this.stateService.updateConnectionBuildupState('push');
                 });
@@ -967,7 +977,7 @@ export class WebClientService {
         if (skipPush === true) {
             this.$log.debug(this.logTag, 'start(): Skipping push notification');
         } else if (this.pushService.isAvailable()) {
-            this.sendPush(threema.WakeupType.FullReconnect);
+            this.sendPush();
         } else if (this.trustedKeyStore.hasTrustedKey()) {
             this.$log.debug(this.logTag, 'Push service not available');
             this.stateService.updateConnectionBuildupState('manual_start');
@@ -3523,8 +3533,10 @@ export class WebClientService {
         if (shouldQueue) {
             chunkCache = this.previousChunkCache;
             this.$log.debug(this.logTag, 'Currently not connected, queueing chunk');
-            if (this.pushService.isAvailable()) {
-                this.sendPush(threema.WakeupType.Wakeup);
+            if (retransmit && this.pushService.isAvailable()) {
+                // TODO: Apply the chunk **push** blacklist instead of the
+                //       retransmit flag!
+                this.sendPush();
             } else {
                 this.$log.warn(this.logTag, 'Push service not available, cannot wake up peer!');
             }