latest_message.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. import {getSenderIdentity} from '../helpers/messages';
  18. import {MessageService} from '../services/message';
  19. import {ReceiverService} from '../services/receiver';
  20. import {WebClientService} from '../services/webclient';
  21. export default [
  22. 'WebClientService', 'ReceiverService', 'MessageService', '$filter',
  23. function(webClientService: WebClientService, receiverService: ReceiverService,
  24. messageService: MessageService, $filter: any) {
  25. return {
  26. restrict: 'EA',
  27. scope: {},
  28. bindToController: {
  29. conversation: '<',
  30. },
  31. controllerAs: 'ctrl',
  32. controller: [function() {
  33. this.$onInit = function() {
  34. // Conversation properties
  35. this.isGroup = this.conversation.type === 'group';
  36. this.isDistributionList = !this.isGroup && this.conversation.type === 'distributionList';
  37. // Voip status
  38. this.showVoipInfo = () => this.conversation.latestMessage.type === 'voipStatus';
  39. this.getStatusIcon = () => {
  40. if (this.showVoipInfo()) {
  41. return 'phone_locked';
  42. } else if (this.isGroup) {
  43. return 'group';
  44. } else if (this.isDistributionList) {
  45. return 'forum';
  46. } else if (!this.conversation.latestMessage.isOutbox) {
  47. return 'reply';
  48. } else {
  49. const showStatusIcon = messageService.showStatusIcon(
  50. this.conversation.latestMessage,
  51. this.conversation.receiver,
  52. );
  53. return showStatusIcon ? $filter('messageStateIcon')(this.conversation.latestMessage) : null;
  54. }
  55. };
  56. // Find sender of latest message
  57. this.getContact = () => {
  58. return webClientService.contacts.get(
  59. getSenderIdentity(
  60. (this.conversation as threema.Conversation).latestMessage,
  61. webClientService.me.id,
  62. ),
  63. );
  64. };
  65. const contact = this.getContact();
  66. // Typing indicator
  67. this.isTyping = () => false;
  68. if (this.isGroup === false && this.isDistributionList === false && contact !== null) {
  69. this.isTyping = () => webClientService.isTyping(contact);
  70. }
  71. this.isHidden = () => this.conversation.receiver.locked;
  72. // Show...
  73. this.showIcon = () => {
  74. const message = (this.conversation as threema.Conversation).latestMessage;
  75. return message.type !== 'text' && message.type !== 'status';
  76. };
  77. // Drafts
  78. this.getDraft = () => webClientService.getDraft(this.conversation.receiver);
  79. this.showDraft = () => {
  80. if (receiverService.isConversationActive(this.conversation.receiver)) {
  81. // Don't show draft if conversation is active
  82. return false;
  83. }
  84. const draft = this.getDraft();
  85. return draft !== undefined && draft !== null;
  86. };
  87. };
  88. }],
  89. templateUrl: 'directives/latest_message.html',
  90. };
  91. },
  92. ];