Răsfoiți Sursa

Add controller model to conversation controller

Danilo Bargen 8 ani în urmă
părinte
comite
d20f99b627

+ 1 - 0
src/controller_model/contact.ts

@@ -69,6 +69,7 @@ export class ContactControllerModel implements threema.ControllerModel {
                 break;
 
             case ControllerModelMode.VIEW:
+            case ControllerModelMode.CHAT:
                 this.subject = this.contact.displayName;
                 this.access = this.contact.access;
                 break;

+ 1 - 0
src/controller_model/distributionList.ts

@@ -57,6 +57,7 @@ export class DistributionListControllerModel implements threema.ControllerModel
                 break;
 
             case ControllerModelMode.VIEW:
+            case ControllerModelMode.CHAT:
                 this.subject = this.distributionList.displayName;
                 this.members = this.distributionList.members;
                 break;

+ 1 - 0
src/controller_model/group.ts

@@ -62,6 +62,7 @@ export class GroupControllerModel implements threema.ControllerModel {
                 break;
 
             case ControllerModelMode.VIEW:
+            case ControllerModelMode.CHAT:
                 this.subject = this.group.displayName;
                 this.members = this.group.members;
                 break;

+ 37 - 8
src/partials/messenger.ts

@@ -158,6 +158,7 @@ class SettingsController {
 
 class ConversationController {
     public name = 'navigation';
+    private logTag: string = '[ConversationController]';
 
     // Angular services
     private $stateParams;
@@ -176,6 +177,9 @@ class ConversationController {
     private $mdDialog: ng.material.IDialogService;
     private $mdToast: ng.material.IToastService;
 
+    // Controller model
+    private controllerModel: threema.ControllerModel;
+
     // DOM Elements
     private domChatElement: HTMLElement;
 
@@ -210,6 +214,7 @@ class ConversationController {
         '$stateParams', '$state', '$timeout', '$log', '$scope', '$rootScope',
         '$mdDialog', '$mdToast', '$location', '$translate',
         'WebClientService', 'StateService', 'ReceiverService', 'MimeService', 'VersionService',
+        'ControllerModelService',
     ];
     constructor($stateParams: threema.ConversationStateParams,
                 $state: ng.ui.IStateService,
@@ -225,7 +230,8 @@ class ConversationController {
                 stateService: StateService,
                 receiverService: ReceiverService,
                 mimeService: MimeService,
-                versionService: VersionService) {
+                versionService: VersionService,
+                controllerModelService: ControllerModelService) {
         this.$stateParams = $stateParams;
         this.$timeout = $timeout;
         this.$log = $log;
@@ -244,13 +250,6 @@ class ConversationController {
         // Close any showing dialogs
         this.$mdDialog.cancel();
 
-        // Check if this is our own contact
-        if (this.webClientService.me.id === $stateParams.id) {
-            $log.warn('ConversationController: Cannot show own contact, redirecting to home');
-            $state.go('messenger.home');
-            return;
-        }
-
         this.maxTextLength = this.webClientService.getMaxTextLength();
 
         // On every navigation event, close all dialogs.
@@ -289,6 +288,36 @@ class ConversationController {
                 this.receiver.type = this.type;
             }
 
+            // Initialize controller model
+            const mode = ControllerModelMode.CHAT;
+            switch (this.receiver.type) {
+                case 'me':
+                case 'contact':
+                    this.controllerModel = controllerModelService.contact(
+                        this.receiver as threema.ContactReceiver, mode);
+                    break;
+                case 'group':
+                    this.controllerModel = controllerModelService.group(
+                        this.receiver as threema.GroupReceiver, mode);
+                    break;
+                case 'distributionList':
+                    this.controllerModel = controllerModelService.distributionList(
+                        this.receiver as threema.DistributionListReceiver, mode);
+                    break;
+                default:
+                    $log.error(this.logTag, 'Cannot initialize controller model:',
+                        'Invalid receiver type "' + this.receiver.type + '"');
+                    $state.go('welcome');
+                    return;
+            }
+
+            // Check if this receiver may be viewed
+            if (this.controllerModel.canView() === false) {
+                $log.warn(this.logTag, 'Cannot view this receiver, redirecting to home');
+                $state.go('messenger.home');
+                return;
+            }
+
             // initial set locked state
             this.locked = this.receiver.locked;
 

+ 1 - 0
src/types/enums.ts

@@ -19,4 +19,5 @@ export enum ControllerModelMode {
     NEW = 1,
     VIEW = 2,
     EDIT = 3,
+    CHAT = 4,
 }