Просмотр исходного кода

Support different wakeup types in push notification

Danilo Bargen 7 лет назад
Родитель
Сommit
f854953b5f
3 измененных файлов с 16 добавлено и 6 удалено
  1. 3 1
      src/services/push.ts
  2. 6 5
      src/services/webclient.ts
  3. 7 0
      src/threema.d.ts

+ 3 - 1
src/services/push.ts

@@ -20,6 +20,7 @@ export class PushService {
     private static ARG_TOKEN = 'token';
     private static ARG_SESSION = 'session';
     private static ARG_VERSION = 'version';
+    private static ARG_WAKEUP_TYPE = 'wakeup';
     private static ARG_ENDPOINT = 'endpoint';
     private static ARG_BUNDLE_ID = 'bundleid';
 
@@ -71,7 +72,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 sendPush(session: Uint8Array): Promise<boolean> {
+    public sendPush(session: Uint8Array, wakeupType: threema.WakeupType): Promise<boolean> {
         if (!this.isAvailable()) {
             return Promise.resolve(false);
         }
@@ -81,6 +82,7 @@ export class PushService {
             [PushService.ARG_TYPE]: this.pushType,
             [PushService.ARG_SESSION]: sha256(session),
             [PushService.ARG_VERSION]: this.version,
+            [PushService.ARG_WAKEUP_TYPE]: wakeupType,
         };
         if (this.pushType === threema.PushTokenType.Apns) {
             // APNS token format: "<hex-deviceid>;<endpoint>;<bundle-id>"

+ 6 - 5
src/services/webclient.ts

@@ -619,7 +619,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(): void {
+    private sendPush(wakeupType: threema.WakeupType): void {
         // Make sure not to flood the target device with pushes
         const minPushInterval = 2000;
         const now = new Date();
@@ -631,10 +631,11 @@ export class WebClientService {
         this.lastPush = now;
 
         // Actually send the push notification
-        this.pushService.sendPush(this.salty.permanentKeyBytes)
+        this.pushService.sendPush(this.salty.permanentKeyBytes, wakeupType)
             .catch(() => this.$log.warn(this.logTag, 'Could not notify app!'))
             .then(() => {
-                this.$log.debug(this.logTag, 'Requested app wakeup via', this.pushTokenType, 'push');
+                const wakeupTypeString = wakeupType === threema.WakeupType.FullReconnect ? 'reconnect' : 'wakeup';
+                this.$log.debug(this.logTag, 'Requested app', wakeupTypeString, 'via', this.pushTokenType, 'push');
                 this.$rootScope.$apply(() => {
                     this.stateService.updateConnectionBuildupState('push');
                 });
@@ -659,7 +660,7 @@ export class WebClientService {
         if (skipPush === true) {
             this.$log.debug(this.logTag, 'start(): Skipping push notification');
         } else if (this.pushService.isAvailable()) {
-            this.sendPush();
+            this.sendPush(threema.WakeupType.FullReconnect);
         } else if (this.trustedKeyStore.hasTrustedKey()) {
             this.$log.debug(this.logTag, 'Push service not available');
             this.stateService.updateConnectionBuildupState('manual_start');
@@ -2785,7 +2786,7 @@ export class WebClientService {
                         + this.salty.state + '), putting outgoing message in queue');
                     this.outgoingMessageQueue.push(message);
                     if (this.pushService.isAvailable()) {
-                        this.sendPush();
+                        this.sendPush(threema.WakeupType.Wakeup);
                     } else {
                         this.$log.warn(this.logTag, 'Push service not available, cannot wake up peer!');
                     }

+ 7 - 0
src/threema.d.ts

@@ -441,6 +441,13 @@ declare namespace threema {
         Apns = 'a',
     }
 
+    const enum WakeupType {
+        // A full reconnect (by entering the password on the main screen).
+        FullReconnect = '0',
+        // A wakeup, as implemented by the iOS app.
+        Wakeup = '1',
+    }
+
     interface TrustedKeyStoreData {
         ownPublicKey: Uint8Array;
         ownSecretKey: Uint8Array;