A self hosted chat application with end-to-end encrypted messaging.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
4.1 KiB

4 years ago
4 years ago
4 years ago
  1. import { NotificationService } from "./NotificationService";
  2. // @ts-ignore
  3. import * as alertify from "alertifyjs";
  4. import { ActiveUserViewModel } from "../viewmodel/ActiveUserViewModel";
  5. import log = require("loglevel");
  6. import bootbox = require("bootbox")
  7. export class AlertifyNotificationService implements NotificationService {
  8. private readonly _alertify = alertify;
  9. constructor() {
  10. this._alertify.set('notifier', 'position', 'top-center');
  11. }
  12. success(message: string): void {
  13. this._alertify.success(message)
  14. }
  15. error(message: string): void {
  16. this._alertify.error(message);
  17. }
  18. errorWithDelay(message: string, delay: number): void {
  19. const _delay = this._alertify.get('notifier', 'delay');
  20. this._alertify.set('notifier', 'delay', delay);
  21. this._alertify.error(message);
  22. this._alertify.set('notifier', 'delay', _delay);
  23. }
  24. warning(message: string): void {
  25. this._alertify.warning(message);
  26. }
  27. message(message: string): void {
  28. this._alertify.message(message);
  29. }
  30. passphrasePrompt(vm: ActiveUserViewModel, vms: ActiveUserViewModel[], cb1: (contactName: string, passphrase: string,
  31. lastMessageTime: string | null, op: string) => void,
  32. cb2: () => any): void {
  33. // alertify.myprompt || alertify.dialog('myprompt', function () {
  34. // // document.getElementById('passphraseFormNew')!.addEventListener('submit', function (e: Event) {
  35. // // e.preventDefault();
  36. // // log.debug(this.querySelectorAll('input'))
  37. // // Array.from(this.querySelectorAll('input')).map((el) => {
  38. // // const el2 = el as HTMLInputElement;
  39. // // vm.passphrase = el2.value;
  40. // // vm.unlocked = true;
  41. // // cb1(vm.userName!, vm.passphrase, null, "new");
  42. // // cb2();
  43. // // alertify.myprompt().close();
  44. // // })
  45. // // log.debug(vm)
  46. // // })
  47. // return {
  48. // main: function (content: HTMLElement) {
  49. // log.debug(vm)
  50. // // @ts-ignore
  51. // this.setContent(content);
  52. // },
  53. // setup: function () {
  54. // return {
  55. // focus: {
  56. // // @ts-ignore
  57. // element: function () {
  58. // // @ts-ignore
  59. // return this.elements.body.querySelector(this.get('selector'));
  60. // },
  61. // select: true
  62. // },
  63. // options: {
  64. // title: 'Enter Passphrase',
  65. // basic: true,
  66. // maximizable: false,
  67. // resizable: false,
  68. // padding: false
  69. // }
  70. // };
  71. // },
  72. // settings: {
  73. // // @ts-ignore
  74. // selector: undefined
  75. // },
  76. // }
  77. // })
  78. // alertify.myprompt(document.getElementById('passphraseFormNew')).set('selector', 'input[type="password"]');
  79. if (vm.passphrase == null) {
  80. bootbox.prompt({
  81. title: "Please enter the passphrase",
  82. inputType: 'password',
  83. callback: function (result) {
  84. if (result) {
  85. log.debug(result);
  86. cb1(vm.userName!, result, null, "new");
  87. vm.unlocked = true
  88. vms.filter(v => v.userName == vm.userName).map(v => { v.passphrase = result; v.unlocked = true })
  89. cb2();
  90. log.debug(vm)
  91. log.debug(vms)
  92. }
  93. }
  94. });
  95. }
  96. else {
  97. cb1(vm.userName!, vm.passphrase, null, "new");
  98. }
  99. }
  100. }