Forráskód Böngészése

Revert "Receiver editing: Only send avatar if changed" (#253)

This reverts commit 27a4024e937950b77a9a76aaafe5a0e0811fa5f4.

Will be re-merged later on, after the next release, since it needs a
protocol version update.
Danilo Bargen 8 éve
szülő
commit
b4747ed8b7

+ 1 - 17
src/controller_model/avatar.ts

@@ -21,8 +21,7 @@ export class AvatarControllerModel {
     private $log: ng.ILogService;
     private avatar: ArrayBuffer = null;
     private loadAvatar: Promise<string>;
-    private onChangeAvatar: (image: ArrayBuffer) => void;
-    private _avatarChanged: boolean = false;
+    public onChangeAvatar: (image: ArrayBuffer) => void;
 
     constructor($log: ng.ILogService,
                 webClientService: WebClientService,
@@ -45,25 +44,10 @@ export class AvatarControllerModel {
         // bind to the editor
         this.onChangeAvatar = (image: ArrayBuffer) => {
             this.avatar = image;
-            this._avatarChanged = true;
         };
     }
 
-    /**
-     * Return the avatar bytes (or null if no avatar is defined).
-     */
     public getAvatar(): ArrayBuffer | null {
         return this.avatar;
     }
-
-    /**
-     * Return whether this avatar was changed.
-     *
-     * This will return true if an avatar was added or removed. It does not
-     * actually look at the content to determine whether the bytes of the
-     * avatar really changed.
-     */
-    public get avatarChanged(): boolean {
-        return this._avatarChanged;
-    }
 }

+ 1 - 1
src/controller_model/contact.ts

@@ -118,7 +118,7 @@ export class ContactControllerModel implements threema.ControllerModel {
                     this.contact.id,
                     this.firstName,
                     this.lastName,
-                    this.avatarController.avatarChanged ? this.avatarController.getAvatar() : undefined,
+                    this.avatarController.getAvatar(),
                 );
             case ControllerModelMode.NEW:
                 return this.webClientService.addContact(this.identity);

+ 2 - 1
src/controller_model/group.ts

@@ -199,9 +199,10 @@ export class GroupControllerModel implements threema.ControllerModel {
                     this.group.id,
                     this.members,
                     this.name,
-                    this.avatarController.avatarChanged ? this.avatarController.getAvatar() : undefined,
+                    this.avatarController.getAvatar(),
                 );
             case ControllerModelMode.NEW:
+
                 return this.webClientService.createGroup(
                     this.members,
                     this.name,

+ 6 - 6
src/partials/welcome.ts

@@ -57,7 +57,7 @@ class WelcomeController {
 
     // Custom services
     private webClientService: WebClientService;
-    private trustedKeyStore: TrustedKeyStoreService;
+    private TrustedKeyStore: TrustedKeyStoreService;
     private pushService: PushService;
     private stateService: StateService;
 
@@ -76,7 +76,7 @@ class WelcomeController {
                 $timeout: ng.ITimeoutService, $interval: ng.IIntervalService,
                 $log: ng.ILogService, $window: ng.IWindowService, $mdDialog: ng.material.IDialogService,
                 $translate: ng.translate.ITranslateService,
-                webClientService: WebClientService, trustedKeyStore: TrustedKeyStoreService,
+                webClientService: WebClientService, TrustedKeyStore: TrustedKeyStoreService,
                 stateService: StateService, pushService: PushService,
                 browserService: BrowserService,
                 versionService: VersionService,
@@ -95,7 +95,7 @@ class WelcomeController {
 
         // Own services
         this.webClientService = webClientService;
-        this.trustedKeyStore = trustedKeyStore;
+        this.TrustedKeyStore = TrustedKeyStore;
         this.stateService = stateService;
         this.pushService = pushService;
 
@@ -127,7 +127,7 @@ class WelcomeController {
         }
 
         // Determine whether local storage is available
-        if (this.trustedKeyStore.blocked === true) {
+        if (this.TrustedKeyStore.blocked === true) {
             $log.error('Cannot access local storage. Is it being blocked by a browser add-on?');
             this.showLocalStorageWarning();
         }
@@ -144,7 +144,7 @@ class WelcomeController {
             const keyStore = $stateParams.initParams.keyStore;
             const peerTrustedKey = $stateParams.initParams.peerTrustedKey;
             this.reconnect(keyStore, peerTrustedKey);
-        } else if (trustedKeyStore.hasTrustedKey()) {
+        } else if (TrustedKeyStore.hasTrustedKey()) {
             this.mode = 'unlock';
             this.unlock();
         } else {
@@ -225,7 +225,7 @@ class WelcomeController {
      * Decrypt the keys and initiate the session.
      */
     private unlockConfirm(): void {
-        const decrypted: threema.TrustedKeyStoreData = this.trustedKeyStore.retrieveTrustedKey(this.password);
+        const decrypted: threema.TrustedKeyStoreData = this.TrustedKeyStore.retrieveTrustedKey(this.password);
         if (decrypted === null) {
             return this.showDecryptionFailed();
         }

+ 35 - 51
src/services/webclient.ts

@@ -103,7 +103,6 @@ export class WebClientService {
     private static ARGUMENT_RECEIVER_ID = 'id';
     private static ARGUMENT_TEMPORARY_ID = 'temporaryId';
     private static ARGUMENT_REFERENCE_MSG_ID = 'refMsgId';
-    private static ARGUMENT_AVATAR = 'avatar';
     private static ARGUMENT_AVATAR_HIGH_RESOLUTION = 'highResolution';
     private static ARGUMENT_CONTACT_IS_TYPING = 'isTyping';
     private static ARGUMENT_MESSAGE_ID = 'messageId';
@@ -220,7 +219,7 @@ export class WebClientService {
                 qrCodeService: QrCodeService,
                 mimeService: MimeService,
                 receiverService: ReceiverService,
-                versionService: VersionService,
+                VersionService: VersionService,
                 CONFIG: threema.Config) {
 
         // Angular services
@@ -243,7 +242,7 @@ export class WebClientService {
         this.qrCodeService = qrCodeService;
         this.mimeService = mimeService;
         this.receiverService = receiverService;
-        this.versionService = versionService;
+        this.versionService = VersionService;
 
         // Configuration object
         this.config = CONFIG;
@@ -1055,7 +1054,7 @@ export class WebClientService {
     /**
      * Send a add Contact request
      */
-    public addContact(threemaId: string): Promise<threema.ContactReceiver> {
+    public addContact(threemaId: String): Promise<threema.ContactReceiver> {
         return this._sendCreatePromise(WebClientService.SUB_TYPE_CONTACT, {
             [WebClientService.ARGUMENT_IDENTITY]: threemaId,
         });
@@ -1064,52 +1063,38 @@ export class WebClientService {
     /**
      * Modify a contact name or a avatar
      */
-    public modifyContact(threemaId: string,
-                         firstName?: string,
-                         lastName?: string,
+    public modifyContact(threemaId: String,
+                         firstName: String,
+                         lastName: String,
                          avatar?: ArrayBuffer): Promise<threema.ContactReceiver> {
-        // Prepare payload data
-        const data = {};
-        if (firstName !== undefined) {
-            data[WebClientService.ARGUMENT_FIRST_NAME] = firstName;
-        }
-        if (lastName !== undefined) {
-            data[WebClientService.ARGUMENT_LAST_NAME] = lastName;
-        }
-        if (avatar !== undefined) {
-            data[WebClientService.ARGUMENT_AVATAR] = avatar;
-        }
-
-        // If no changes happened, resolve the promise immediately.
-        if (Object.keys(data).length === 0) {
-            this.$log.warn(this.logTag, 'Trying to modify contact without any changes');
-            return Promise.resolve(this.contacts.get(threemaId));
-        }
-
-        // Send update
-        const args = {
+        let promise = this._sendUpdatePromise(WebClientService.SUB_TYPE_CONTACT, {
             [WebClientService.ARGUMENT_IDENTITY]: threemaId,
-        };
-        const promise = this._sendUpdatePromise(WebClientService.SUB_TYPE_CONTACT, args, data);
+        }, {
+            [WebClientService.ARGUMENT_FIRST_NAME]: firstName,
+            [WebClientService.ARGUMENT_LAST_NAME]: lastName,
+            [WebClientService.ARGUMENT_AVATAR_HIGH_RESOLUTION]: avatar,
+        });
 
-        // If necessary, reset avatar to force a avatar reload
         if (avatar !== undefined) {
-            this.contacts.get(threemaId).avatar = {};
+            // reset avatar to force a avatar reload
+            this.receivers.getData({
+                type: 'contact',
+                id: threemaId,
+            } as threema.Receiver).avatar = {};
         }
-
         return promise;
     }
 
     /**
      * Create a group receiver
      */
-    public createGroup(members: string[],
-                       name: string = null,
+    public createGroup(members: String[],
+                       name: String = null,
                        avatar?: ArrayBuffer): Promise<threema.GroupReceiver> {
-        const data = {
+        let data = {
             [WebClientService.ARGUMENT_MEMBERS]: members,
             [WebClientService.ARGUMENT_NAME]: name,
-        } as Object;
+        } as any;
 
         if (avatar !== undefined) {
             data[WebClientService.ARGUMENT_AVATAR_HIGH_RESOLUTION] = avatar;
@@ -1120,27 +1105,26 @@ export class WebClientService {
 
     public modifyGroup(id: string,
                        members: String[],
-                       name?: String,
+                       name: String = null,
                        avatar?: ArrayBuffer): Promise<threema.GroupReceiver> {
-        // Prepare payload data
-        const data = {};
-        data[WebClientService.ARGUMENT_MEMBERS] = members;
-        if (name !== undefined) {
-            data[WebClientService.ARGUMENT_NAME] = name;
-        }
+        let data = {
+            [WebClientService.ARGUMENT_MEMBERS]: members,
+            [WebClientService.ARGUMENT_NAME]: name,
+        } as any;
+
         if (avatar !== undefined) {
-            data[WebClientService.ARGUMENT_AVATAR] = avatar;
+            data[WebClientService.ARGUMENT_AVATAR_HIGH_RESOLUTION] = avatar;
         }
-
-        // Send update
-        const args = {
+        let promise = this._sendUpdatePromise(WebClientService.SUB_TYPE_GROUP, {
             [WebClientService.ARGUMENT_RECEIVER_ID]: id,
-        };
-        let promise = this._sendUpdatePromise(WebClientService.SUB_TYPE_GROUP, args, data);
+        }, data);
 
-        // If necessary, reset avatar to force a avatar reload
         if (avatar !== undefined) {
-            this.groups.get(id).avatar = {};
+            // reset avatar to force a avatar reload
+            this.receivers.getData({
+                type: 'group',
+                id: id,
+            } as threema.GroupReceiver).avatar = {};
         }
         return promise;
     }

+ 1 - 2
tslint.json

@@ -11,7 +11,6 @@
         "only-arrow-functions": false,
         "quotemark": [true, "single", "avoid-escape"],
         "indent": [true, "spaces"],
-        "whitespace": [true, "check-branch", "check-decl", "check-operator", "check-module", "check-separator", "check-type", "check-typecast", "check-preblock"],
-        "variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore", "allow-pascal-case"]
+        "whitespace": [true, "check-branch", "check-decl", "check-operator", "check-module", "check-separator", "check-type", "check-typecast", "check-preblock"]
     }
 }