user_details_modal.js 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { __ } from '@converse/headless/i18n';
  2. import { html } from "lit-html";
  3. import avatar from "./avatar.js";
  4. import { modal_close_button, modal_header_close_button } from "./buttons"
  5. const i18n_address = __('XMPP Address');
  6. const i18n_email = __('Email');
  7. const i18n_fingerprints = __('OMEMO Fingerprints');
  8. const i18n_full_name = __('Full Name');
  9. const i18n_nickname = __('Nickname');
  10. const i18n_profile = __('The User\'s Profile Image');
  11. const i18n_refresh = __('Refresh');
  12. const i18n_role = __('Role');
  13. const i18n_url = __('URL');
  14. const i18n_remove_contact = __('Remove as contact');
  15. const i18n_trusted = __('Trusted');
  16. const i18n_untrusted = __('Untrusted');
  17. const i18n_no_devices = __("No OMEMO-enabled devices found");
  18. const avatar_data = {
  19. 'alt_text': i18n_profile,
  20. 'extra_classes': 'mb-3'
  21. }
  22. const device_fingerprint = (o) => {
  23. if (o.device.get('bundle') && o.device.get('bundle').fingerprint) {
  24. return html`
  25. <li class="list-group-item">
  26. <form class="fingerprint-trust">
  27. <div class="btn-group btn-group-toggle">
  28. <label class="btn btn--small ${(o.device.get('trusted') !== -1) ? 'btn-primary active' : 'btn-secondary'}">
  29. <input type="radio" name="${o.device.get('id')}" value="1" ?checked=${o.device.get('trusted') !== -1}>${i18n_trusted}
  30. </label>
  31. <label class="btn btn--small ${(o.device.get('trusted') !== -1) ? 'btn-primary active' : 'btn-secondary'}">
  32. <input type="radio" name="${o.device.get('id')}" value="-1" ?checked=${o.device.get('trusted') === -1}>${i18n_untrusted}
  33. </label>
  34. </div>
  35. <span class="fingerprint">${o.utils.formatFingerprint(o.device.get('bundle').fingerprint)}</span>
  36. </form>
  37. </li>
  38. `;
  39. } else {
  40. return ''
  41. }
  42. }
  43. const fingerprints = (o) => {
  44. const devices = o.view.devicelist.devices;
  45. return html`
  46. <hr/>
  47. <ul class="list-group fingerprints">
  48. <li class="list-group-item active">${i18n_fingerprints}</li>
  49. ${ devices.length ?
  50. devices.map(device => device_fingerprint(Object.assign({device}, o))) :
  51. html`<li class="list-group-item"> ${i18n_no_devices} </li>` }
  52. </ul>
  53. `;
  54. }
  55. const remove_button = (o) => {
  56. return html`
  57. <button type="button" @click="${o.removeContact}" class="btn btn-danger remove-contact">
  58. <i class="far fa-trash-alt"></i>${i18n_remove_contact}
  59. </button>
  60. `;
  61. }
  62. export default (o) => html`
  63. <div class="modal-dialog" role="document">
  64. <div class="modal-content">
  65. <div class="modal-header">
  66. <h5 class="modal-title" id="user-details-modal-label">${o.display_name}</h5>
  67. ${modal_header_close_button}
  68. </div>
  69. <div class="modal-body">
  70. ${ o.image ? avatar(Object.assign(avatar_data, o)) : '' }
  71. ${ o.fullname ? html`<p><label>${i18n_full_name}:</label> ${o.fullname}</p>` : '' }
  72. <p><label>${i18n_address}:</label> <a href="xmpp:${o.jid}">${o.jid}</a></p>
  73. ${ o.nickname ? html`<p><label>${i18n_nickname}:</label> ${o.nickname}</p>` : '' }
  74. ${ o.url ? html`<p><label>${i18n_url}:</label> <a target="_blank" rel="noopener" href="${o.url}">${o.url}</a></p>` : '' }
  75. ${ o.email ? html`<p><label>${i18n_email}:</label> <a href="mailto:${o.email}">${o.email}</a></p>` : '' }
  76. ${ o.role ? html`<p><label>${i18n_role}:</label> ${o.role}</p>` : '' }
  77. ${ (o._converse.pluggable.plugins['converse-omemo'].enabled(o._converse)) ? fingerprints(o) : '' }
  78. </div>
  79. <div class="modal-footer">
  80. ${modal_close_button}
  81. <button type="button" class="btn btn-info refresh-contact"><i class="fa fa-refresh"> </i>${i18n_refresh}</button>
  82. ${ (o.allow_contact_removal && o.is_roster_contact) ? remove_button(o) : '' }
  83. </div>
  84. </div>
  85. </div>
  86. `;