Parcourir la source

Clean up draft displaying logic

Danilo Bargen il y a 8 ans
Parent
commit
3dfe0a07d4

+ 1 - 1
src/controllers/status.ts

@@ -136,7 +136,7 @@ export class StatusController {
     }
 
     /**
-     * Go back to the welcome screen and try to reconnect using the same keys as right now.
+     * Attempt to reconnect after a connection loss.
      */
     private reconnect(): void {
         this.$log.warn(this.logTag, 'Connection lost. Attempting to reconnect...');

+ 1 - 1
src/directives/latest_message.html

@@ -1,4 +1,4 @@
-<div class="latest-message" ng-class="{'has-draft': ctrl.hasDraft(), 'is-typing': ctrl.isTyping(), 'is-hidden': ctrl.isHidden()}">
+<div class="latest-message" ng-class="{'show-draft': ctrl.showDraft(), 'is-typing': ctrl.isTyping(), 'is-hidden': ctrl.isHidden()}">
 
     <!-- Typing indicator -->
     <div class="left typing">

+ 5 - 4
src/directives/latest_message.ts

@@ -78,13 +78,14 @@ export default [
                     && this.message.type !== 'status';
 
                 this.getDraft = () => {
-                    if (receiverService.isConversationActive(this.receiver)) {
-                        return null;
-                    }
                     return webClientService.getDraft(this.receiver);
                 };
 
-                this.hasDraft = () => {
+                this.showDraft = () => {
+                    if (receiverService.isConversationActive(this.receiver)) {
+                        // Don't show draft if conversation is active
+                        return false;
+                    }
                     let draft = this.getDraft();
                     return draft !== undefined && draft !== null;
                 };

+ 2 - 2
src/sass/sections/_navigation.scss

@@ -191,7 +191,7 @@
                         }
                     }
 
-                    &.has-draft {
+                    &.show-draft {
                         .no-draft {
                             display: none;
                         }
@@ -202,7 +202,7 @@
                             display: none;
                         }
                     }
-                    &:not(.has-draft) {
+                    &:not(.show-draft) {
                         .draft {
                             display: none;
                         }

+ 7 - 2
src/services/receiver.ts

@@ -40,11 +40,16 @@ export class ReceiverService {
     }
 
     public isConversationActive(conversation: threema.Conversation): boolean {
-        if (this.activeReceiver !== undefined) {
-           return this.compare(conversation, this.activeReceiver);
+        if (!this.activeReceiver) {
+            return false;
         }
+        return this.compare(conversation, this.activeReceiver);
     }
 
+    /**
+     * Compare two conversations and/or receivers.
+     * Return `true` if they both have the same type and id.
+     */
     public compare(a: threema.Conversation | threema.Receiver,
                    b: threema.Conversation | threema.Receiver): boolean {
         return a !== undefined