message_text.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. export default [
  19. function() {
  20. return {
  21. restrict: 'EA',
  22. scope: {},
  23. bindToController: {
  24. message: '=eeeMessage',
  25. multiLine: '=?eeeMultiLine',
  26. },
  27. controllerAs: 'ctrl',
  28. controller: [function() {
  29. // Get text depending on type
  30. let rawText = null;
  31. let message = this.message as threema.Message;
  32. switch (message.type) {
  33. case 'text':
  34. rawText = message.body;
  35. break;
  36. case 'location':
  37. rawText = message.location.poi;
  38. break;
  39. case 'file':
  40. // Prefer caption for file messages, if available
  41. if (message.caption && message.caption.length > 0) {
  42. rawText = message.caption;
  43. } else {
  44. rawText = message.file.name;
  45. }
  46. break;
  47. default:
  48. rawText = message.caption;
  49. break;
  50. }
  51. // Escaping will be done in the HTML using filters
  52. this.text = rawText;
  53. if (this.multiLine === undefined) {
  54. this.multiLine = true;
  55. }
  56. }],
  57. template: `
  58. <span threema-action ng-bind-html="ctrl.text | escapeHtml | markify | emojify | mentionify | linkify | nlToBr: ctrl.multiLine"></span>
  59. `,
  60. };
  61. },
  62. ];