latest_message.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 {ReceiverService} from '../services/receiver';
  18. import {WebClientService} from '../services/webclient';
  19. export default [
  20. 'WebClientService', 'ReceiverService',
  21. function(webClientService: WebClientService, receiverService: ReceiverService) {
  22. return {
  23. restrict: 'EA',
  24. scope: {},
  25. bindToController: {
  26. type: '=eeeType',
  27. message: '=eeeMessage',
  28. receiver: '=eeeReceiver',
  29. },
  30. controllerAs: 'ctrl',
  31. controller: [function() {
  32. // Utilities
  33. const getIdentity = function(message) {
  34. // TODO: Get rid of duplication with eeeMessage directive
  35. if (message.isOutbox) {
  36. return webClientService.me.id;
  37. }
  38. if (message.partnerId !== null) {
  39. return message.partnerId;
  40. }
  41. return null;
  42. };
  43. // Conversation properties
  44. this.isGroup = this.type as threema.ReceiverType === 'group';
  45. this.isDistributionList = !this.isGroup
  46. && this.type as threema.ReceiverType === 'distributionList';
  47. this.defaultStatusIcon = (this.isGroup ? 'group' : (this.isDistributionList ? 'forum' : null));
  48. // this.hasContact = webClientService.contacts.has(getIdentity(this.message));
  49. // Find sender of latest message in group chats
  50. this.contact = null;
  51. if (this.message) {
  52. this.contact = webClientService.contacts.get(getIdentity(this.message));
  53. }
  54. // Typing indicator
  55. this.isTyping = () => false;
  56. if (this.isGroup === false
  57. && this.isDitributionList === false
  58. && this.contact !== null) {
  59. this.isTyping = () => {
  60. return webClientService.isTyping(this.contact);
  61. };
  62. }
  63. this.isHidden = () => {
  64. return this.receiver.locked;
  65. };
  66. // Show...
  67. this.showIcon = this.message
  68. && this.message.type !== 'text'
  69. && this.message.type !== 'status';
  70. this.getDraft = () => {
  71. if (receiverService.isConversationActive(this.receiver)) {
  72. return null;
  73. }
  74. return webClientService.getDraft(this.receiver);
  75. };
  76. this.hasDraft = () => {
  77. let draft = this.getDraft();
  78. return draft !== undefined && draft !== null;
  79. };
  80. }],
  81. templateUrl: 'directives/latest_message.html',
  82. };
  83. },
  84. ];