contact_badge.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * This file is part of Threema Web.
  3. *
  4. * Threema Web is free software: you can redistribute it and/or modify it
  5. * under the terms of the GNU Affero General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or (at
  7. * your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Affero General Public License
  15. * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. // tslint:disable:max-line-length
  18. import {StateService as UiStateService} from '@uirouter/angularjs';
  19. import {WebClientService} from '../services/webclient';
  20. /**
  21. * Show a contact receiver with small avatar, name and verification level
  22. */
  23. export default [
  24. 'WebClientService',
  25. '$state',
  26. function(webClientService: WebClientService, $state: UiStateService) {
  27. return {
  28. restrict: 'EA',
  29. scope: {},
  30. bindToController: {
  31. identity: '=?eeeIdentity',
  32. contactReceiver: '=?eeeContact',
  33. linked: '=?eeeLinked',
  34. onRemove: '=?eeeOnRemove',
  35. },
  36. controllerAs: 'ctrl',
  37. controller: [function() {
  38. this.$onInit = function() {
  39. if (this.contactReceiver === undefined) {
  40. this.contactReceiver = webClientService.contacts.get(this.identity);
  41. } else {
  42. this.identity = this.contactReceiver.id;
  43. }
  44. this.click = () => {
  45. if (this.linked !== undefined
  46. && this.linked === true) {
  47. $state.go('messenger.home.conversation', {type: 'contact', id: this.identity, initParams: null});
  48. }
  49. };
  50. this.showActions = this.onRemove !== undefined;
  51. };
  52. }],
  53. template: `
  54. <div class="contact-badge receiver-badge" ng-click="ctrl.click()">
  55. <section class="avatar-box">
  56. <eee-avatar eee-receiver="ctrl.contactReceiver"
  57. eee-resolution="'low'"></eee-avatar>
  58. </section>
  59. <div class="receiver-badge-name"
  60. ng-bind-html="ctrl.contactReceiver.displayName | escapeHtml | emojify">
  61. </div>
  62. <div class="contact-badge-identity">
  63. {{ctrl.contactReceiver.id}}
  64. </div>
  65. <div class="contact-badge-actions" ng-if="ctrl.showActions">
  66. <md-button aria-label="Remove" class="md-icon-button" ng-click="ctrl.onRemove(ctrl.contactReceiver)">
  67. <i class="material-icons md-dark md-24">delete</i>
  68. </md-button>
  69. </div>
  70. </div>
  71. `,
  72. };
  73. },
  74. ];