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.

126 lines
5.4 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 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. ///<reference path="./SprintfTest.d.ts" />
  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. const usersListElement = document.getElementById('contacts-box');
  33. const userSearchButton = document.getElementById('user-search');
  34. const userSearchInputElement = document.getElementById('user-search-term') as HTMLInputElement;
  35. const userSearchCancelButton = document.getElementById('user-search-cancel');
  36. const searchService: SearchService<ActiveUserViewModel> = new FuseSearchService(["userName"]);
  37. log.setLevel("TRACE")
  38. const chatModel = new ChatModel();
  39. const userModel = new UserModel();
  40. // const userModel = ModelFactory.createModel("USER");
  41. const uvDeps: UserViewDeps = {
  42. model: userModel,
  43. chatModel: chatModel,
  44. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  45. usersListElement: usersListElement,
  46. userSearchInputElement: userSearchInputElement,
  47. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  48. userSearchButton: userSearchButton,
  49. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  50. userSearchCancelButton: userSearchCancelButton,
  51. searchService: searchService,
  52. userContactOnlineTemplate: TemplateFactory.getTemplate('user-contact-online-template'),
  53. userContactOfflineTemplate: TemplateFactory.getTemplate('user-contact-offline-template')
  54. }
  55. const userView = new UserView(uvDeps);
  56. // console.log(userBox);
  57. userModel.attach(userView);
  58. // userView.model
  59. const userController = new UserController(userModel, userView);
  60. // userController.test();
  61. // userModel.someBusinessMethod(activeUsersMock);
  62. log.info("hello");
  63. const chatArea = document.getElementById('chat-area-new');
  64. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  65. const cvDeps: ChatViewDeps = {
  66. chatModel: chatModel,
  67. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  68. messageContainer: chatArea,
  69. messageSendTemplate: TemplateFactory.getTemplate('msg_container_send_template'),
  70. messageReceiveTemplate: TemplateFactory.getTemplate('msg_container_template'),
  71. markdownService: new MarkDownItMarkDownService,
  72. encryptionService: new SJCLEncryptionService
  73. }
  74. const chatView = new ChatView(cvDeps);
  75. chatModel.attach(chatView);
  76. const chatController = new ChatController(chatModel, chatView);
  77. function someFunc(vm: ActiveUserViewModel): void {
  78. // log.info(vm);
  79. // logger.info(vm)
  80. }
  81. userController.getActiveUsers();
  82. log.info("test");
  83. // someFunc(activeUserViewModelMock);
  84. // @ts-ignore: Object is possibly 'null'.
  85. var source = document.getElementById("msg_container_template").innerHTML;
  86. var msgContainerTemplate = Handlebars.compile(source);
  87. JsonAPI.ACTIVE_USERS_GET + 'aef';
  88. const encryptionService: EncryptionService = new SJCLEncryptionService();
  89. let messageCipherDTO: MessageCipherDTO = encryptionService.encrypt("password", "data");
  90. console.log(encryptionService.decrypt("password", messageCipherDTO));
  91. Handlebars.registerHelper('avatar', function () {
  92. 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>';
  93. });
  94. const testList: ChatMessageDTO[] = [];
  95. // @ts-ignore
  96. console.log()
  97. // @ts-ignore
  98. log.info(Sprintf("test sprintf"))
  99. // log.info(sprintf2.sprintf("test sprintf"))
  100. const ns: NotificationService = new AlertifyNotificationService();
  101. ns.success("Welcome");
  102. // ns.errorWithDelay("Hmm very long error notif", 10);