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.

95 lines
4.3 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
  1. import { Builder } from "builder-pattern";
  2. import * as Handlebars from "handlebars";
  3. import * as log from 'loglevel';
  4. import { ChatController } from "./controller/ChatController";
  5. import { UserController } from "./controller/UserController";
  6. import { ChatModel } from "./model/ChatModel";
  7. import { ChatModelHelper } from "./model/ChatModelHelper";
  8. import { UserModel } from "./model/UserModel";
  9. import { AlertifyNotificationService } from "./service/AlertifyNotificationService";
  10. import { EncryptionServiceFactory } from "./service/EncryptionServiceFactory";
  11. import { FuseSearchService } from "./service/FuseSearchService";
  12. import { MarkDownItMarkDownService } from "./service/MarkDownItMarkDownService";
  13. import { NotificationService } from "./service/NotificationService";
  14. import { SearchService } from "./service/SearchService";
  15. import { TemplateFactory } from "./template/TemplateFactory";
  16. import { ChatView } from "./view/ChatView";
  17. import { ChatViewDeps } from "./view/ChatViewDeps";
  18. import { UserView } from "./view/UserView";
  19. import { UserViewDeps } from "./view/UserViewDeps";
  20. import { ActiveUserViewModel } from "./viewmodel/ActiveUserViewModel";
  21. import moment = require("moment");
  22. log.setLevel("TRACE");
  23. const usersListElement = document.getElementById('contacts-box');
  24. const userSearchButton = document.getElementById('user-search');
  25. const userSearchInputElement = document.getElementById('user-search-term') as HTMLInputElement;
  26. const userSearchCancelButton = document.getElementById('user-search-cancel');
  27. const chatArea = document.getElementById('chat-area-new');
  28. const activeUserSearchService: SearchService<ActiveUserViewModel> = new FuseSearchService(["userName"]);
  29. const ns: NotificationService = new AlertifyNotificationService();
  30. const encryptionService = EncryptionServiceFactory.getEncryptionService();
  31. const chatModelHelper = new ChatModelHelper(encryptionService, ns);
  32. const chatModel = new ChatModel(chatModelHelper);
  33. const cvDeps: ChatViewDeps = {
  34. chatModel: chatModel,
  35. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  36. messageContainer: chatArea,
  37. messageSendTemplate: TemplateFactory.getTemplate('msg_container_send_template'),
  38. messageReceiveTemplate: TemplateFactory.getTemplate('msg_container_template'),
  39. markdownService: new MarkDownItMarkDownService,
  40. encryptionService: encryptionService,
  41. notificationService: ns
  42. }
  43. const chatView = new ChatView(cvDeps);
  44. chatModel.attach(chatView);
  45. const chatController = new ChatController(chatModel, chatView);
  46. const userModel = new UserModel(ns);
  47. const uvDeps: UserViewDeps = {
  48. model: userModel,
  49. chatModel: chatModel,
  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. usersListElement: usersListElement,
  52. userSearchInputElement: userSearchInputElement,
  53. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  54. userSearchButton: userSearchButton,
  55. // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
  56. userSearchCancelButton: userSearchCancelButton,
  57. searchService: activeUserSearchService,
  58. userContactOnlineTemplate: TemplateFactory.getTemplate('user-contact-online-template'),
  59. userContactOfflineTemplate: TemplateFactory.getTemplate('user-contact-offline-template')
  60. }
  61. const userView = new UserView(uvDeps);
  62. userModel.attach(userView);
  63. const userController = new UserController(userModel, userView);
  64. userController.getActiveUsers();
  65. Handlebars.registerHelper('avatar', function () {
  66. 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>';
  67. });
  68. Handlebars.registerHelper('fromNow', function (date: string) {
  69. return moment(date).fromNow();
  70. })
  71. Handlebars.registerHelper('msgDateFormat', function(date: string) {
  72. return moment(date).calendar(moment.now(), {lastWeek: "DD/MM/YY hh:mm:a", sameElse: "DD/MM/YY hh:mm:a"})
  73. })
  74. ns.success("Welcome");
  75. // ns.errorWithDelay("Hmm very long error notif", 10);
  76. const test = Builder<UserViewDeps>().build();