Browse Source

Changes to page loading

Chat message pages now use passphrases from the stored model.
master
Rohan Sircar 4 years ago
parent
commit
ff43977f93
  1. 6
      chatto/src/main/javascript/ts/src/main.ts
  2. 20
      chatto/src/main/javascript/ts/src/view/ChatView.ts
  3. 4
      chatto/src/main/javascript/ts/src/view/ChatViewDeps.ts

6
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,

20
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<ChatMessageViewModel> {
private readonly _chatModel: ChatModel;
@ -21,6 +22,7 @@ export class ChatView implements Observer<ChatMessageViewModel> {
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<ChatMessageViewModel> {
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<ChatMessageViewModel> {
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)

4
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<ChatMessageViewModel>;
markdownService: MarkDownService;
encryptionService: EncryptionService;
notificationService: NotificationService
notificationService: NotificationService;
userModel: UserModel
}
Loading…
Cancel
Save