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.

92 lines
3.8 KiB

  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 * as sprintf2 from "sprintf-js";
  25. const usersListElement = document.getElementById('contacts-box');
  26. const userSearchButton = document.getElementById('user-search');
  27. const userSearchInputElement = document.getElementById('user-search-term')
  28. const userSearchCancelButton = document.getElementById('user-search-cancel')
  29. log.setLevel("TRACE")
  30. const chatModel = new ChatModel();
  31. const userModel = new UserModel();
  32. // const userModel = ModelFactory.createModel("USER");
  33. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  34. const userView = new UserView(userModel, chatModel, usersListElement, userSearchInputElement, userSearchButton, userSearchCancelButton);
  35. // console.log(userBox);
  36. userModel.attach(userView);
  37. // userView.model
  38. const userController = new UserController(userModel, userView);
  39. // userController.test();
  40. // userModel.someBusinessMethod(activeUsersMock);
  41. log.info("hello");
  42. const chatArea = document.getElementById('chat-area-new');
  43. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  44. const chatView = new ChatView(chatModel, chatArea);
  45. chatModel.attach(chatView);
  46. const chatController = new ChatController(chatModel, chatView);
  47. function someFunc(vm: ActiveUserViewModel): void {
  48. // log.info(vm);
  49. // logger.info(vm)
  50. }
  51. userController.getActiveUsers();
  52. log.info("test");
  53. // someFunc(activeUserViewModelMock);
  54. // @ts-ignore: Object is possibly 'null'.
  55. var source = document.getElementById("msg_container_template").innerHTML;
  56. var msgContainerTemplate = Handlebars.compile(source);
  57. JsonAPI.ACTIVE_USERS_GET + 'aef';
  58. const encryptionService: EncryptionService = new SJCLEncryptionService();
  59. let messageCipherDTO: MessageCipherDTO = encryptionService.encrypt("password","data");
  60. console.log(encryptionService.decrypt("password", messageCipherDTO));
  61. Handlebars.registerHelper('avatar', function() {
  62. 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>';
  63. });
  64. const testList: ChatMessageDTO[] = [];
  65. const cmSearchService: SearchService<ChatMessageDTO> = new FuseSearchService(["userName"]);
  66. // @ts-ignore
  67. log.info(sprintf("test sprintf"))
  68. log.info(sprintf2.sprintf("test sprintf"))
  69. const ns: NotificationService = new AlertifyNotificationService();
  70. ns.success("Welcome");
  71. // ns.errorWithDelay("Hmm very long error notif", 10);