2020-01-27 16:13:38 +00:00
import { Builder } from "builder-pattern" ;
2019-12-06 14:21:07 +00:00
import * as Handlebars from "handlebars" ;
import * as log from 'loglevel' ;
2020-01-27 16:13:38 +00:00
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 { AlertifyNotificationService } from "./service/AlertifyNotificationService" ;
import { EncryptionServiceFactory } from "./service/EncryptionServiceFactory" ;
2019-12-08 14:16:09 +00:00
import { FuseSearchService } from "./service/FuseSearchService" ;
2020-01-27 16:13:38 +00:00
import { MarkDownItMarkDownService } from "./service/MarkDownItMarkDownService" ;
2019-12-11 05:26:16 +00:00
import { NotificationService } from "./service/NotificationService" ;
2020-01-27 16:13:38 +00:00
import { SearchService } from "./service/SearchService" ;
2019-12-11 10:30:45 +00:00
import { TemplateFactory } from "./template/TemplateFactory" ;
2020-01-27 16:13:38 +00:00
import { ChatView } from "./view/ChatView" ;
2019-12-11 10:30:45 +00:00
import { ChatViewDeps } from "./view/ChatViewDeps" ;
2020-01-27 16:13:38 +00:00
import { UserView } from "./view/UserView" ;
import { UserViewDeps } from "./view/UserViewDeps" ;
import { ActiveUserViewModel } from "./viewmodel/ActiveUserViewModel" ;
2020-02-01 10:56:27 +00:00
import moment = require ( "moment" ) ;
2020-01-27 16:13:38 +00:00
log . setLevel ( "TRACE" ) ;
2019-12-02 12:00:00 +00:00
2019-12-08 14:16:09 +00:00
const usersListElement = document . getElementById ( 'contacts-box' ) ;
const userSearchButton = document . getElementById ( 'user-search' ) ;
2019-12-11 10:30:45 +00:00
const userSearchInputElement = document . getElementById ( 'user-search-term' ) as HTMLInputElement ;
const userSearchCancelButton = document . getElementById ( 'user-search-cancel' ) ;
2020-01-27 16:13:38 +00:00
const chatArea = document . getElementById ( 'chat-area-new' ) ;
2019-12-11 18:04:42 +00:00
const activeUserSearchService : SearchService < ActiveUserViewModel > = new FuseSearchService ( [ "userName" ] ) ;
2020-01-27 16:13:38 +00:00
const ns : NotificationService = new AlertifyNotificationService ( ) ;
const encryptionService = EncryptionServiceFactory . getEncryptionService ( ) ;
2019-12-06 14:21:07 +00:00
2019-12-02 12:00:00 +00:00
2019-12-06 14:21:07 +00:00
2020-01-27 16:13:38 +00:00
const chatModelHelper = new ChatModelHelper ( encryptionService , ns ) ;
const chatModel = new ChatModel ( chatModelHelper ) ;
2020-03-15 07:20:22 +00:00
const userModel = new UserModel ( ns ) ;
2020-01-27 16:13:38 +00:00
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'.
messageContainer : chatArea ,
messageSendTemplate : TemplateFactory.getTemplate ( 'msg_container_send_template' ) ,
messageReceiveTemplate : TemplateFactory.getTemplate ( 'msg_container_template' ) ,
markdownService : new MarkDownItMarkDownService ,
encryptionService : encryptionService ,
2020-03-15 07:20:22 +00:00
notificationService : ns ,
userModel : userModel
2020-01-27 16:13:38 +00:00
}
const chatView = new ChatView ( cvDeps ) ;
chatModel . attach ( chatView ) ;
const chatController = new ChatController ( chatModel , chatView ) ;
2019-12-11 10:30:45 +00:00
2020-01-27 16:13:38 +00:00
2020-03-15 07:20:22 +00:00
2019-12-11 10:30:45 +00:00
const uvDeps : UserViewDeps = {
model : userModel ,
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'.
usersListElement : usersListElement ,
userSearchInputElement : userSearchInputElement ,
// @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
userSearchButton : userSearchButton ,
// @ts-ignore: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'HTMLElement'. Type 'null' is not assignable to type 'HTMLElement'.
userSearchCancelButton : userSearchCancelButton ,
2019-12-11 18:04:42 +00:00
searchService : activeUserSearchService ,
2019-12-11 10:30:45 +00:00
userContactOnlineTemplate : TemplateFactory.getTemplate ( 'user-contact-online-template' ) ,
2020-02-14 13:48:22 +00:00
userContactOfflineTemplate : TemplateFactory.getTemplate ( 'user-contact-offline-template' ) ,
notificationService : ns
2019-12-11 10:30:45 +00:00
}
const userView = new UserView ( uvDeps ) ;
2019-12-02 12:00:00 +00:00
userModel . attach ( userView ) ;
const userController = new UserController ( userModel , userView ) ;
2019-12-07 06:00:51 +00:00
userController . getActiveUsers ( ) ;
2020-03-19 06:24:30 +00:00
// @ts-ignore
Handlebars . registerHelper ( 'moment' , require ( 'helper-moment' ) ) ;
2019-12-11 10:30:45 +00:00
Handlebars . registerHelper ( 'avatar' , function ( ) {
2019-12-06 14:21:07 +00:00
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>' ;
2019-12-08 14:16:09 +00:00
} ) ;
2020-02-01 10:56:27 +00:00
Handlebars . registerHelper ( 'fromNow' , function ( date : string ) {
2020-02-14 13:48:22 +00:00
if ( date == null )
return ": Never"
2020-02-01 10:56:27 +00:00
return moment ( date ) . fromNow ( ) ;
} )
2020-02-13 12:55:57 +00:00
Handlebars . registerHelper ( 'msgDateFormat' , function ( date : string ) {
return moment ( date ) . calendar ( moment . now ( ) , { lastWeek : "DD/MM/YY hh:mm A" , sameElse : "DD/MM/YY hh:mm A" } )
2020-02-01 10:56:27 +00:00
} )
2019-12-08 14:16:09 +00:00
2020-02-14 13:48:22 +00:00
Handlebars . registerHelper ( 'lockIcon' , function ( unlocked : boolean ) {
switch ( unlocked ) {
case true : { return '<i class="fas fa-lock-open user-passphrase"></i>' ; }
default : { return '<i class="fas fa-lock user-passphrase"></i>' ; }
}
} )
2019-12-11 10:30:45 +00:00
2020-01-27 16:13:38 +00:00
2019-12-11 05:26:16 +00:00
ns . success ( "Welcome" ) ;
2019-12-11 18:04:42 +00:00
// ns.errorWithDelay("Hmm very long error notif", 10);
2019-12-12 07:38:53 +00:00
const test = Builder < UserViewDeps > ( ) . build ( ) ;
2019-12-12 12:53:41 +00:00