Bladeren bron

Merge pull request #754 from threema-ch/752-conversation-pin-icon

Only show pin/unpin button if conversation exists
Danilo Bargen 6 jaren geleden
bovenliggende
commit
d9e6182544
2 gewijzigde bestanden met toevoegingen van 18 en 2 verwijderingen
  1. 1 0
      src/partials/messenger.conversation.html
  2. 17 2
      src/partials/messenger.ts

+ 1 - 0
src/partials/messenger.conversation.html

@@ -29,6 +29,7 @@
         <div class="header-buttons">
             <toggle-button
                 flag="ctrl.conversation.isStarred"
+                ng-if="ctrl.conversation"
                 on-enable="ctrl.pinConversation()"
                 on-disable="ctrl.unpinConversation()"
                 label-enabled="messenger.PINNED_CONVERSATION"

+ 17 - 2
src/partials/messenger.ts

@@ -234,7 +234,7 @@ class ConversationController {
 
     // The conversation receiver
     public receiver: threema.Receiver;
-    public conversation: threema.Conversation;
+    public _conversation: threema.Conversation;  // Access through getter
     public type: threema.ReceiverType;
 
     // The conversation messages
@@ -347,7 +347,7 @@ class ConversationController {
         // Set receiver, conversation and type
         try {
             this.receiver = webClientService.receivers.getData({type: $stateParams.type, id: $stateParams.id});
-            this.conversation = this.webClientService.conversations.find(this.receiver);
+            this._conversation = this.webClientService.conversations.find(this.receiver);
             this.type = $stateParams.type;
 
             if (this.receiver.type === undefined) {
@@ -480,6 +480,13 @@ class ConversationController {
         });
     }
 
+    public get conversation(): threema.Conversation {
+        if (!hasValue(this._conversation)) {
+            this._conversation = this.webClientService.conversations.find(this.receiver);
+        }
+        return this._conversation;
+    }
+
     public isEnabled(): boolean {
         return this.type !== 'group'
             || !(this.receiver as threema.GroupReceiver).disabled;
@@ -879,6 +886,10 @@ class ConversationController {
      * Mark the current conversation as pinned.
      */
     public pinConversation(): void {
+        if (!hasValue(this.conversation)) {
+            this.$log.warn(this.logTag, 'Cannot pin, no conversation exists');
+            return;
+        }
         this.webClientService
             .modifyConversation(this.conversation, true)
             .then(() => this.showMessage('messenger.PINNED_CONVERSATION_OK'))
@@ -892,6 +903,10 @@ class ConversationController {
      * Mark the current conversation as not pinned.
      */
     public unpinConversation(): void {
+        if (!hasValue(this.conversation)) {
+            this.$log.warn(this.logTag, 'Cannot unpin, no conversation exists');
+            return;
+        }
         this.webClientService
             .modifyConversation(this.conversation, false)
             .then(() => this.showMessage('messenger.UNPINNED_CONVERSATION_OK'))