Merge branch 'developer' of bitbucket.org:equilibriumito/gabinete-digital into developer

This commit is contained in:
tiago.kayaya
2022-03-29 00:11:33 +01:00
44 changed files with 533 additions and 504 deletions
+13 -2
View File
@@ -18,6 +18,7 @@ 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';
import { InitialsService } from './functions/initials.service';
@Injectable({
providedIn: 'root'
@@ -44,7 +45,8 @@ export class AuthService {
private NfService:NfService,
private processesService: ProcessesService,
private AttachmentsService: AttachmentsService,
private storage: Storage ) {
private storage: Storage,
private initialsService: InitialsService ) {
this.headers = new HttpHeaders();
@@ -74,6 +76,8 @@ export class AuthService {
try {
response = await this.http.post<LoginUserRespose>(environment.apiURL + "UserAuthentication/Login", '', this.opts).toPromise();
console.log(response);
if(saveSession) {
this.SetSession(response, user)
}
@@ -94,6 +98,9 @@ export class AuthService {
} else if(session.RoleID == 100000011) {
session.Profile = 'MDGPR'
}
else{
session.Profile = this.initialsService.getInitials(session.FullName);
}
session.Password = user.password
session.RochetChatUser = user.username.split('@')[0]
@@ -149,7 +156,7 @@ export class AuthService {
this.WsChatService.connect();
this.WsChatService.login().then((message: any) => {
SessionStore.user.RochetChatUserId = message.result.id
SessionStore.save()
this.WsChatService.setStatus('online')
@@ -169,11 +176,15 @@ export class AuthService {
try {
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
message.file.guid = guid.path
console.log('========================================',guid)
// await this.storage.set(guid.path, message.file.image_url).then(() => {
// console.log('add picture to chat IMAGE SAVED')
// // message.getFileFromDb()
// });
message.downloadFileMsg()
return true
} catch(e) {
console.log('failed to upload to server', e)
+46 -29
View File
@@ -10,6 +10,8 @@ import { ChatStorageService } from './chat-storage.service'
import { ChatMethodsService } from './chat-methods.service'
import { MessageModel, DeleteMessageModel } from '../../models/beast-orm'
import { AESEncrypt } from '../aesencrypt.service'
import { HttpClient, HttpEventType } from '@angular/common/http';
import { AttachmentsService } from 'src/app/services/attachments.service';
@Injectable({
providedIn: 'root'
@@ -59,7 +61,8 @@ export class MessageService {
private WsChatService: WsChatService,
private ChatStorageService: ChatStorageService,
private ChatMethodsService: ChatMethodsService,
private AESEncrypt: AESEncrypt) {
private AESEncrypt: AESEncrypt,
private AttachmentsService: AttachmentsService,) {
}
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, }:Message) {
@@ -74,17 +77,21 @@ export class MessageService {
this._id = _id
this._updatedAt = _updatedAt || new Date().getTime()
this.file = file
this.attachments = attachments
this.temporaryData = temporaryData
this.localReference = localReference || null
this.id = id
this.delate = delate
this.delateRequest = delateRequest
if(this.attachments?.length >= 1 && attachments?.length >= 1) {
this.attachments[0] = Object.assign(this.attachments[0], attachments[0])
} else {
this.attachments = attachments
}
this.viewed = [...new Set([...viewed,...this.viewed])];
this.received = [...new Set([...received,...this.received])];
if(!this.ts) {
this.offline = true
this.messageSend = false
@@ -102,7 +109,6 @@ export class MessageService {
}
if(this.hasFile) {
// this.getFileFromDb()
if(this.file.type != 'application/webtrix') {
this.displayType = this.file.type.replace('application/','').toUpperCase()
}
@@ -118,19 +124,6 @@ export class MessageService {
return firstName + ' ' + lastName
}
// getFileFromDb() {
// if(this.hasFile) {
// if (this.file.guid) {
// this.storage.get(this.file.guid).then((image) => {
// if(image != null) {
// this.file.image_url = image
// }
// });
// }
// }
// }
async send(): Promise<any> {
this.sendAttempt++;
@@ -152,7 +145,7 @@ export class MessageService {
this.uploadingFile = false
if(uploadSuccessfully || this.hasSendAttachment == false) {
if(uploadSuccessfully) {
this.hasSendAttachment = true
this.errorUploadingAttachment = false
this.temporaryData = {}
@@ -186,6 +179,11 @@ export class MessageService {
}
async sendRequest(params) {
if(params?.attachments?.image_url) {
delete params?.attachments?.image_url
}
this.ChatMethodsService.send(params).subscribe(
(response: any) => {
const ChatMessage = response.message
@@ -198,12 +196,7 @@ export class MessageService {
type: 'reConnect',
funx: async ()=> {
this.WsChatService.send(params).then(({message, requestId}) => {
let ChatMessage = message.result
this.messageSend = true
this.redefinedMessage(ChatMessage)
})
this.send()
return true
}
})
@@ -222,11 +215,36 @@ export class MessageService {
await this.save()
}
async downloadFileMsg() {
const result = await this.NfService.beforeSendAttachment(this)
if(result) {
downloadFileMsg() {
}
let downloadFile = "";
this.AttachmentsService.downloadFile(this.file.guid).subscribe(async (event) => {
if (event.type === HttpEventType.DownloadProgress) {
} else if (event.type === HttpEventType.Response) {
if (this.file.type == "application/img") {
downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
} else if (this.file.type === 'application/pdf') {
downloadFile = event.body as any;
} else if (this.file.type == 'application/audio') {
downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '');
}
this.attachments[0] = {
image_url: downloadFile,
name: this.attachments[0].name,
title: this.attachments[0].title,
title_link: downloadFile,
title_link_download: this.attachments[0].title_link_download,
ts: this.attachments[0].ts
}
// save the changes to the storage
this.save()
}
});
}
@@ -242,7 +260,6 @@ export class MessageService {
async delateDB() {
// alert('delete data')
const message = await MessageModel.get({_id: this._id})
await message.delete()
+56 -39
View File
@@ -21,6 +21,7 @@ import { ChatMethodsService } from './chat-methods.service'
import { DeleteMessageModel, MessageModel } from '../../models/beast-orm'
import { AESEncrypt } from '../aesencrypt.service'
import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'src/app/models/message.model';
import { AttachmentsService } from 'src/app/services/attachments.service';
@Injectable({
providedIn: 'root'
@@ -75,7 +76,8 @@ export class RoomService {
private NfService: NfService,
private ChatStorageService: ChatStorageService,
private ChatMethodsService: ChatMethodsService,
private AESEncrypt: AESEncrypt
private AESEncrypt: AESEncrypt,
private AttachmentsService: AttachmentsService
) {
this.NativeNotificationService.askForPermission()
@@ -143,7 +145,7 @@ export class RoomService {
}
}
setData({members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt), _updatedAt }) {
setData({members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService), _updatedAt }) {
this.customFields = customFields
this.id = id
this.name = name
@@ -236,7 +238,6 @@ export class RoomService {
const args = message.fields.args
// alert(JSON.stringify(args))
if (typeof args[1] != 'object') {
@@ -269,7 +270,12 @@ export class RoomService {
getRoomMembersIds(): string[] {
return this.members.map((user)=> user._id)
try {
return this.members.map((user)=> user._id)
} catch(error) {
return []
}
}
getAllMemberThatIsNotOffline(): string[] {
@@ -357,37 +363,46 @@ export class RoomService {
* @description delete message in the view
* @param id message ID
*/
async deleteMessage(id) {
await this.messages.forEach(async(message, index) => {
if(message._id == id) {
this.messages.splice(index, 1)
async deleteMessage(_id) {
const id = _id
for (let i =0; i <= this.messages.length; i++) {
if(this.messages[i]?._id == id ) {
if (SessionStore.user.RochetChatUser == message.u.username) {
//Get previous last message from room
const previousLastMessage = this.messages.slice(-1)[0];
this.lastMessage = previousLastMessage;
this.calDateDuration(previousLastMessage._updatedAt)
this.sortRoomList()
if (SessionStore.user.RochetChatUser == this.messages[i]?.u?.username) {
const allMemberThatIsOffline = this.getAllMemberThatIsOffline()
await DeleteMessageModel.create({
messageId: message._id,
rid: message.rid,
ts: message.ts,
u: message.u,
DeleteMessageModel.create({
messageId: this.messages[i]._id,
rid: this.messages[i].rid,
ts: this.messages[i].ts,
u: this.messages[i].u,
needToReceiveBy: allMemberThatIsOffline
})
}
message.delateStatusFalse()
message.delateDB()
this.messages[i]?.delateDB()
//Get previous last message from room
const previousLastMessage = this.messages.slice(-1)[0];
// console.log(_id,'==',this.messages[i]?._id, true)
this.messages.splice(i, 1)
this.lastMessage = previousLastMessage;
this.calDateDuration(previousLastMessage._updatedAt)
this.sortRoomList()
return true
} else {
// console.log(_id,'==',this.messages[i]?._id, false)
}
})
}
}
@@ -411,22 +426,26 @@ export class RoomService {
async sendDeleteRequest(msgId) {
const message = this.messages.find((e)=>e._id = msgId)
message.delateStatusFalse()
const message = this.messages.find((e)=>e._id == msgId)
await message.delateStatusFalse()
this.ChatMethodsService.deleteMessage({_id:msgId, msgId:msgId, roomId:message.rid}).subscribe(
(response: any) => {
message.delateRequest = true
message.save()
this.deleteMessage(msgId)
},
(response) => {
async (response: any) => {
if (response.error.error.startsWith('No message found with the id of')) {
// alert('not found')
message.delateRequest = true
await message.save()
this.deleteMessage(msgId)
},
async (response) => {
if (response?.error?.error.startsWith('No message found with the id of')) {
this.deleteMessage(msgId)
message.delateRequest = true
await message.save()
} else {
// this.deleteMessage(DeletedMessageId)
this.WsChatService.registerCallback({
type: 'reConnect',
funx: async ()=> {
@@ -666,7 +685,7 @@ export class RoomService {
message = this.fix_updatedAt(message)
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt)
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
wewMessage.setData(message)
wewMessage.loadHistory = this.hasLoadHistory
@@ -694,8 +713,6 @@ export class RoomService {
}
async ChatMessageIsPresentInTheView(ChatMessage:ChatMessageInterface) {
let foundIndex;
@@ -725,7 +742,7 @@ export class RoomService {
async prepareCreate({message, save = true}): Promise<MessageService> {
message = this.fix_updatedAt(message)
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt)
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
wewMessage.setData(message)
wewMessage.loadHistory = this.hasLoadHistory
@@ -737,7 +754,7 @@ export class RoomService {
simplePrepareMessage(message) {
message = this.fix_updatedAt(message)
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt)
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
wewMessage.setData(message)
wewMessage.loadHistory = this.hasLoadHistory
@@ -19,6 +19,7 @@ import { AuthService } from '../auth.service';
import { ChatStorageService } from './chat-storage.service'
import { ChatMethodsService } from './chat-methods.service'
import { AESEncrypt } from '../aesencrypt.service'
import { AttachmentsService } from 'src/app/services/attachments.service';
@Injectable({
providedIn: 'root'
@@ -55,7 +56,8 @@ export class WsChatMethodsService {
private authService: AuthService,
private ChatStorageService: ChatStorageService,
private ChatMethodsService:ChatMethodsService,
private AESEncrypt: AESEncrypt
private AESEncrypt: AESEncrypt,
private AttachmentsService:AttachmentsService
) {
this.loggedUser = authService.ValidatedUserChat['data'];
@@ -158,7 +160,10 @@ export class WsChatMethodsService {
} catch(e){}
this.sortRoomList()
setTimeout(()=>{
this.sortRoomList()
}, 1000)
}
async getAllRooms () {
@@ -202,7 +207,11 @@ export class WsChatMethodsService {
console.log('save rooms', rooms)
await this.storage.set('Rooms', rooms);
this.sortRoomList()
setTimeout(()=>{
this.sortRoomList()
}, 1000)
this.loadingWholeList = false
}
@@ -305,7 +314,7 @@ export class WsChatMethodsService {
// create room
if(!this.roomExist(roomId)) {
let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt)
let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService)
room.setData(setData)
room.receiveMessage()
room.getAllUsers = this.getUsers
+1 -1
View File
@@ -728,7 +728,7 @@ export class WsChatService {
this.wsMsgQueue[requestId] = {message, requestId, loginRequired}
} else {
let messageStr = JSON.stringify(message)
console.log('messageStr', messageStr)
// console.log('messageStr', messageStr)
this.socket.send(messageStr)
}
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { InitialsService } from './initials.service';
describe('InitialsService', () => {
let service: InitialsService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(InitialsService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -0,0 +1,18 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class InitialsService {
constructor() { }
getInitials(name:string){
let names = name.split(' '),
initials = names[0].substring(0, 1).toUpperCase();
if (names.length > 1) {
initials += names[names.length - 1].substring(0, 1).toUpperCase();
}
return initials;
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
import { TestBed } from '@angular/core/testing';
import { PermissionService } from './worker/permission.service';
import { PermissionService } from './permission.service';
describe('PermissionService', () => {
let service: PermissionService;
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { SessionStore } from '../../store/session.service';
import { SessionStore } from '../store/session.service';
@Injectable({
providedIn: 'root'
@@ -15,12 +15,28 @@ export class PermissionService {
if(!Array.isArray(args)) {
args = [args]
}
return args.includes(this.SessionStore.user.Profile)
return args.includes(this.SessionStore.user.Profile)
}
userPermission(args) {
if(!Array.isArray(args)) {
args = [args]
}
for(let permission of (this.SessionStore.user.UserPermissions || [])){
if (args.includes(permission)){
return true;
}
}
return false;
}
role(args: any) {
let UserRoleIsValid = this.userRole(args)
return {
@@ -39,4 +55,4 @@ export class PermissionService {
}
}
}
+2 -2
View File
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { AttachmentsService } from '../attachments.service';
import { EventsService } from '../events.service';
import { PermissionService } from '../worker/permission.service';
import { PermissionService } from '../permission.service';
@@ -18,7 +18,7 @@ export class EventService {
create({body, calendar}) {
if(this.p.userRole(['PR'])) {
return this.eventService.postEventPr(body, calendar)