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

Add type parameter to ControllerModel

Danilo Bargen 7 éve
szülő
commit
9460131c54

+ 1 - 1
src/controller_model/contact.ts

@@ -21,7 +21,7 @@ import {AvatarControllerModel} from './avatar';
 // Type aliases
 import ControllerModelMode = threema.ControllerModelMode;
 
-export class ContactControllerModel implements threema.ControllerModel {
+export class ContactControllerModel implements threema.ControllerModel<threema.ContactReceiver> {
 
     // Angular services
     private $log: ng.ILogService;

+ 1 - 1
src/controller_model/distributionList.ts

@@ -20,7 +20,7 @@ import {WebClientService} from '../services/webclient';
 // Type aliases
 import ControllerModelMode = threema.ControllerModelMode;
 
-export class DistributionListControllerModel implements threema.ControllerModel {
+export class DistributionListControllerModel implements threema.ControllerModel<threema.DistributionListReceiver> {
 
     private $log: ng.ILogService;
     private $translate: ng.translate.ITranslateService;

+ 1 - 1
src/controller_model/group.ts

@@ -21,7 +21,7 @@ import {AvatarControllerModel} from './avatar';
 // Type aliases
 import ControllerModelMode = threema.ControllerModelMode;
 
-export class GroupControllerModel implements threema.ControllerModel {
+export class GroupControllerModel implements threema.ControllerModel<threema.GroupReceiver> {
 
     private $log: ng.ILogService;
     private $translate: ng.translate.ITranslateService;

+ 2 - 2
src/controller_model/me.ts

@@ -20,7 +20,7 @@ import {AvatarControllerModel} from './avatar';
 
 import ControllerModelMode = threema.ControllerModelMode;
 
-export class MeControllerModel implements threema.ControllerModel {
+export class MeControllerModel implements threema.ControllerModel<threema.MeReceiver> {
     private logTag: string = '[MeControllerModel]';
 
     // Angular services
@@ -164,7 +164,7 @@ export class MeControllerModel implements threema.ControllerModel {
     /**
      * Save the changes, return a promise with the receiver.
      */
-    public save(): Promise<threema.ContactReceiver> {
+    public save(): Promise<threema.MeReceiver> {
         /*
         switch (this.getMode()) {
             case ControllerModelMode.EDIT:

+ 4 - 4
src/partials/messenger.ts

@@ -195,7 +195,7 @@ class ConversationController {
     private $mdToast: ng.material.IToastService;
 
     // Controller model
-    private controllerModel: threema.ControllerModel;
+    private controllerModel: threema.ControllerModel<threema.Receiver>;
 
     // DOM Elements
     private domChatElement: HTMLElement;
@@ -1084,7 +1084,7 @@ class ReceiverDetailController {
     private isWorkReceiver = false;
     private showBlocked = () => false;
 
-    private controllerModel: threema.ControllerModel;
+    private controllerModel: threema.ControllerModel<threema.Receiver>;
 
     public static $inject = [
         '$log', '$stateParams', '$state', '$mdDialog', '$translate',
@@ -1246,7 +1246,7 @@ class ReceiverEditController {
     private execute: ExecuteService;
     public loading = false;
 
-    private controllerModel: threema.ControllerModel;
+    private controllerModel: threema.ControllerModel<threema.Receiver>;
     public type: string;
 
     public static $inject = [
@@ -1358,7 +1358,7 @@ class ReceiverCreateController {
     public type: string;
     private execute: ExecuteService;
 
-    public controllerModel: threema.ControllerModel;
+    public controllerModel: threema.ControllerModel<threema.Receiver>;
 
     public static $inject = ['$stateParams', '$mdDialog', '$mdToast', '$translate',
         '$timeout', '$state', '$log', 'ControllerModelService'];

+ 16 - 5
src/services/controller_model.ts

@@ -42,7 +42,10 @@ export class ControllerModelService {
         this.webClientService = webClientService;
     }
 
-    public me(receiver: threema.MeReceiver, mode: ControllerModelMode): threema.ControllerModel {
+    public me(
+        receiver: threema.MeReceiver,
+        mode: ControllerModelMode,
+    ): threema.ControllerModel<threema.MeReceiver> {
         return new MeControllerModel(
             this.$log,
             this.$translate,
@@ -53,7 +56,10 @@ export class ControllerModelService {
         );
     }
 
-    public contact(receiver: threema.ContactReceiver, mode: ControllerModelMode): threema.ControllerModel {
+    public contact(
+        receiver: threema.ContactReceiver,
+        mode: ControllerModelMode,
+    ): threema.ControllerModel<threema.ContactReceiver> {
         return new ContactControllerModel(
             this.$log,
             this.$translate,
@@ -64,7 +70,10 @@ export class ControllerModelService {
         );
     }
 
-    public group(receiver: threema.GroupReceiver, mode: ControllerModelMode): threema.ControllerModel {
+    public group(
+        receiver: threema.GroupReceiver,
+        mode: ControllerModelMode,
+    ): threema.ControllerModel<threema.GroupReceiver> {
         return new GroupControllerModel(
             this.$log,
             this.$translate,
@@ -75,8 +84,10 @@ export class ControllerModelService {
         );
     }
 
-    public distributionList(receiver: threema.DistributionListReceiver,
-                            mode: ControllerModelMode): threema.ControllerModel {
+    public distributionList(
+        receiver: threema.DistributionListReceiver,
+        mode: ControllerModelMode,
+    ): threema.ControllerModel<threema.DistributionListReceiver> {
         return new DistributionListControllerModel(
             this.$log,
             this.$translate,

+ 2 - 2
src/threema.d.ts

@@ -447,7 +447,7 @@ declare namespace threema {
         CHAT = 'chat',
     }
 
-    interface ControllerModel {
+    interface ControllerModel<T extends BaseReceiver> {
         /**
          * The title shown in the header.
          */
@@ -461,7 +461,7 @@ declare namespace threema {
         /**
          * Save the changes, return a promise with the receiver.
          */
-        save(): Promise<Receiver>;
+        save(): Promise<T>;
 
         /**
          * Delete all messages in this conversation.