From ff43977f93bd3eca337227fd36bf913741cfb065 Mon Sep 17 00:00:00 2001 From: Rohan Sircar Date: Sun, 15 Mar 2020 12:50:22 +0530 Subject: [PATCH] Changes to page loading Chat message pages now use passphrases from the stored model. --- chatto/src/main/javascript/ts/src/main.ts | 6 ++++-- .../main/javascript/ts/src/view/ChatView.ts | 20 +++++-------------- .../javascript/ts/src/view/ChatViewDeps.ts | 4 +++- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/chatto/src/main/javascript/ts/src/main.ts b/chatto/src/main/javascript/ts/src/main.ts index 5fbd71a..89f2f58 100644 --- a/chatto/src/main/javascript/ts/src/main.ts +++ b/chatto/src/main/javascript/ts/src/main.ts @@ -37,6 +37,7 @@ const encryptionService = EncryptionServiceFactory.getEncryptionService(); const chatModelHelper = new ChatModelHelper(encryptionService, ns); const chatModel = new ChatModel(chatModelHelper); +const userModel = new UserModel(ns); const cvDeps: ChatViewDeps = { chatModel: chatModel, // @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'. @@ -45,7 +46,8 @@ const cvDeps: ChatViewDeps = { messageReceiveTemplate: TemplateFactory.getTemplate('msg_container_template'), markdownService: new MarkDownItMarkDownService, encryptionService: encryptionService, - notificationService: ns + notificationService: ns, + userModel: userModel } const chatView = new ChatView(cvDeps); chatModel.attach(chatView); @@ -53,7 +55,7 @@ const chatController = new ChatController(chatModel, chatView); -const userModel = new UserModel(ns); + const uvDeps: UserViewDeps = { model: userModel, chatModel: chatModel, diff --git a/chatto/src/main/javascript/ts/src/view/ChatView.ts b/chatto/src/main/javascript/ts/src/view/ChatView.ts index d1cbb09..b9aa89f 100644 --- a/chatto/src/main/javascript/ts/src/view/ChatView.ts +++ b/chatto/src/main/javascript/ts/src/view/ChatView.ts @@ -12,6 +12,7 @@ import { ChatViewDeps } from "./ChatViewDeps"; import { fetchHandler } from "./FetchHandler"; import { ObserverData } from '../observe/ObserverData'; import { NotificationService } from '../service/NotificationService'; +import { UserModel } from '../model/UserModel'; export class ChatView implements Observer { private readonly _chatModel: ChatModel; @@ -21,6 +22,7 @@ export class ChatView implements Observer { private readonly _markdownService: MarkDownService; private readonly _encryptionService: EncryptionService; private readonly _notificationService: NotificationService; + private readonly _userModel: UserModel; constructor(deps: ChatViewDeps) { @@ -31,6 +33,7 @@ export class ChatView implements Observer { this._markdownService = deps.markdownService; this._encryptionService = deps.encryptionService; this._notificationService = deps.notificationService; + this._userModel = deps.userModel; this._initEventListeners(); $(document).ready(function () { @@ -196,22 +199,9 @@ export class ChatView implements Observer { if ($(this._messageContainer).scrollTop() == 0 && $(this._messageContainer).html() != "") { let currentMsg = $('.msg:first'); log.debug('Reached top') - let passphrase: string; - let passphraseInput = document.getElementById('passphrase') as HTMLInputElement; - - if (passphraseInput == null) { - log.error('passphraseInput element reference is null'); - return; - } - passphrase = passphraseInput.value - if (passphrase == '' || passphrase == null) { - // alert('Please input passphrase') - // alertify.error('Please enter a passphrase'); - log.error('passphrase is empty or null'); - return; - } + let ab = this._userModel.activeUsersList.find(u => u.userName == JsonAPI.contactName) if (JsonAPI.contactName != null) - this._chatModel.getMessages(JsonAPI.contactName, passphrase, null, "page").then(() => { + this._chatModel.getMessages(JsonAPI.contactName, ab!.passphrase, null, "page").then(() => { if (currentMsg != null) { // log.debug(currentMsg.offset()!.top) $(this._messageContainer).scrollTop(currentMsg.position().top - $('.msg').position()!.top) diff --git a/chatto/src/main/javascript/ts/src/view/ChatViewDeps.ts b/chatto/src/main/javascript/ts/src/view/ChatViewDeps.ts index 9b127c8..83af2b9 100644 --- a/chatto/src/main/javascript/ts/src/view/ChatViewDeps.ts +++ b/chatto/src/main/javascript/ts/src/view/ChatViewDeps.ts @@ -3,6 +3,7 @@ import { ChatModel } from "../model/ChatModel"; import { MarkDownService } from "../service/MarkDownService"; import { EncryptionService } from "../service/EncryptionService"; import { NotificationService } from "../service/NotificationService"; +import { UserModel } from "../model/UserModel"; export interface ChatViewDeps { chatModel: ChatModel; @@ -11,5 +12,6 @@ export interface ChatViewDeps { messageReceiveTemplate: Handlebars.TemplateDelegate; markdownService: MarkDownService; encryptionService: EncryptionService; - notificationService: NotificationService + notificationService: NotificationService; + userModel: UserModel } \ No newline at end of file