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.

141 lines
5.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. import { Controller } from "./controller/AbstractController";
  2. import { UserModel } from "./model/UserModel"
  3. import { Model } from "./model/AbstractModel";
  4. import { View } from "./view/AbstractView";
  5. import { UserView } from "./view/UserView";
  6. import { UserController } from "./controller/UserController";
  7. import { ModelFactory } from "./model/ModelFactory";
  8. import { ActiveUserViewModel } from "./viewmodel/ActiveUserViewModel";
  9. import { ChatMessageViewModel } from "./viewmodel/ChatMessageViewModel";
  10. import * as Handlebars from "handlebars";
  11. import { ChatModel } from "./model/ChatModel";
  12. import { ChatView } from "./view/ChatView";
  13. import { ChatController } from "./controller/ChatController";
  14. import { JsonAPI } from "./singleton/JsonAPI";
  15. import * as log from 'loglevel';
  16. import { EncryptionService } from "./service/EncryptionService";
  17. import { SJCLEncryptionService } from "./service/SJCLEncryptionService";
  18. import { MessageCipherDTO } from "./dto/MessageCipherDTO";
  19. import { SearchService } from "./service/SearchService";
  20. import { FuseSearchService } from "./service/FuseSearchService";
  21. import { ChatMessageDTO } from "./dto/ChatMessageDTO";
  22. import { NotificationService } from "./service/NotificationService";
  23. import { AlertifyNotificationService } from "./service/AlertifyNotificationService";
  24. import { Builder } from "builder-pattern";
  25. // import "./SprintfTest.d.ts"
  26. // import { sprintf } from "sprintf-js";
  27. // import sprintf = require('sprintf-js');
  28. import { TemplateFactory } from "./template/TemplateFactory";
  29. import { UserViewDeps } from "./view/UserViewDeps";
  30. import { ChatViewDeps } from "./view/ChatViewDeps";
  31. import { MarkDownItMarkDownService } from "./service/MarkDownItMarkDownService";
  32. import { Sprintf } from "./singleton/Sprintf";
  33. const usersListElement = document.getElementById('contacts-box');
  34. const userSearchButton = document.getElementById('user-search');
  35. const userSearchInputElement = document.getElementById('user-search-term') as HTMLInputElement;
  36. const userSearchCancelButton = document.getElementById('user-search-cancel');
  37. const activeUserSearchService: SearchService<ActiveUserViewModel> = new FuseSearchService(["userName"]);
  38. log.setLevel("TRACE")
  39. const chatModel = new ChatModel();
  40. const userModel = new UserModel();
  41. // const userModel = ModelFactory.createModel("USER");
  42. const uvDeps: UserViewDeps = {
  43. model: userModel,
  44. chatModel: chatModel,
  45. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  46. usersListElement: usersListElement,
  47. userSearchInputElement: userSearchInputElement,
  48. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  49. userSearchButton: userSearchButton,
  50. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  51. userSearchCancelButton: userSearchCancelButton,
  52. searchService: activeUserSearchService,
  53. userContactOnlineTemplate: TemplateFactory.getTemplate('user-contact-online-template'),
  54. userContactOfflineTemplate: TemplateFactory.getTemplate('user-contact-offline-template')
  55. }
  56. const userView = new UserView(uvDeps);
  57. // console.log(userBox);
  58. userModel.attach(userView);
  59. // userView.model
  60. const userController = new UserController(userModel, userView);
  61. // userController.test();
  62. // userModel.someBusinessMethod(activeUsersMock);
  63. log.info("hello");
  64. const chatArea = document.getElementById('chat-area-new');
  65. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  66. const cvDeps: ChatViewDeps = {
  67. chatModel: chatModel,
  68. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  69. messageContainer: chatArea,
  70. messageSendTemplate: TemplateFactory.getTemplate('msg_container_send_template'),
  71. messageReceiveTemplate: TemplateFactory.getTemplate('msg_container_template'),
  72. markdownService: new MarkDownItMarkDownService,
  73. encryptionService: new SJCLEncryptionService
  74. }
  75. const chatView = new ChatView(cvDeps);
  76. chatModel.attach(chatView);
  77. const chatController = new ChatController(chatModel, chatView);
  78. function someFunc(vm: ActiveUserViewModel): void {
  79. // log.info(vm);
  80. // logger.info(vm)
  81. }
  82. userController.getActiveUsers();
  83. log.info("test");
  84. // someFunc(activeUserViewModelMock);
  85. // @ts-ignore: Object is possibly 'null'.
  86. var source = document.getElementById("msg_container_template").innerHTML;
  87. var msgContainerTemplate = Handlebars.compile(source);
  88. JsonAPI.ACTIVE_USERS_GET + 'aef';
  89. const encryptionService: EncryptionService = new SJCLEncryptionService();
  90. let messageCipherDTO: MessageCipherDTO = encryptionService.encrypt("password", "data");
  91. console.log(encryptionService.decrypt("password", messageCipherDTO));
  92. async function func(): Promise<void> {
  93. const text = await encryptionService.decryptAsPromise("password", messageCipherDTO)
  94. log.debug(text);
  95. }
  96. func();
  97. Handlebars.registerHelper('avatar', function () {
  98. return '<div class="img_cont_msg"> <img src="https://static.turbosquid.com/Preview/001292/481/WV/_D.jpg" class="rounded-circle user_img_msg"> </div>';
  99. });
  100. const testList: ChatMessageDTO[] = [];
  101. // @ts-ignore
  102. console.log()
  103. log.info(Sprintf("test sprintf"))
  104. // log.info(sprintf2.sprintf("test sprintf"))
  105. const ns: NotificationService = new AlertifyNotificationService();
  106. ns.success("Welcome");
  107. // ns.errorWithDelay("Hmm very long error notif", 10);
  108. const ss = FuseSearchService.getInstance<ActiveUserViewModel>([""]);
  109. const test = Builder<UserViewDeps>().build();