Просмотр исходного кода

Contacts: Exclude hidden receivers (#661)

Contacts are marked as hidden if they are part of a common group, but
have never been contacted directly.

Fixes #655.
Danilo Bargen 6 лет назад
Родитель
Сommit
e1e5b0983b
3 измененных файлов с 21 добавлено и 13 удалено
  1. 1 10
      src/filters.ts
  2. 1 1
      src/partials/messenger.navigation.html
  3. 19 2
      src/partials/messenger.ts

+ 1 - 10
src/filters.ts

@@ -20,6 +20,7 @@ import {markify} from './markup_parser';
 import {MimeService} from './services/mime';
 import {NotificationService} from './services/notification';
 import {WebClientService} from './services/webclient';
+import {isContactReceiver} from './typeguards';
 
 angular.module('3ema.filters', [])
 
@@ -216,16 +217,6 @@ angular.module('3ema.filters', [])
     };
 })
 
-/**
- * Return whether contact is not me.
- */
-.filter('isNotMe', ['WebClientService', function(webClientService: WebClientService) {
-    return function(obj: threema.Receiver) {
-        const valid = (contact: threema.Receiver) => contact.id !== webClientService.receivers.me.id;
-        return filter(obj, valid);
-    };
-}])
-
 /**
  * Filter for duration formatting.
  */

+ 1 - 1
src/partials/messenger.navigation.html

@@ -120,7 +120,7 @@
 <div id="navigation-contacts" class="tab-content" ng-if="ctrl.activeTab == 'contacts'" in-view-container>
     <p class="empty" ng-if="ctrl.contacts().length === 0" translate>messenger.NO_CONTACTS_FOUND</p>
     <ul ng-class="{'hide-inactive': ctrl.hideInactiveContacts()}">
-        <li ng-repeat="contact in ctrl.contacts() | isNotMe | filter:ctrl.searchContact"
+        <li ng-repeat="contact in ctrl.contacts() | filter:ctrl.searchContact"
             ui-sref="messenger.home.conversation({ type: 'contact', id: contact.id, initParams: null })"
             class="contact"
             ng-class="{'inactive': contact.state == 'INACTIVE'}">

+ 19 - 2
src/partials/messenger.ts

@@ -24,7 +24,7 @@ import {
 } from '@uirouter/angularjs';
 
 import {ContactControllerModel} from '../controller_model/contact';
-import {bufferToUrl, hasValue, logAdapter, supportsPassive, throttle, u8aToHex} from '../helpers';
+import {bufferToUrl, filter, hasValue, logAdapter, supportsPassive, throttle, u8aToHex} from '../helpers';
 import {ContactService} from '../services/contact';
 import {ControllerService} from '../services/controller';
 import {ControllerModelService} from '../services/controller_model';
@@ -942,7 +942,24 @@ class NavigationController {
     }
 
     public contacts(): threema.ContactReceiver[] {
-        return Array.from(this.webClientService.contacts.values()) as threema.ContactReceiver[];
+        const contacts = [];
+        // Since `values()` on a map returns an iterator, we cannot directly
+        // apply the `.filter()` method that arrays provide. Therefore, in
+        // order to avoid creating an intermediate array just for filtering,
+        // create the list of contacts imperatively.
+        for (const contact of this.webClientService.contacts.values()) {
+            // Exclude own contact
+            if (contact.id === this.webClientService.receivers.me.id) {
+                continue;
+            }
+            // Exclude hidden contacts
+            if (contact.hidden === true) {
+                continue;
+            }
+            // Otherwise add to results
+            contacts.push(contact);
+        }
+        return contacts;
     }
 
     /**