Organized imports
This commit is contained in:
parent
2b3d6009f1
commit
00a01bc81b
@ -1,26 +1,26 @@
|
|||||||
|
import { Client } from "@stomp/stompjs";
|
||||||
import { Builder } from "builder-pattern";
|
import { Builder } from "builder-pattern";
|
||||||
import * as Handlebars from "handlebars";
|
import * as Handlebars from "handlebars";
|
||||||
import * as log from "loglevel";
|
import log from "loglevel";
|
||||||
import { ChatController } from "./controller/ChatController";
|
import moment from "moment";
|
||||||
import { UserController } from "./controller/UserController";
|
import SockJS from "sockjs-client";
|
||||||
import { ChatModel } from "./model/ChatModel";
|
|
||||||
import { ChatModelHelper } from "./model/ChatModelHelper";
|
|
||||||
import { UserModel } from "./model/UserModel";
|
|
||||||
import { AlertifyNotificationService } from "../common/service/AlertifyNotificationService";
|
import { AlertifyNotificationService } from "../common/service/AlertifyNotificationService";
|
||||||
import { EncryptionServiceFactory } from "../common/service/EncryptionServiceFactory";
|
import { EncryptionServiceFactory } from "../common/service/EncryptionServiceFactory";
|
||||||
import { FuseSearchService } from "../common/service/FuseSearchService";
|
import { FuseSearchService } from "../common/service/FuseSearchService";
|
||||||
import { MarkDownItMarkDownService } from "../common/service/MarkDownItMarkDownService";
|
import { MarkDownItMarkDownService } from "../common/service/MarkDownItMarkDownService";
|
||||||
import { NotificationService } from "../common/service/NotificationService";
|
import { NotificationService } from "../common/service/NotificationService";
|
||||||
import { SearchService } from "../common/service/SearchService";
|
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 { TemplateFactory } from "./template/TemplateFactory";
|
||||||
import { ChatView } from "./view/ChatView";
|
import { ChatView } from "./view/ChatView";
|
||||||
import { ChatViewDeps } from "./view/ChatViewDeps";
|
import { ChatViewDeps } from "./view/ChatViewDeps";
|
||||||
import { UserView } from "./view/UserView";
|
import { UserView } from "./view/UserView";
|
||||||
import { UserViewDeps } from "./view/UserViewDeps";
|
import { UserViewDeps } from "./view/UserViewDeps";
|
||||||
import { ActiveUserViewModel } from "./viewmodel/ActiveUserViewModel";
|
import { ActiveUserViewModel } from "./viewmodel/ActiveUserViewModel";
|
||||||
import moment = require("moment");
|
|
||||||
import SockJS from "sockjs-client";
|
|
||||||
import { Client } from "@stomp/stompjs";
|
|
||||||
|
|
||||||
// log.setLevel("TRACE");
|
// log.setLevel("TRACE");
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { Subject } from "../observe/Observable";
|
import { Subject } from "../observe/Observable";
|
||||||
import { Observer } from "../observe/Observer";
|
import { Observer } from "../observe/Observer";
|
||||||
|
import { ObserverData } from "../observe/ObserverData";
|
||||||
import { JsonAPI } from "../singleton/JsonAPI";
|
import { JsonAPI } from "../singleton/JsonAPI";
|
||||||
|
import { ActiveUserViewModel } from "../viewmodel/ActiveUserViewModel";
|
||||||
import { ChatMessageViewModel } from "../viewmodel/ChatMessageViewModel";
|
import { ChatMessageViewModel } from "../viewmodel/ChatMessageViewModel";
|
||||||
import { ChatModelHelper } from "./ChatModelHelper";
|
import { ChatModelHelper } from "./ChatModelHelper";
|
||||||
import log = require("loglevel");
|
import log from "loglevel";
|
||||||
import { ObserverData } from "../observe/ObserverData";
|
import moment from "moment";
|
||||||
import { ActiveUserViewModel } from "../viewmodel/ActiveUserViewModel";
|
|
||||||
import moment = require("moment");
|
|
||||||
|
|
||||||
interface Params {
|
interface Params {
|
||||||
userName: string;
|
userName: string;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import * as log from "loglevel";
|
import log from "loglevel";
|
||||||
import { ChatMessageDTO } from "../../common/dto/ChatMessageDTO";
|
import { ChatMessageDTO } from "../../common/dto/ChatMessageDTO";
|
||||||
|
import { Sprintf } from "../../common/global/Sprintf";
|
||||||
import { EncryptionService } from "../../common/service/EncryptionService";
|
import { EncryptionService } from "../../common/service/EncryptionService";
|
||||||
import { NotificationService } from "../../common/service/NotificationService";
|
import { NotificationService } from "../../common/service/NotificationService";
|
||||||
import { JsonAPI } from "../singleton/JsonAPI";
|
import { JsonAPI } from "../singleton/JsonAPI";
|
||||||
import { Sprintf } from "../../common/global/Sprintf";
|
|
||||||
import { ChatMessageViewModel } from "../viewmodel/ChatMessageViewModel";
|
import { ChatMessageViewModel } from "../viewmodel/ChatMessageViewModel";
|
||||||
import { fetchErrorHandler } from "./FetchErrorHandler";
|
import { fetchErrorHandler } from "./FetchErrorHandler";
|
||||||
|
|
||||||
|
@ -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 { Subject } from "../observe/Observable";
|
||||||
import { Observer } from "../observe/Observer";
|
import { Observer } from "../observe/Observer";
|
||||||
import { JsonAPI } from "../singleton/JsonAPI";
|
import { JsonAPI } from "../singleton/JsonAPI";
|
||||||
import { ActiveUserViewModel } from "../viewmodel/ActiveUserViewModel";
|
import { ActiveUserViewModel } from "../viewmodel/ActiveUserViewModel";
|
||||||
import { fetchErrorHandler } from "./FetchErrorHandler";
|
import { fetchErrorHandler } from "./FetchErrorHandler";
|
||||||
import { NotificationService } from "../../common/service/NotificationService";
|
|
||||||
|
|
||||||
export class UserModel implements Subject<ActiveUserViewModel> {
|
export class UserModel implements Subject<ActiveUserViewModel> {
|
||||||
/**
|
/**
|
||||||
@ -64,8 +64,8 @@ export class UserModel implements Subject<ActiveUserViewModel> {
|
|||||||
|
|
||||||
updateLastActive(username: String, lastActive: Date): void {
|
updateLastActive(username: String, lastActive: Date): void {
|
||||||
this._activeUsersList
|
this._activeUsersList
|
||||||
.filter(u => u.userName == username)
|
.filter((u) => u.userName == username)
|
||||||
.forEach(u => u.lastActive = lastActive)
|
.forEach((u) => (u.lastActive = lastActive));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,5 +112,5 @@ export class UserModel implements Subject<ActiveUserViewModel> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private helperMethod() { }
|
private helperMethod() {}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
import * as DOMPurify from "dompurify";
|
import DOMPurify from "dompurify";
|
||||||
import * as log from "loglevel";
|
import log from "loglevel";
|
||||||
import { ChatMessageDTO } from "../../common/dto/ChatMessageDTO";
|
import { ChatMessageDTO } from "../../common/dto/ChatMessageDTO";
|
||||||
import { MessageCipherDTO } from "../../common/dto/MessageCipherDTO";
|
import { MessageCipherDTO } from "../../common/dto/MessageCipherDTO";
|
||||||
import { ChatModel } from "../model/ChatModel";
|
|
||||||
import { Observer } from "../observe/Observer";
|
|
||||||
import { EncryptionService } from "../../common/service/EncryptionService";
|
import { EncryptionService } from "../../common/service/EncryptionService";
|
||||||
import { MarkDownService } from "../../common/service/MarkDownService";
|
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 { JsonAPI } from "../singleton/JsonAPI";
|
||||||
import { ChatMessageViewModel } from "../viewmodel/ChatMessageViewModel";
|
import { ChatMessageViewModel } from "../viewmodel/ChatMessageViewModel";
|
||||||
import { ChatViewDeps } from "./ChatViewDeps";
|
import { ChatViewDeps } from "./ChatViewDeps";
|
||||||
import { fetchHandler } from "./FetchHandler";
|
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<ChatMessageViewModel> {
|
export class ChatView implements Observer<ChatMessageViewModel> {
|
||||||
private readonly _chatModel: ChatModel;
|
private readonly _chatModel: ChatModel;
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { Observer } from "../observe/Observer";
|
import DOMPurify from "dompurify";
|
||||||
import { ActiveUserViewModel } from "../viewmodel/ActiveUserViewModel";
|
import { NotificationService } from "../../common/service/NotificationService";
|
||||||
import { ChatModel } from "../model/ChatModel";
|
|
||||||
import log = require("loglevel");
|
|
||||||
import * as DOMPurify from "dompurify";
|
|
||||||
import { SearchService } from "../../common/service/SearchService";
|
import { SearchService } from "../../common/service/SearchService";
|
||||||
|
import { ChatModel } from "../model/ChatModel";
|
||||||
import { UserModel } from "../model/UserModel";
|
import { UserModel } from "../model/UserModel";
|
||||||
import { UserViewDeps } from "./UserViewDeps";
|
import { Observer } from "../observe/Observer";
|
||||||
import { ObserverData } from "../observe/ObserverData";
|
import { ObserverData } from "../observe/ObserverData";
|
||||||
import { JsonAPI } from "../singleton/JsonAPI";
|
import { JsonAPI } from "../singleton/JsonAPI";
|
||||||
import { NotificationService } from "../../common/service/NotificationService";
|
import { ActiveUserViewModel } from "../viewmodel/ActiveUserViewModel";
|
||||||
import { ChatMessageViewModel } from "../viewmodel/ChatMessageViewModel";
|
import { ChatMessageViewModel } from "../viewmodel/ChatMessageViewModel";
|
||||||
|
import { UserViewDeps } from "./UserViewDeps";
|
||||||
|
import log from "loglevel";
|
||||||
|
|
||||||
export class UserView implements Observer<ActiveUserViewModel> {
|
export class UserView implements Observer<ActiveUserViewModel> {
|
||||||
private readonly _model: UserModel;
|
private readonly _model: UserModel;
|
||||||
@ -89,58 +89,63 @@ export class UserView implements Observer<ActiveUserViewModel> {
|
|||||||
JsonAPI.contactName = userName;
|
JsonAPI.contactName = userName;
|
||||||
// @ts-ignore: Object is possibly 'null'.
|
// @ts-ignore: Object is possibly 'null'.
|
||||||
document.getElementById("user-name-span").innerText = userName;
|
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;
|
currentUser.userName = userName;
|
||||||
|
|
||||||
if (!currentUser?.passphrase) {
|
if (!currentUser?.passphrase) {
|
||||||
this._notificationService.passphrasePrompt(
|
this._notificationService.passphrasePrompt(async (result) => {
|
||||||
async (result) => {
|
if (result) {
|
||||||
if (result) {
|
const valid = await this._chatModel.isPassphraseValid(
|
||||||
|
result,
|
||||||
const valid = await this._chatModel.isPassphraseValid(result, currentUser.userName!);
|
currentUser.userName!
|
||||||
if (!valid) {
|
);
|
||||||
bootbox.alert("Some error occured. Please check your password");
|
if (!valid) {
|
||||||
log.error("invalid password");
|
bootbox.alert("Some error occured. Please check your password");
|
||||||
return;
|
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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
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");
|
this._chatModel.getMessages(currentUser, "new");
|
||||||
}
|
}
|
||||||
|
|
||||||
el.className += " active";
|
el.className += " active";
|
||||||
if (currentUser.unlocked && currentUser.lastMessageTime) {
|
if (currentUser.unlocked && currentUser.lastMessageTime) {
|
||||||
this._newMessagesLoop = setInterval(
|
this._newMessagesLoop = setInterval(
|
||||||
this._chatModel.getMessages.bind(this._chatModel, currentUser, "update"),
|
this._chatModel.getMessages.bind(
|
||||||
|
this._chatModel,
|
||||||
|
currentUser,
|
||||||
|
"update"
|
||||||
|
),
|
||||||
10_000
|
10_000
|
||||||
);
|
);
|
||||||
this._model.notify();
|
this._model.notify();
|
||||||
@ -177,9 +182,8 @@ export class UserView implements Observer<ActiveUserViewModel> {
|
|||||||
let searchResult = this._searchService.search(list, searchTerm);
|
let searchResult = this._searchService.search(list, searchTerm);
|
||||||
this.update({ data: searchResult, op: "" });
|
this.update({ data: searchResult, op: "" });
|
||||||
log.debug(searchResult);
|
log.debug(searchResult);
|
||||||
}
|
} else {
|
||||||
else {
|
this._notificationService.error("Please enter a name");
|
||||||
this._notificationService.error("Please enter a name")
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user