latest_message.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.showVoipInfo = (this.message as threema.Message).type === 'voipStatus';
  48. this.defaultStatusIcon = this.showVoipInfo ? 'phone_locked' :
  49. (this.isGroup ? 'group' : (this.isDistributionList ? 'forum' : null));
  50. // Find sender of latest message in group chats
  51. this.contact = null;
  52. if (this.message) {
  53. this.contact = webClientService.contacts.get(getIdentity(this.message));
  54. }
  55. // Typing indicator
  56. this.isTyping = () => false;
  57. if (this.isGroup === false
  58. && this.isDitributionList === false
  59. && this.contact !== null) {
  60. this.isTyping = () => {
  61. return webClientService.isTyping(this.contact);
  62. };
  63. }
  64. this.isHidden = () => {
  65. return this.receiver.locked;
  66. };
  67. // Show...
  68. this.showIcon = this.message
  69. && this.message.type !== 'text'
  70. && this.message.type !== 'status';
  71. this.getDraft = () => {
  72. return webClientService.getDraft(this.receiver);
  73. };
  74. this.showDraft = () => {
  75. if (receiverService.isConversationActive(this.receiver)) {
  76. // Don't show draft if conversation is active
  77. return false;
  78. }
  79. let draft = this.getDraft();
  80. return draft !== undefined && draft !== null;
  81. };
  82. }],
  83. templateUrl: 'directives/latest_message.html',
  84. };
  85. },
  86. ];