This commit is contained in:
Peter Maquiran
2022-02-07 17:55:00 +01:00
parent 2caaad7f2b
commit e03fb2b413
14 changed files with 333 additions and 379 deletions
+4 -4
View File
@@ -3,8 +3,8 @@ import { Attachment, EventAttachment } from '../models/attachment.model';
import { Observable } from 'rxjs';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { AuthService } from '../services/auth.service';
import { LoginUserRespose } from '../models/user.model';
import { SessionStore } from '../store/session.service';
@Injectable({
providedIn: 'root'
@@ -14,10 +14,10 @@ export class AttachmentsService {
loggeduser: LoginUserRespose;
headers: HttpHeaders;
constructor(private http: HttpClient, user: AuthService) {
this.loggeduser = user.ValidatedUser;
constructor(private http: HttpClient) {
this.loggeduser = SessionStore.user
this.headers = new HttpHeaders();
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey);
}
uploadFile(formData:any) {
+54 -18
View File
@@ -12,6 +12,12 @@ import { AESEncrypt } from '../services/aesencrypt.service';
import { CookieService } from 'ngx-cookie-service';
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
import { Router } from '@angular/router';
import { NfService } from 'src/app/services/chat/nf.service'
import { MessageService } from 'src/app/services/chat/message.service';
import { ProcessesService } from 'src/app/services/processes.service';
import { AttachmentsService } from 'src/app/services/attachments.service';
import { RoomService } from './chat/room.service';
import { Storage } from '@ionic/storage';
@Injectable({
providedIn: 'root'
})
@@ -33,7 +39,11 @@ export class AuthService {
private aesencrypt: AESEncrypt,
private cookieService: CookieService,
private WsChatService: WsChatService,
private router: Router,) {
private router: Router,
private NfService:NfService,
private processesService: ProcessesService,
private AttachmentsService: AttachmentsService,
private storage: Storage ) {
this.headers = new HttpHeaders();
@@ -41,13 +51,7 @@ export class AuthService {
this.ValidatedUser = SessionStore.user
console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password)
this.WsChatService.connect();
this.WsChatService.login().then((message) => {
console.log('rocket chat login successfully', message)
this.WsChatService.setStatus('busy')
}).catch((message)=>{
console.log('rocket chat login failed', message)
})
this.loginToChatWs()
}
@@ -115,16 +119,7 @@ export class AuthService {
if(responseChat) {
setTimeout(()=>{
this.WsChatService.connect();
this.WsChatService.login().then((message) => {
console.log('rocket chat login successfully', message)
this.WsChatService.setStatus('online')
}).catch((message)=>{
console.log('rocket chat login failed', message)
})
}, 1)
this.loginToChatWs()
console.log('Login to Rocket chat OK');
this.ValidatedUserChat = responseChat;
@@ -143,6 +138,47 @@ export class AuthService {
}
}
private loginToChatWs() {
setTimeout(()=>{
this.WsChatService.connect();
this.WsChatService.login().then((message) => {
console.log('rocket chat login successfully', message)
this.WsChatService.setStatus('online')
}).catch((message)=>{
console.log('rocket chat login failed', message)
})
this.NfService.beforeSendAttachment = async (message: MessageService, room?: RoomService) => {
if(message.hasFile) {
if(message.file.type != 'application/webtrix') {
const formData = message.temporaryData
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
message.file.guid = guid.path
await this.storage.set(guid.path, message.file.image_url).then(() => {
console.log('add picture to chat IMAGE SAVED')
message.getFileFromDb()
});
return true
} else {
const res = message.temporaryData
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
message.attachments[0].title_link = url_no_options
message.attachments[0].message_link = url_no_options
return true
}
}
return false
}
}, 1)
}
autologout(expirationDate:number){
setTimeout(()=>{
this.logout();
+16 -10
View File
@@ -3,6 +3,7 @@ import { Message } from 'src/app/models/chatMethod';
import { Storage } from '@ionic/storage';
import { SessionStore } from 'src/app/store/session.service';
import { capitalizeTxt } from 'src/plugin/text'
import { NfService } from 'src/app/services/chat/nf.service'
@Injectable({
providedIn: 'root'
@@ -23,9 +24,12 @@ export class MessageService {
attachments
offline = true
displayType = ''
temporaryData = {}
temporaryData: any = {}
hasFile = false
hasSendAttachment = false
constructor(private storage: Storage) {
constructor(private storage: Storage,
private NfService: NfService) {
}
setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments, temporaryData}:Message) {
@@ -49,18 +53,20 @@ export class MessageService {
this.offline = false
}
if (this.file) {
this.getFileFromDb()
if(this.file.type) {
if(this.file.type != 'application/webtrix' && typeof(this.file.type) == 'string') {
this.displayType = this.file.type.replace('application/','').toUpperCase()
if(typeof(this.file.type) == 'string') {
this.hasFile = true
}
}
}
if(this.hasFile) {
this.getFileFromDb()
if(this.file.type != 'application/webtrix') {
this.displayType = this.file.type.replace('application/','').toUpperCase()
}
}
}
private usernameToDisplayName(username) {
@@ -71,13 +77,13 @@ export class MessageService {
}
getFileFromDb() {
if (this.file) {
if(this.hasFile) {
if (this.file.guid) {
this.storage.get(this.file.guid).then((image) => {
if(image != null) {
this.file.image_url = image
}
});
}
}
+5
View File
@@ -1,9 +1,14 @@
import { Injectable } from '@angular/core';
import { MessageService } from './message.service';
import { RoomService } from './room.service';
@Injectable({
providedIn: 'root'
})
export class NfService {
beforeSendAttachment = (message: MessageService, room?: RoomService): Promise<boolean> => new Promise ((resolve, reject)=> (resolve(true)))
constructor() { }
}
+17 -13
View File
@@ -14,6 +14,7 @@ import { SortService } from '../functions/sort.service';
import { chatUser } from 'src/app/models/chatMethod';
import { environment } from 'src/environments/environment';
import { ChatService } from 'src/app/services/chat.service';
import { NfService } from 'src/app/services/chat/nf.service'
@Injectable({
providedIn: 'root'
@@ -63,11 +64,12 @@ export class RoomService {
private NativeNotificationService: NativeNotificationService,
private sortService: SortService,
private chatService: ChatService,
private NfService: NfService
) {
this.NativeNotificationService.askForPermission()
}
setData({ customFields, id, name, t, lastMessage = new MessageService(this.storage), _updatedAt }) {
setData({ customFields, id, name, t, lastMessage = new MessageService(this.storage, this.NfService), _updatedAt }) {
this.customFields = customFields
this.id = id
this.name = name
@@ -232,19 +234,21 @@ export class RoomService {
})
} else {
console.log('complex send')
return {
message: message,
updateMessage: (update)=> {
offlineChatMessage = Object.assign(offlineChatMessage, update)
const result = this.NfService.beforeSendAttachment(message, this)
delete message.temporaryData;
if(result) {
message.hasSendAttachment = true
this.WsChatService.send({roomId:this.id, msg:message.msg,attachments:offlineChatMessage.attachments, file:offlineChatMessage.file}).then((data: any) => {
console.log('send sucees', data.result)
let ChatMessage = data.result
this.redefinedMessage(message, ChatMessage)
})
}
this.WsChatService.send({roomId:this.id, msg:message.msg, attachments:offlineChatMessage.attachments, file:offlineChatMessage.file}).then((data: any) => {
console.log('send sucees', data.result)
let ChatMessage = data.result
this.redefinedMessage(message, ChatMessage)
})
}
}
@@ -398,7 +402,7 @@ export class RoomService {
prepareMessage(message): MessageService {
message = this.fix_updatedAt(message)
const wewMessage = new MessageService(this.storage)
const wewMessage = new MessageService(this.storage, this.NfService)
wewMessage.setData(message)
this.messages.push(wewMessage)
@@ -12,7 +12,7 @@ import { ChatService } from 'src/app/services/chat.service';
import { NativeNotificationService } from 'src/app/services/native-notification.service';
import { SortService } from '../functions/sort.service';
import { chatUser } from 'src/app/models/chatMethod';
import { NfService } from 'src/app/services/chat/nf.service'
@Injectable({
providedIn: 'root'
})
@@ -41,7 +41,8 @@ export class WsChatMethodsService {
private sqlservice: SqliteService,
private NativeNotificationService: NativeNotificationService,
private sortService: SortService,
private ChatService: ChatService
private ChatService: ChatService,
private NfService: NfService
) {
(async()=>{
await this.getAllRooms();
@@ -203,7 +204,7 @@ export class WsChatMethodsService {
prepareRoom(roomData) {
let room:RoomService;
room = new RoomService(this.WsChatService, new MessageService(this.storage), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService)
room = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService)
room.setData({
customFields: roomData.customFields,
+3 -5
View File
@@ -1,6 +1,5 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { AuthService } from '../services/auth.service';
import { LoginUserRespose } from '../models/user.model';
import { environment } from 'src/environments/environment';
import { Observable } from 'rxjs';
@@ -10,7 +9,7 @@ import { ExpedienteFullTask } from '../models/Expediente';
import { GetTasksListType } from '../models/GetTasksListType';
import { fullTaskList } from '../models/dailyworktask.model';
import { ChangeProfileService } from './change-profile.service';
import { SessionStore } from '../store/session.service';
@Injectable({
providedIn: 'root'
})
@@ -22,15 +21,14 @@ export class ProcessesService {
constructor(
private http: HttpClient,
public user: AuthService,
private changeProfileService: ChangeProfileService
) {
this.loggeduser = this.user.ValidatedUser;
this.loggeduser = SessionStore.user;
this.setHeader()
this.changeProfileService.registerCallback(()=>{
this.loggeduser = this.user.ValidatedUser;
this.loggeduser = SessionStore.user;
this.setHeader()
})