-
+
diff --git a/src/app/pages/gabinete-digital/gabinete-digital.page.ts b/src/app/pages/gabinete-digital/gabinete-digital.page.ts index 285af08d2..fa90ee7a4 100644 --- a/src/app/pages/gabinete-digital/gabinete-digital.page.ts +++ b/src/app/pages/gabinete-digital/gabinete-digital.page.ts @@ -22,7 +22,7 @@ import { CustomTaskPipe } from 'src/app/pipes/custom-task.pipe'; //import { NotificationsService } from 'src/app/services/notifications.service'; import { DespachoService } from 'src/app/Rules/despacho.service'; import { ChangeProfileService } from 'src/app/services/change-profile.service'; -import { PermissionService } from 'src/app/services/worker/permission.service'; +import { PermissionService } from 'src/app/services/permission.service'; import { ThemeService } from 'src/app/services/theme.service' @@ -115,6 +115,9 @@ export class GabineteDigitalPage implements OnInit, DoCheck { customTaskPipe = new CustomTaskPipe() + permissions = { + Agenda: 530 + } @ViewChild(ExpedientsPage) expedientesPage: ExpedientsPage; @ViewChild(PendentesPage) pendentesListPage: PendentesPage; @ViewChild(EventsToApprovePage) eventsToApprove: EventsToApprovePage; @@ -256,7 +259,7 @@ export class GabineteDigitalPage implements OnInit, DoCheck { let date = new Date(element.taskStartDate); date.setMonth(date.getMonth() + 1); let taskDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); - + let task = { "SerialNumber": element.serialNumber, "Folio": element.workflowInstanceDataFields.Subject, @@ -274,11 +277,11 @@ export class GabineteDigitalPage implements OnInit, DoCheck { "Agenda": element.workflowInstanceDataFields.Agenda, "customDate": this.setFormatDate(new Date(element.workflowInstanceDataFields.StartDate), new Date(element.workflowInstanceDataFields.EndDate), element.workflowInstanceDataFields.IsAllDayEvent), } - + this.allProcessesList.push(task); this.allProcessesList = removeDuplicate(this.allProcessesList); this.allProcessesList = this.sortService.sortDate(this.allProcessesList, 'CreateDate') - + }); }) } else { @@ -287,9 +290,9 @@ export class GabineteDigitalPage implements OnInit, DoCheck { let date = new Date(element.taskStartDate); date.setMonth(date.getMonth() + 1); let taskDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(); - + var workflowInstanceDataFields = JSON.parse(element.workflowInstanceDataFields); - + let task = { "SerialNumber": element.serialNumber, "Folio": workflowInstanceDataFields.Subject, @@ -306,11 +309,11 @@ export class GabineteDigitalPage implements OnInit, DoCheck { "Agenda": workflowInstanceDataFields.Agenda, "customDate": this.setFormatDate(new Date(workflowInstanceDataFields.StartDate), new Date(workflowInstanceDataFields.EndDate), workflowInstanceDataFields.IsAllDayEvent), } - + this.allProcessesList.push(task); this.allProcessesList = removeDuplicate(this.allProcessesList) this.allProcessesList = this.sortService.sortDate(this.allProcessesList, 'CreateDate') - + }); console.log("All process from db ", allprocess) }) diff --git a/src/app/pages/gabinete-digital/pedidos/pedido/pedido.page.ts b/src/app/pages/gabinete-digital/pedidos/pedido/pedido.page.ts index 0874bd07e..79204effd 100644 --- a/src/app/pages/gabinete-digital/pedidos/pedido/pedido.page.ts +++ b/src/app/pages/gabinete-digital/pedidos/pedido/pedido.page.ts @@ -23,7 +23,7 @@ import { PedidoService } from 'src/app/Rules/pedido.service'; import { SqliteService } from 'src/app/services/sqlite.service'; import { BackgroundService } from 'src/app/services/background.service'; -import { PermissionService } from 'src/app/services/worker/permission.service'; +import { PermissionService } from 'src/app/services/permission.service'; import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page'; import { ThemeService } from 'src/app/services/theme.service' import { DataService } from 'src/app/services/data.service'; diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index 37a27b44f..9072eb405 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -12,6 +12,8 @@ import { ChangeProfileService } from 'src/app/services/change-profile.service'; import { ThemeService } from 'src/app/services/theme.service'; import { StorageService } from 'src/app/services/storage.service'; import { ChatService } from 'src/app/services/chat.service'; +import { PermissionService } from 'src/app/services/permission.service'; +import { PermissionList } from 'src/app/models/permissionList'; @Component({ selector: 'app-login', @@ -29,7 +31,8 @@ export class LoginPage implements OnInit { hasPin: boolean loginPreference: string - sessionStore = SessionStore + sessionStore = SessionStore; + permissionList = new PermissionList(); constructor( private notificatinsservice: NotificationsService, @@ -40,7 +43,8 @@ export class LoginPage implements OnInit { private clearStoreService: ClearStoreService, private changeProfileService: ChangeProfileService, public ThemeService: ThemeService, - private storageservice: StorageService + private storageservice: StorageService, + public permissionService: PermissionService, ) {} ngOnInit() { @@ -101,26 +105,29 @@ export class LoginPage implements OnInit { // login to API successfully if (attempt) { if (attempt.UserId == SessionStore.user.UserId) { + await this.authService.SetSession(attempt, this.userattempt); await this.authService.loginChat(); - await this.authService.loginToChatWs() + await this.authService.loginToChatWs(); this.getToken(); SessionStore.setInativity(true); - this.goback() + this.goback(); + } else { - this.clearStoreService.clear() - SessionStore.delete() + this.clearStoreService.clear(); + SessionStore.delete(); window.localStorage.clear(); await this.authService.SetSession(attempt, this.userattempt); - this.changeProfileService.run() + this.changeProfileService.run(); await this.authService.loginChat(); - await this.authService.loginToChatWs() + await this.authService.loginToChatWs(); this.getToken(); this.router.navigateByUrl('/pin', { replaceUrl: true }); + } } else{ @@ -141,7 +148,15 @@ export class LoginPage implements OnInit { if(pathName) { this.router.navigate([pathName]); } else { - this.router.navigate(['/home/events']); + if(this.permissionService.userPermission(this.permissionList.Agenda) || this.permissionService.userPermission(this.permissionList.Gabinete)){ + this.router.navigate(['/home/events']); + } + else if(this.permissionService.userPermission(this.permissionList.Chat)){ + this.router.navigate(['/home/chat']); + } + else if(this.permissionService.userPermission(this.permissionList.Actions)){ + this.router.navigate(['/home/publications']); + } } } diff --git a/src/app/pages/publications/view-publications/view-publications.page.html b/src/app/pages/publications/view-publications/view-publications.page.html index 847b460c5..91e993b76 100644 --- a/src/app/pages/publications/view-publications/view-publications.page.html +++ b/src/app/pages/publications/view-publications/view-publications.page.html @@ -33,7 +33,9 @@ -->
- +
diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index b28f8f4ec..f4f015d41 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -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(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] @@ -124,7 +131,6 @@ export class AuthService { let responseChat = await this.httpService.post('login', postData).toPromise(); if(responseChat) { - console.log('Login to Rocket chat OK', responseChat); this.ValidatedUserChat = responseChat; localStorage.setItem('userChat', JSON.stringify(responseChat)); @@ -149,7 +155,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 +175,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) diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 472164861..e4bdcc206 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -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' @@ -22,10 +24,10 @@ export class MessageService { msg = '' rid = '' ts = {} - - u = { - name: '', - username: '', + + u = { + name: '', + username: '', _id: "" } @@ -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 { this.sendAttempt++; @@ -138,7 +131,7 @@ export class MessageService { if(!this.hasFile) { const params = {roomId:this.rid, msg:this.msg, localReference: this.localReference} - + await this.sendRequest(params) } else { @@ -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 = {} @@ -178,7 +171,7 @@ export class MessageService { return new Promise((resolve, reject)=>{ reject(false) }) - + } } @@ -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 @@ -197,13 +195,8 @@ export class MessageService { this.WsChatService.registerCallback({ 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 } }) @@ -213,7 +206,7 @@ export class MessageService { async redefinedMessage(ChatMessage , update = true) { ChatMessage = this.NfService.fix_updatedAt(ChatMessage) - + const message = this.getChatObj() ChatMessage = Object.assign(message, ChatMessage) @@ -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() + } + }); } @@ -241,8 +259,7 @@ export class MessageService { } async delateDB() { - - // alert('delete data') + const message = await MessageModel.get({_id: this._id}) await message.delete() @@ -261,8 +278,8 @@ export class MessageService { return { channels: this.channels, mentions: this.mentions, - //msg: this.AESEncrypt.encrypt(this.msg, SessionStore.user.RochetChatUser), - msg:this.msg, + //msg: this.AESEncrypt.encrypt(this.msg, SessionStore.user.RochetChatUser), + msg:this.msg, rid: this.rid, ts: this.ts, u: this.u, @@ -294,6 +311,7 @@ export class MessageService { async save() { const message = this.getChatObj() + console.log(message); await MessageModel.update(message) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index f7f9bbd7f..b5099f4fe 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -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 { 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 diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 789d0a453..db3e320d7 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -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 diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 75df35da7..bfb47a6d9 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -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) } diff --git a/src/app/services/functions/initials.service.spec.ts b/src/app/services/functions/initials.service.spec.ts new file mode 100644 index 000000000..7ecc24a60 --- /dev/null +++ b/src/app/services/functions/initials.service.spec.ts @@ -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(); + }); +}); diff --git a/src/app/services/functions/initials.service.ts b/src/app/services/functions/initials.service.ts new file mode 100644 index 000000000..3615f4124 --- /dev/null +++ b/src/app/services/functions/initials.service.ts @@ -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; + } +} diff --git a/src/app/services/permission.service.spec.ts b/src/app/services/permission.service.spec.ts index 8ddccabff..1a77304d8 100644 --- a/src/app/services/permission.service.spec.ts +++ b/src/app/services/permission.service.spec.ts @@ -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; diff --git a/src/app/services/worker/permission.service.ts b/src/app/services/permission.service.ts similarity index 58% rename from src/app/services/worker/permission.service.ts rename to src/app/services/permission.service.ts index e093625c9..3587a5dc6 100644 --- a/src/app/services/worker/permission.service.ts +++ b/src/app/services/permission.service.ts @@ -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 { } -} \ No newline at end of file +} diff --git a/src/app/services/rules/event.service.ts b/src/app/services/rules/event.service.ts index c066e5223..a4f4e1be3 100644 --- a/src/app/services/rules/event.service.ts +++ b/src/app/services/rules/event.service.ts @@ -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) diff --git a/src/app/shared/chat/group-messages/group-messages.page.html b/src/app/shared/chat/group-messages/group-messages.page.html index 8032aa779..2e0a784e4 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -60,66 +60,75 @@
-
-
-
-
- - - - -
-
- {{msg.u.name}} - {{msg.duration}} -
-
-
-
-
- image - -
-
-
-
- - - - - - - {{file.title}} +
+
+
+
+ + + + +
+
+ {{msg.u.name}} + {{msg.duration}} +
+
+
+
+
+ NOT UPLOADED +
+
+ image + +
+
+
+
+ + + + + + + {{file.title}} +
+
+ + + {{file.title}} + + + +
+
+ +
+
+ + {{file.description}} + + {{msg.displayType}} +
-
- -
-
- - {{file.description}} - - {{msg.displayType}} -
+ {{last ? scrollToBottom() : ''}}
- {{last ? scrollToBottom() : ''}}
+
+ {{msg.u.name}} criou esta reunião
+
+ De {{showDateDuration(msg.file.start_date)}} a {{showDateDuration(msg.file.end_date)}}
+ {{msg.file.venue}}
+
-
- {{msg.u.name}} criou esta reunião
-
- De {{showDateDuration(msg.file.start_date)}} a {{showDateDuration(msg.file.end_date)}}
- {{msg.file.venue}}
-
-
-
- Apagou a mensagem -
- +
Alterou o nome do grupo para "{{msg.msg.split('-').join(' ')}}"
@@ -208,9 +217,9 @@ - + diff --git a/src/app/shared/chat/group-messages/group-messages.page.ts b/src/app/shared/chat/group-messages/group-messages.page.ts index 245533836..829ce53d3 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -274,20 +274,23 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe } async loadFiles() { + try { + this.storage.get('fileName').then((fileName) => { + this.lastAudioRecorded = fileName; + }) + + this.storage.get('recordData').then((recordData) => { + console.log(recordData); + if(recordData?.value?.recordDataBase64.includes('data:audio')){ + this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64); + } + else{ + this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`); + } + }); + } catch (error) {} - this.storage.get('fileName').then((fileName) => { - this.lastAudioRecorded = fileName; - }) - this.storage.get('recordData').then((recordData) => { - console.log(recordData); - if(recordData.value.recordDataBase64.includes('data:audio')){ - this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64); - } - else{ - this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`); - } - }); } startRecording() { @@ -417,41 +420,64 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe this.wsChatMethodsService.getGroupRoom(this.roomId).send({}) } - async sendAudio(fileName) { + base64toBlob(base64Data, contentType) { + contentType = contentType || ''; + var sliceSize = 1024; + var byteCharacters = atob(base64Data); + var bytesLength = byteCharacters.length; + var slicesCount = Math.ceil(bytesLength / sliceSize); + var byteArrays = new Array(slicesCount); + for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) { + var begin = sliceIndex * sliceSize; + var end = Math.min(begin + sliceSize, bytesLength); + + var bytes = new Array(end - begin); + for (var offset = begin, i = 0; offset < end; ++i, ++offset) { + bytes[i] = byteCharacters[offset].charCodeAt(0); + } + byteArrays[sliceIndex] = new Uint8Array(bytes); + } + return new Blob(byteArrays, { type: contentType }); +} + + async sendAudio(fileName) { const roomId = this.roomId + let audioFile; this.storage.get('recordData').then((recordData) => { console.log(recordData); - if(recordData.value.recordDataBase64.includes('data:audio')){ - this.audioRecorded = recordData.value.recordDataBase64; + audioFile = recordData; + if(recordData?.value?.recordDataBase64.includes('data:audio')){ + this.audioRecorded = recordData?.value?.recordDataBase64; } else{ - this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; + this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`; } - }); + //Converting base64 to blob - const base64Response = await fetch(this.audioRecorded); - const blob = await base64Response.blob(); - + const encodedData = btoa(this.audioRecorded); + const blob = this.base64toBlob(encodedData, recordData.value.mimeType) + console.log(blob) const formData = new FormData(); formData.append("blobFile", blob); this.wsChatMethodsService.getGroupRoom(roomId).send({ file: { "type": "application/audio", - /* "guid": '', */ + "msDuration":audioFile.value.msDuration, + "mimeType":audioFile.value.mimeType, }, attachments: [{ "title": fileName , - "title_link": this.audioRecorded, "title_link_download": true, - "type": "file" + "type": "audio" }], temporaryData: formData }) - this.deleteRecording(); + }); + this.deleteRecording(); } deleteMessage(msgId: string) { @@ -971,41 +997,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe downloadFileMsg(msg: MessageService) { - console.log('FILE TYPE', msg.file.type) - this.downloadFile = ""; - if (msg.file.type == "application/img") { - this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => { - console.log('FILE TYPE 22', msg.file.guid) - var name = msg.file.guid; - - if (event.type === HttpEventType.DownloadProgress) { - //this.downloadProgess = Math.round((100 * event.loaded) / event.total); - console.log('FILE TYPE 33', msg.file.type) - } else if (event.type === HttpEventType.Response) { - if (msg.file.type == "application/img") { - this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - } else if (msg.file.type === 'application/pdf') { - - this.downloadFile = event.body; - } - - msg.attachments[0] = { - image_url: this.downloadFile, - name: msg.attachments[0].name, - title: msg.attachments[0].title, - title_link_download: msg.attachments[0].title_link_download, - ts: msg.attachments[0].ts - } - - await this.storage.set(msg.file.guid, this.downloadFile).then(() => { - console.log('IMAGE SAVED') - }); - } - - }); - - } - + msg.downloadFileMsg() } async openPreview(msg) { @@ -1029,5 +1021,12 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe } + async audioPreview(msg) { + console.log(msg); + if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') { + this.downloadFileMsg(msg) + } else {} + } + } diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index f2b691ed3..7ec469275 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -35,7 +35,7 @@
+ *ngFor="let msg of wsChatMethodsService.getDmRoom(roomId).messages; index as i; let last = last">
@@ -49,12 +49,12 @@ {{msg.duration}}
- - {{msg.msg}} + + {{msg.msg}} Apagou a mensagem - + @@ -84,7 +84,6 @@
image - @@ -109,7 +108,15 @@ {{file.title}}
-
+
+ + + {{file.title}} + + + +
+
@@ -119,7 +126,7 @@ {{msg.displayType}} - + @@ -133,28 +140,30 @@
- {{msg.u.name}} criou esta reunião
-
- + De {{showDateDuration(msg.file.start_date)}} a {{showDateDuration(msg.file.end_date)}}
- + {{msg.file.venue}}
-
- Apagou a mensagem -
+
- + @@ -165,7 +174,7 @@ - +
- + diff --git a/src/app/shared/chat/messages/messages.page.scss b/src/app/shared/chat/messages/messages.page.scss index f594b8b3f..9933b4de3 100644 --- a/src/app/shared/chat/messages/messages.page.scss +++ b/src/app/shared/chat/messages/messages.page.scss @@ -227,6 +227,13 @@ margin-top: 4px; } + .chat-icon-download{ + font-size: 95px; + margin: 0 auto; + margin-top: 4px; + border: 1px solid red; + } + .type-message{ display: flex; border: 1px solid #ebebeb; @@ -329,3 +336,8 @@ display: block; .typing ngx-letters-avatar { padding-right: 5px; } + +.div-do-audio{ + border: 1px solid red !important; + overflow: auto; +} diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index d470e7306..b13432140 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -25,7 +25,6 @@ import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.serv import { WsChatService } from 'src/app/services/chat/ws-chat.service' import { MessageService } from 'src/app/services/chat/message.service'; import { AttachmentsService } from 'src/app/services/attachments.service'; - import { CameraService } from 'src/app/services/camera.service'; import { FileType } from 'src/app/models/fileType'; import { SearchPage } from 'src/app/pages/search/search.page'; @@ -250,10 +249,22 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } async loadFiles() { + try { + this.storage.get('fileName').then((fileName) => { + this.lastAudioRecorded = fileName; + }) + + this.storage.get('recordData').then((recordData) => { + console.log(recordData); + if (recordData?.value?.recordDataBase64.includes('data:audio')) { + this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64); + } + else { + this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`); + } + }); + } catch (error) { } - this.storage.get('fileName').then((fileName) => { - this.lastAudioRecorded = fileName; - }) this.storage.get('recordData').then((recordData) => { console.log(recordData); @@ -267,7 +278,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } startRecording() { - console.log('Recording'); if (this.recording) { return; @@ -354,64 +364,49 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.wsChatMethodsService.getDmRoom(this.roomId).send({}) } - async sendAudio(fileName) { + async sendAudio(fileName) { const roomId = this.roomId let audioFile; this.storage.get('recordData').then((recordData) => { console.log(recordData); audioFile = recordData; + if (recordData.value.recordDataBase64.includes('data:audio')) { this.audioRecorded = recordData.value.recordDataBase64; } - else { - this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; + else{ + this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`; } - }); + //Converting base64 to blob + const encodedData = btoa(this.audioRecorded); + const blob = this.base64toBlob(encodedData, recordData.value.mimeType) + console.log(blob) + const formData = new FormData(); + formData.append("blobFile", blob); - //Converting base64 to blob - const base64Response = await fetch(this.audioRecorded); - const blob = await base64Response.blob(); + this.wsChatMethodsService.getDmRoom(roomId).send({ + file: { + "type": "application/audio", + "msDuration": audioFile.value.msDuration, + "mimeType": audioFile.value.mimeType, + }, + attachments: [{ + "title": fileName, + "title_link_download": true, + "type": "audio" + }], + temporaryData: formData + }) - const formData = new FormData(); - formData.append("blobFile", blob); - - this.wsChatMethodsService.getDmRoom(roomId).send({ - file: { - "type": "application/audio", - /* "guid": '', */ - "msDuration": audioFile.value.msDuration, - "mimeType": audioFile.value.mimeType, - }, - attachments: [{ - "title": fileName, - "title_link": this.audioRecorded, - "title_link_download": true, - "type": "audio" - }], - temporaryData: formData - }) + }); this.deleteRecording(); - } + deleteMessage(msgId: string, msg: MessageService) { - - /* msg.delateStatusFalse() - this.wsChatMethodsService.getDmRoom(this.roomId).sendDeleteRequest(msgId) */ - - } - - async viewDocument(msg: any, url?: string) { - if (msg.file.type == "application/img") { - let response: any = await this.AttachmentsService.getFile(msg.file.guid).toPromise(); - console.log(response); - alert(response); - - //this.openPreview(msg); - - } - else if (msg.file.type == "application/webtrix") { + this.wsChatMethodsService.getDmRoom(this.roomId).sendDeleteRequest(msgId) + if (msg.file.type == "application/webtrix") { this.openViewDocumentModal(msg.file); } else { @@ -955,6 +950,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy DocumentViewer.viewDocument } + async audioPreview(msg) { + console.log(msg); + if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') { + this.downloadFileMsg(msg) + } else { } + } + async openPreview(msg) { console.log(msg); @@ -962,22 +964,22 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.downloadFileMsg(msg) - /* } else if (msg.file.type === "application/pdf") { - - - console.log(str); - const win = window.open("", "_blank"); - let html = ''; - - html += ''; - html += ''; - html += '