From 00a01bc81bc80e4a765df73a8bc0a3e52d43a333 Mon Sep 17 00:00:00 2001 From: Rohan Sircar Date: Fri, 7 Aug 2020 12:31:07 +0530 Subject: [PATCH] Organized imports --- src/main/frontend/chat/main.ts | 18 +-- src/main/frontend/chat/model/ChatModel.ts | 8 +- .../frontend/chat/model/ChatModelHelper.ts | 4 +- src/main/frontend/chat/model/UserModel.ts | 10 +- src/main/frontend/chat/view/ChatView.ts | 14 +-- src/main/frontend/chat/view/UserView.ts | 106 +++++++++--------- 6 files changed, 82 insertions(+), 78 deletions(-) diff --git a/src/main/frontend/chat/main.ts b/src/main/frontend/chat/main.ts index af47324..99dd265 100644 --- a/src/main/frontend/chat/main.ts +++ b/src/main/frontend/chat/main.ts @@ -1,26 +1,26 @@ +import { Client } from "@stomp/stompjs"; import { Builder } from "builder-pattern"; import * as Handlebars from "handlebars"; -import * as log from "loglevel"; -import { ChatController } from "./controller/ChatController"; -import { UserController } from "./controller/UserController"; -import { ChatModel } from "./model/ChatModel"; -import { ChatModelHelper } from "./model/ChatModelHelper"; -import { UserModel } from "./model/UserModel"; +import log from "loglevel"; +import moment from "moment"; +import SockJS from "sockjs-client"; import { AlertifyNotificationService } from "../common/service/AlertifyNotificationService"; import { EncryptionServiceFactory } from "../common/service/EncryptionServiceFactory"; import { FuseSearchService } from "../common/service/FuseSearchService"; import { MarkDownItMarkDownService } from "../common/service/MarkDownItMarkDownService"; import { NotificationService } from "../common/service/NotificationService"; import { SearchService } from "../common/service/SearchService"; +import { ChatController } from "./controller/ChatController"; +import { UserController } from "./controller/UserController"; +import { ChatModel } from "./model/ChatModel"; +import { ChatModelHelper } from "./model/ChatModelHelper"; +import { UserModel } from "./model/UserModel"; import { TemplateFactory } from "./template/TemplateFactory"; import { ChatView } from "./view/ChatView"; import { ChatViewDeps } from "./view/ChatViewDeps"; import { UserView } from "./view/UserView"; import { UserViewDeps } from "./view/UserViewDeps"; import { ActiveUserViewModel } from "./viewmodel/ActiveUserViewModel"; -import moment = require("moment"); -import SockJS from "sockjs-client"; -import { Client } from "@stomp/stompjs"; // log.setLevel("TRACE"); diff --git a/src/main/frontend/chat/model/ChatModel.ts b/src/main/frontend/chat/model/ChatModel.ts index e03caa3..240f377 100644 --- a/src/main/frontend/chat/model/ChatModel.ts +++ b/src/main/frontend/chat/model/ChatModel.ts @@ -1,12 +1,12 @@ import { Subject } from "../observe/Observable"; import { Observer } from "../observe/Observer"; +import { ObserverData } from "../observe/ObserverData"; import { JsonAPI } from "../singleton/JsonAPI"; +import { ActiveUserViewModel } from "../viewmodel/ActiveUserViewModel"; import { ChatMessageViewModel } from "../viewmodel/ChatMessageViewModel"; import { ChatModelHelper } from "./ChatModelHelper"; -import log = require("loglevel"); -import { ObserverData } from "../observe/ObserverData"; -import { ActiveUserViewModel } from "../viewmodel/ActiveUserViewModel"; -import moment = require("moment"); +import log from "loglevel"; +import moment from "moment"; interface Params { userName: string; diff --git a/src/main/frontend/chat/model/ChatModelHelper.ts b/src/main/frontend/chat/model/ChatModelHelper.ts index b432b58..6df4d41 100644 --- a/src/main/frontend/chat/model/ChatModelHelper.ts +++ b/src/main/frontend/chat/model/ChatModelHelper.ts @@ -1,9 +1,9 @@ -import * as log from "loglevel"; +import log from "loglevel"; import { ChatMessageDTO } from "../../common/dto/ChatMessageDTO"; +import { Sprintf } from "../../common/global/Sprintf"; import { EncryptionService } from "../../common/service/EncryptionService"; import { NotificationService } from "../../common/service/NotificationService"; import { JsonAPI } from "../singleton/JsonAPI"; -import { Sprintf } from "../../common/global/Sprintf"; import { ChatMessageViewModel } from "../viewmodel/ChatMessageViewModel"; import { fetchErrorHandler } from "./FetchErrorHandler"; diff --git a/src/main/frontend/chat/model/UserModel.ts b/src/main/frontend/chat/model/UserModel.ts index 01d3760..bf264e9 100644 --- a/src/main/frontend/chat/model/UserModel.ts +++ b/src/main/frontend/chat/model/UserModel.ts @@ -1,10 +1,10 @@ -import * as log from "loglevel"; +import log from "loglevel"; +import { NotificationService } from "../../common/service/NotificationService"; import { Subject } from "../observe/Observable"; import { Observer } from "../observe/Observer"; import { JsonAPI } from "../singleton/JsonAPI"; import { ActiveUserViewModel } from "../viewmodel/ActiveUserViewModel"; import { fetchErrorHandler } from "./FetchErrorHandler"; -import { NotificationService } from "../../common/service/NotificationService"; export class UserModel implements Subject { /** @@ -64,8 +64,8 @@ export class UserModel implements Subject { updateLastActive(username: String, lastActive: Date): void { this._activeUsersList - .filter(u => u.userName == username) - .forEach(u => u.lastActive = lastActive) + .filter((u) => u.userName == username) + .forEach((u) => (u.lastActive = lastActive)); } /** @@ -112,5 +112,5 @@ export class UserModel implements Subject { }); } - private helperMethod() { } + private helperMethod() {} } diff --git a/src/main/frontend/chat/view/ChatView.ts b/src/main/frontend/chat/view/ChatView.ts index 6796fb9..95b1819 100644 --- a/src/main/frontend/chat/view/ChatView.ts +++ b/src/main/frontend/chat/view/ChatView.ts @@ -1,18 +1,18 @@ -import * as DOMPurify from "dompurify"; -import * as log from "loglevel"; +import DOMPurify from "dompurify"; +import log from "loglevel"; import { ChatMessageDTO } from "../../common/dto/ChatMessageDTO"; import { MessageCipherDTO } from "../../common/dto/MessageCipherDTO"; -import { ChatModel } from "../model/ChatModel"; -import { Observer } from "../observe/Observer"; import { EncryptionService } from "../../common/service/EncryptionService"; import { MarkDownService } from "../../common/service/MarkDownService"; +import { NotificationService } from "../../common/service/NotificationService"; +import { ChatModel } from "../model/ChatModel"; +import { UserModel } from "../model/UserModel"; +import { Observer } from "../observe/Observer"; +import { ObserverData } from "../observe/ObserverData"; import { JsonAPI } from "../singleton/JsonAPI"; import { ChatMessageViewModel } from "../viewmodel/ChatMessageViewModel"; import { ChatViewDeps } from "./ChatViewDeps"; import { fetchHandler } from "./FetchHandler"; -import { ObserverData } from "../observe/ObserverData"; -import { NotificationService } from "../../common/service/NotificationService"; -import { UserModel } from "../model/UserModel"; export class ChatView implements Observer { private readonly _chatModel: ChatModel; diff --git a/src/main/frontend/chat/view/UserView.ts b/src/main/frontend/chat/view/UserView.ts index bbc4709..686f53c 100644 --- a/src/main/frontend/chat/view/UserView.ts +++ b/src/main/frontend/chat/view/UserView.ts @@ -1,15 +1,15 @@ -import { Observer } from "../observe/Observer"; -import { ActiveUserViewModel } from "../viewmodel/ActiveUserViewModel"; -import { ChatModel } from "../model/ChatModel"; -import log = require("loglevel"); -import * as DOMPurify from "dompurify"; +import DOMPurify from "dompurify"; +import { NotificationService } from "../../common/service/NotificationService"; import { SearchService } from "../../common/service/SearchService"; +import { ChatModel } from "../model/ChatModel"; import { UserModel } from "../model/UserModel"; -import { UserViewDeps } from "./UserViewDeps"; +import { Observer } from "../observe/Observer"; import { ObserverData } from "../observe/ObserverData"; import { JsonAPI } from "../singleton/JsonAPI"; -import { NotificationService } from "../../common/service/NotificationService"; +import { ActiveUserViewModel } from "../viewmodel/ActiveUserViewModel"; import { ChatMessageViewModel } from "../viewmodel/ChatMessageViewModel"; +import { UserViewDeps } from "./UserViewDeps"; +import log from "loglevel"; export class UserView implements Observer { private readonly _model: UserModel; @@ -89,58 +89,63 @@ export class UserView implements Observer { JsonAPI.contactName = userName; // @ts-ignore: Object is possibly 'null'. document.getElementById("user-name-span").innerText = userName; - let currentUser = this._model.activeUsersList.find((vm) => vm.userName === userName) || new ActiveUserViewModel(); + let currentUser = + this._model.activeUsersList.find((vm) => vm.userName === userName) || + new ActiveUserViewModel(); currentUser.userName = userName; if (!currentUser?.passphrase) { - this._notificationService.passphrasePrompt( - async (result) => { - if (result) { - - const valid = await this._chatModel.isPassphraseValid(result, currentUser.userName!); - if (!valid) { - bootbox.alert("Some error occured. Please check your password"); - log.error("invalid password"); - return; - } - currentUser.unlocked = true; - currentUser.passphrase = result; - const chatMessages: ChatMessageViewModel[] = await this._chatModel.getMessages(currentUser, "new"); - - this._model.activeUsersList - .filter((v) => v.userName == currentUser!.userName) - .forEach((v) => { - v.passphrase = result; - v.unlocked = true; - if (chatMessages.length > 0) { - v.lastMessageTime = new Date( - chatMessages[chatMessages.length - 1].messageTime - ); - const lastMessageText = (v.lastMessageText = - chatMessages[chatMessages.length - 1].message); - if (lastMessageText.length > 15) { - v.lastMessageText = - chatMessages[chatMessages.length - 1].message.slice( - 0, - 15 - ) + "..."; - } - } - }); - this._promptHandler(currentUser); - + this._notificationService.passphrasePrompt(async (result) => { + if (result) { + const valid = await this._chatModel.isPassphraseValid( + result, + currentUser.userName! + ); + if (!valid) { + bootbox.alert("Some error occured. Please check your password"); + log.error("invalid password"); + return; } + currentUser.unlocked = true; + currentUser.passphrase = result; + const chatMessages: ChatMessageViewModel[] = await this._chatModel.getMessages( + currentUser, + "new" + ); + + this._model.activeUsersList + .filter((v) => v.userName == currentUser!.userName) + .forEach((v) => { + v.passphrase = result; + v.unlocked = true; + if (chatMessages.length > 0) { + v.lastMessageTime = new Date( + chatMessages[chatMessages.length - 1].messageTime + ); + const lastMessageText = (v.lastMessageText = + chatMessages[chatMessages.length - 1].message); + if (lastMessageText.length > 15) { + v.lastMessageText = + chatMessages[chatMessages.length - 1].message.slice(0, 15) + + "..."; + } + } + }); + this._promptHandler(currentUser); } - ); - } - else { + }); + } else { this._chatModel.getMessages(currentUser, "new"); } el.className += " active"; if (currentUser.unlocked && currentUser.lastMessageTime) { this._newMessagesLoop = setInterval( - this._chatModel.getMessages.bind(this._chatModel, currentUser, "update"), + this._chatModel.getMessages.bind( + this._chatModel, + currentUser, + "update" + ), 10_000 ); this._model.notify(); @@ -177,9 +182,8 @@ export class UserView implements Observer { let searchResult = this._searchService.search(list, searchTerm); this.update({ data: searchResult, op: "" }); log.debug(searchResult); - } - else { - this._notificationService.error("Please enter a name") + } else { + this._notificationService.error("Please enter a name"); } }); }