From da416f45ae584e6d51139824a9c2874d603c5d48 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Mon, 24 Jan 2022 14:57:05 +0100 Subject: [PATCH 01/16] save --- src/app/services/chat/ws-chat.service.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 838209d56..052a8c78e 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -277,8 +277,6 @@ export class WsChatService { streamNotifyLogged() { - alert('HERE') - const requestId = uuidv4() const message = { From f85d55cae78aa090f7cbfd489cd524e7ea1e19f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Tue, 25 Jan 2022 14:36:31 +0100 Subject: [PATCH 02/16] send image display done --- src/app/services/functions/file.service.ts | 108 ++++++++++++--------- 1 file changed, 61 insertions(+), 47 deletions(-) diff --git a/src/app/services/functions/file.service.ts b/src/app/services/functions/file.service.ts index cc7576c52..0d80e6506 100644 --- a/src/app/services/functions/file.service.ts +++ b/src/app/services/functions/file.service.ts @@ -13,7 +13,7 @@ import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera import { Filesystem, Directory } from '@capacitor/filesystem'; import { environment } from 'src/environments/environment'; import { HttpClient, HttpEventType, HttpHeaders, HttpParams } from '@angular/common/http'; - +import { Storage } from '@ionic/storage'; const IMAGE_DIR = 'stored-images'; @@ -53,6 +53,7 @@ export class FileService { private platform: Platform, private loadingCtrl: LoadingController, private http: HttpClient, + private storage: Storage ) { this.headers = new HttpHeaders(); } @@ -354,70 +355,83 @@ export class FileService { //loader.remove(); }); */ } + addPictureToChat(roomId) { - addPictureToChat(roomId) { + console.log('add picture to chat') - console.log('add picture to chat') - - const input = this.fileLoaderService.createInput({ - accept: ['image/apng', 'image/jpeg', 'image/png'] - }) + const input = this.fileLoaderService.createInput({ + accept: ['image/apng', 'image/jpeg', 'image/png'] + }) - setInterval(()=>{ - console.log(input.value) - }, 550) + setInterval(() => { + console.log(input.value) + }, 550) - input.onchange = async () => { + input.onchange = async () => { - //alert('Onchange AQUI') + //alert('Onchange AQUI') - const file = this.fileLoaderService.getFirstFile(input) + const file = this.fileLoaderService.getFirstFile(input) - console.log(file); + console.log(file); - const formData = new FormData(); - formData.append("blobFile", file); - let guid: any = await this.uploadFile(formData).toPromise() - console.log('add picture to chat',guid.path); + const formData = new FormData(); + formData.append("blobFile", file); + let guid: any = await this.uploadFile(formData).toPromise() + console.log('add picture to chat', guid.path); + this.downloadFile(guid.path).subscribe(async (event) => { - /* const imageData = await this.fileToBase64Service.convert(file) - this.capturedImage = imageData; */ - this.capturedImageTitle = file.name; + 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) { + var fileImage = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); + console.log('add picture to chat',fileImage); + await this.storage.set(guid, fileImage).then(() => { + console.log('add picture to chat IMAGE SAVED') - let body = { - "message": - { - "rid": roomId, - "msg": "", - "attachments": [{ - //"title": this.capturedImageTitle , - //"text": "description", - "title_link_download": false, - //"image_url": this.capturedImage, - }], - "file":{ - "type": "application/img", - "guid": guid.path, - "image_url": "" + let body = { + "message": + { + "rid": roomId, + "msg": "", + "attachments": [{ + //"title": this.capturedImageTitle , + //"text": "description", + "title_link_download": false, + //"image_url": this.capturedImage, + }], + "file": { + "type": "application/img", + "guid": guid.path, + "image_url": fileImage + } + } } - } + + console.log('SELECT PICTURE GALLERY', body) + console.log(this.capturedImage) + + this.chatService.sendMessage(body).subscribe(res => { + + console.log('Msg after send image', res); + }, (error) => { + console.log('Msg after send image error', error); + }); + }); } - console.log('SELECT PICTURE GALLERY', body) - console.log(this.capturedImage) + }); - this.chatService.sendMessage(body).subscribe(res=> { + /* const imageData = await this.fileToBase64Service.convert(file) + this.capturedImage = imageData; */ - console.log('Msg after send image',res); - },(error) => { - console.log('Msg after send image error',error); - }); - //console.log(this.capturedImage) - }; - } + //console.log(this.capturedImage) + }; +} addDocumentToChat(roomId:string) { const input = this.fileLoaderService.createInput({ From 7325a76718cda6b4669d0a68e3d9e3a6b1a210d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Tue, 25 Jan 2022 16:50:58 +0100 Subject: [PATCH 03/16] publication --- .../view-publications/view-publications.page.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/pages/publications/view-publications/view-publications.page.ts b/src/app/pages/publications/view-publications/view-publications.page.ts index d95ba7411..f81eb7b19 100644 --- a/src/app/pages/publications/view-publications/view-publications.page.ts +++ b/src/app/pages/publications/view-publications/view-publications.page.ts @@ -144,16 +144,16 @@ export class ViewPublicationsPage implements OnInit { console.log('publications ids', res) this.publicationList = new Array(); - for(let i of res) { + /* for(let i of res) { this.publications.GetPublicationById(i).subscribe(ress => { console.log('publications by ids', ress) let item: Publication = this.publicationPipe.itemList(ress) console.log('publications by ids 2', item) this.publicationList.push(item); }) - } + } */ - /* res.forEach(element => { + res.forEach(element => { console.log('publications elements', element) this.publications.GetPublicationById(element).subscribe(ress => { console.log('publications by ids', ress) @@ -162,7 +162,7 @@ export class ViewPublicationsPage implements OnInit { this.publicationList.push(ress); }) - }); */ + }); this.sqliteservice.updateactions(this.folderId, JSON.stringify(this.publicationList)); From 81632c5296aaf1fecc18c96cb9968502e0a357b6 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Wed, 26 Jan 2022 12:51:24 +0100 Subject: [PATCH 04/16] save --- src/app/pages/chat/chat.page.ts | 3 +- .../group-contacts/group-contacts.page.ts | 15 ++++----- .../group-messages/group-messages.page.ts | 32 ++++++------------- 3 files changed, 18 insertions(+), 32 deletions(-) diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index b0c731cdb..cadd6c5fb 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -298,6 +298,7 @@ export class ChatPage implements OnInit { this.openGroupMessagesModal(rid); } else { + alert('HERE OPEN') this.idSelected = rid; this.closeAllDesktopComponents(); this.showEmptyComponent = false; @@ -548,7 +549,7 @@ export class ChatPage implements OnInit { return dateB - dateA; }); - + //console.log('GROUPS FROM DB', this.allGroups) }) diff --git a/src/app/shared/chat/group-messages/group-contacts/group-contacts.page.ts b/src/app/shared/chat/group-messages/group-contacts/group-contacts.page.ts index 63173ed2f..53a2394cb 100644 --- a/src/app/shared/chat/group-messages/group-contacts/group-contacts.page.ts +++ b/src/app/shared/chat/group-messages/group-contacts/group-contacts.page.ts @@ -134,12 +134,9 @@ export class GroupContactsPage implements OnInit { updateGroup(){ this.showLoader = true; - this.chatService.getRoomInfo(this.roomId).subscribe(room=>{ - this.room = room['room']; - this.addContacts(this.room); - this.showLoader = false; - this.openGroupMessage.emit(this.room._id); - }); + this.addContacts(this.roomId); + this.openGroupMessage.emit(this.roomId); + this.showLoader = false; } openGroupMessagesPage(){ this.showLoader = true; @@ -259,15 +256,15 @@ export class GroupContactsPage implements OnInit { user.isChecked = !user.isChecked; } - addContacts(room:any){ - console.log(room); + addContacts(roomId:any){ + console.log(roomId); this.selectedUserList = this.users.filter(function(contact) { return contact.isChecked == true; }); console.log( this.selectedUserList); this.selectedUserList.forEach(user=>{ let body ={ - "roomId":room._id, + "roomId":roomId, "userId":user._id, } this.chatService.addUserToGroup(body).subscribe(res=>{ 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 71a7b751c..37f8abdb4 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -80,9 +80,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe downloadFile: any; constructor( - private menu: MenuController, + public wsChatMethodsService: WsChatMethodsService, private modalController: ModalController, - private actionSheetController: ActionSheetController, public popoverController: PopoverController, private chatService: ChatService, private authService: AuthService, @@ -97,8 +96,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe public ThemeService: ThemeService, private changeDetectorRef: ChangeDetectorRef, private storage: Storage, - public wsChatMethodsService: WsChatMethodsService + ) { + console.log('OnCONSTRUCTOR'); this.loggedUserChat = authService.ValidatedUserChat['data']; this.isGroupCreated = true; this.roomCountDownDate = ""; @@ -106,6 +106,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe } ngOnChanges(changes: SimpleChanges): void { + console.log('OnCHANGES'); + this.getRoomInfo(); //this.scrollToBottom(); this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory(); @@ -120,11 +122,13 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe } ngOnInit() { + console.log(this.roomId); this.loggedUser = this.loggedUserChat; - //console.log(this.wsChatMethodsService.getRoom(this.roomId).massages); this.loggedUser=this.loggedUserChat; - this.getRoomInfo(); + setTimeout(() => { + this.getRoomInfo(); + }, 1000); this.setStatus('online'); this.getChatMembers(); //this.getMessageDB(); @@ -254,6 +258,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe } async getRoomInfo() { + this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory(); let room = await this.chatService.getRoomInfo(this.roomId).toPromise(); this.room = room['room']; if (this.room.name) { @@ -288,29 +293,12 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe } loadGroupMessages(roomId) { - //console.log('here'+room.t); - this.showLoader = true; - //If group is private call getGroupMembers - /* if(room.t === 'p'){ - console.log('private'); */ - this.chatService.getPrivateGroupMessages(this.roomId).subscribe(res => { console.log(res); let msgOnly = res['messages'].filter(data => data.t != 'au'); - //this.messages = msgOnly.reverse(); - //console.log(res); - this.showLoader = false; }); - /* } */ - //Otherwise call getChannelMembers for públic groups - /* else{ - this.chatService.getPublicGroupMessages(this.roomId).subscribe(res=>{ - console.log(res); - this.messages = res['messages'].reverse(); - }); - } */ } sendMessage() { From 2ab70edd9d546677a2734d69d6ea08b2bb86d315 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Wed, 26 Jan 2022 16:37:59 +0100 Subject: [PATCH 05/16] fix bug in create new room --- src/app/pages/chat/chat.page.html | 2 +- src/app/pages/chat/chat.page.ts | 1 - src/app/services/chat/room.service.ts | 3 +- .../services/chat/ws-chat-methods.service.ts | 82 ++++++++++++------- src/app/services/chat/ws-chat.service.ts | 31 ++++++- .../shared/chat/new-group/new-group.page.ts | 37 +++++++-- 6 files changed, 117 insertions(+), 39 deletions(-) diff --git a/src/app/pages/chat/chat.page.html b/src/app/pages/chat/chat.page.html index 770139c39..aae5650aa 100644 --- a/src/app/pages/chat/chat.page.html +++ b/src/app/pages/chat/chat.page.html @@ -121,7 +121,7 @@
{{countDownDate(group.value.customFields.countDownDate, group.value.id)}}
-
{{group.value.lastMessage.u.name}}: {{group.value.lastMessage.msg}}
+
{{group.value.lastMessage.u.name}}: {{group.value.lastMessage.msg}}
diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index cadd6c5fb..870541ab5 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -298,7 +298,6 @@ export class ChatPage implements OnInit { this.openGroupMessagesModal(rid); } else { - alert('HERE OPEN') this.idSelected = rid; this.closeAllDesktopComponents(); this.showEmptyComponent = false; diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 5ef5762f0..8d9c3a482 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -39,7 +39,7 @@ export class RoomService { private sqlservice: SqliteService, ) { } - setData({ customFields, id, name, t, lastMessage, _updatedAt }) { + setData({ customFields, id, name, t, lastMessage = new MessageService(), _updatedAt }) { this.customFields = customFields this.id = id this.name = name @@ -62,6 +62,7 @@ export class RoomService { /* this.ToastService._chatMessage({message:'Nova mensagem', sender:'Gilson'}) */ const message = new MessageService() message.setData(ChatMessage) + this.lastMessage.msg = message.msg if (message.t == 'r') { this.name = message.msg } this.calDateDuration(ChatMessage._updatedAt) diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index b43c3b155..1db0198c6 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -46,35 +46,7 @@ export class WsChatMethodsService { // console.log("ROOMS" + JSON.stringify(rooms)) rooms.result.update.forEach((roomData: room) => { - let room:RoomService; - - //console.log(roomData); - - - room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice) - room.setData({ - customFields: roomData.customFields, - id: this.getRoomId(roomData), - name: this.getRoomName(roomData), - t: roomData.t, - lastMessage: this.getRoomLastMessage(roomData), - _updatedAt: new Date(roomData._updatedAt['$date']) - }) - - room.receiveMessage() - - let roomId = this.getRoomId(roomData) - - if(this.isIndividual(roomData)) { - this.dm[roomId] = room - this.dmCount++ - } else { - this.group[roomId] = room - this.groupCount++ - } - - - + this.prepareRoom(roomData); }); this.loadingWholeList = false @@ -99,6 +71,52 @@ export class WsChatMethodsService { })) } + + subscribeToRoomUpdate(id, roomData) { + this.WsChatService.streamRoomMessages(id).then((subscription)=>{ + console.log('streamRoomMessages', subscription) + }) + this.WsChatService.streamRoomMessages(id).then((subscription)=>{ + console.log('streamRoomMessages', subscription) + }) + this.WsChatService.streamNotifyLogged().then((subscription=>{ + console.log('streamRoomMessages', subscription) + })) + + this.prepareRoom(roomData); + + this.getGroupRoom(id).loadHistory(); + + } + + prepareRoom(roomData){ + let room:RoomService; + + room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice) + room.setData({ + customFields: roomData.customFields, + id: this.getRoomId(roomData), + name: this.getRoomName(roomData), + t: roomData.t, + lastMessage: this.getRoomLastMessage(roomData), + _updatedAt: new Date(roomData._updatedAt['$date']) + }) + + room.receiveMessage() + + let roomId = this.getRoomId(roomData) + + if(this.isIndividual(roomData)) { + this.dm[roomId] = room + this.dmCount++ + } else { + this.group[roomId] = room + this.groupCount++ + } + } + + + leaveRoom(id?) { return this.WsChatService.leaveRoom(id); } @@ -111,6 +129,10 @@ export class WsChatMethodsService { return this.WsChatService.addRoomOwner(roomid, userId); } + createPrivateRoom(groupName, username, customFields){ + return this.WsChatService.createPrivateRoom(groupName, username, customFields); + } + getDmRoom(id): RoomService { try { return this.dm[id] @@ -142,7 +164,7 @@ export class WsChatMethodsService { return roomData._id } - getRoomLastMessage(roomData: room) { + getRoomLastMessage(roomData: room):any { return roomData.lastMessage } diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 872970ece..e4415d5fc 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -229,7 +229,36 @@ export class WsChatService { joinRoom(){} deleteMessage() {} - createRoom() {} + createPrivateRoom(groupName, username, customFields) { + const requestId = uuidv4() + + var message = { + msg: "method", + method: "createPrivateGroup", + id: requestId, + params: [ + groupName, + [username], + false, + customFields, + { + "broadcast":false, + "encrypted":false + } + ] + } + + this.ws.send({message, requestId}); + + return new Promise((resolve, reject) => { + this.ws.registerCallback({type:'Onmessage', funx:(message)=>{ + if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send + resolve(message) + return true + } + }}) + }); + } diff --git a/src/app/shared/chat/new-group/new-group.page.ts b/src/app/shared/chat/new-group/new-group.page.ts index a8fb7a4c5..a63b55ec4 100644 --- a/src/app/shared/chat/new-group/new-group.page.ts +++ b/src/app/shared/chat/new-group/new-group.page.ts @@ -2,7 +2,9 @@ import { analyzeAndValidateNgModules } from '@angular/compiler'; import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'; import { NavigationStart, Router } from '@angular/router'; import { ModalController, NavParams, PickerController, PopoverController } from '@ionic/angular'; +import { AuthService } from 'src/app/services/auth.service'; import { ChatService } from 'src/app/services/chat.service'; +import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'; import { DataService } from 'src/app/services/data.service'; import { ProcessesService } from 'src/app/services/processes.service'; import { GroupDurationPage } from 'src/app/shared/popover/group-duration/group-duration.page'; @@ -25,6 +27,7 @@ export class NewGroupPage implements OnInit{ //groupName:string; task:any; documents: any; + loggedUserChat: any; @Input() groupName:string; @Output() addGroupMessage:EventEmitter = new EventEmitter(); @@ -37,8 +40,11 @@ export class NewGroupPage implements OnInit{ private dataService:DataService, private processesService: ProcessesService, private router: Router, + public wsChatMethodsService: WsChatMethodsService, + private authService: AuthService, ) { + this.loggedUserChat = authService.ValidatedUserChat['data']; this.isGroupCreated = false; //this.groupName = this.navParams.get('name'); } @@ -86,16 +92,37 @@ export class NewGroupPage implements OnInit{ this.addGroupMessage.emit(); } - createGroup(){ + async createGroup(){ let name = this.groupName.split(' ').join('-'); //Take out all special characters in string name = name.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); let body = { "name":name, } - this.chatService.addGroup(body).subscribe(res=>{ + + let customFields = {} + let res:any; + + if(this.thedate){ + let customFields = { + "countDownDate":this.thedate + } + res = await this.wsChatMethodsService.createPrivateRoom(name, this.loggedUserChat.me.username, customFields); + console.log(res); + } + else{ + res = await this.wsChatMethodsService.createPrivateRoom(name, this.loggedUserChat.me.username, customFields); + console.log(res); + } + + this.wsChatMethodsService.subscribeToRoomUpdate(res.result.rid, res.result); + this.addGroupMessage.emit(res.result.rid); + + /* this.chatService.addGroup(body).subscribe(res=>{ console.log('group created'); console.log(res['group']); - this.addGroupMessage.emit(res['group']._id); + this.addGroupMessage.emit(res['group']._id); */ + + /* this.addGroupMessage.emit(res['group']._id); if(this.thedate){ let countDownBody = { @@ -139,11 +166,11 @@ export class NewGroupPage implements OnInit{ } this.chatService.sendMessage(body).toPromise(); }); - } + } */ - }); + //}); } async addContacts(){ From 4a57300391ad2055ea45931370d12bbf474dda62 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Wed, 26 Jan 2022 17:01:50 +0100 Subject: [PATCH 06/16] save --- .../pages/chat/new-group/new-group.page.ts | 34 +++++++++++++++++-- .../shared/chat/new-group/new-group.page.ts | 5 +-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/app/pages/chat/new-group/new-group.page.ts b/src/app/pages/chat/new-group/new-group.page.ts index d1006c0e2..5ca806462 100644 --- a/src/app/pages/chat/new-group/new-group.page.ts +++ b/src/app/pages/chat/new-group/new-group.page.ts @@ -6,6 +6,8 @@ import { GroupContactsPage } from '../group-messages/group-contacts/group-contac import { ThemeService } from 'src/app/services/theme.service' import { ChatService } from 'src/app/services/chat.service'; import { ProcessesService } from 'src/app/services/processes.service'; +import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'; +import { AuthService } from 'src/app/services/auth.service'; @Component({ selector: 'app-new-group', @@ -21,6 +23,7 @@ export class NewGroupPage implements OnInit { thedate:any; groupName:string; documents:any; + loggedUserChat: any; constructor( private pickerController: PickerController, @@ -30,8 +33,11 @@ export class NewGroupPage implements OnInit { public ThemeService: ThemeService, private chatService: ChatService, private processesService: ProcessesService, + public wsChatMethodsService: WsChatMethodsService, + private authService: AuthService, ) { + this.loggedUserChat = authService.ValidatedUserChat['data']; this.isGroupCreated = false; this.groupName = this.navParams.get('name'); this.documents = this.navParams.get('documents'); @@ -55,10 +61,34 @@ export class NewGroupPage implements OnInit { this.modalController.dismiss(); } - createGroup(){ + async createGroup(){ let name = this.groupName.split(' ').join('-'); //Take out all special characters in string name = name.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); + + let customFields = {} + let res:any; + + if(this.thedate){ + let customFields = { + "countDownDate":this.thedate + } + res = await this.wsChatMethodsService.createPrivateRoom(name, this.loggedUserChat.me.username, customFields); + console.log(res); + } + else{ + res = await this.wsChatMethodsService.createPrivateRoom(name, this.loggedUserChat.me.username, customFields); + console.log(res); + } + + this.isGroupCreated = true; + this.addContacts(res.result); + + this.wsChatMethodsService.subscribeToRoomUpdate(res.result.rid, res.result); + + //this.addGroupMessage.emit(res.result.rid); + + /* let body = { "name":name, } this.chatService.addGroup(body).subscribe(res=>{ console.log('group created'); @@ -112,7 +142,7 @@ export class NewGroupPage implements OnInit { this.chatService.sendMessage(body).toPromise(); }); } - }); + }); */ } async addContacts(room){ diff --git a/src/app/shared/chat/new-group/new-group.page.ts b/src/app/shared/chat/new-group/new-group.page.ts index a63b55ec4..9bcc2eddc 100644 --- a/src/app/shared/chat/new-group/new-group.page.ts +++ b/src/app/shared/chat/new-group/new-group.page.ts @@ -96,7 +96,6 @@ export class NewGroupPage implements OnInit{ let name = this.groupName.split(' ').join('-'); //Take out all special characters in string name = name.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); - let body = { "name":name, } let customFields = {} let res:any; @@ -116,7 +115,9 @@ export class NewGroupPage implements OnInit{ this.wsChatMethodsService.subscribeToRoomUpdate(res.result.rid, res.result); this.addGroupMessage.emit(res.result.rid); - /* this.chatService.addGroup(body).subscribe(res=>{ + /* + let body = { "name":name, } + this.chatService.addGroup(body).subscribe(res=>{ console.log('group created'); console.log(res['group']); From 1665045f7cd72a7a1e47f409dab6f894686b3157 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Thu, 27 Jan 2022 14:26:18 +0100 Subject: [PATCH 07/16] fix html in chat views desktop --- .../group-messages/group-messages.page.ts | 2 + .../group-messages/group-messages.page.html | 94 ++++++++------- .../group-messages/group-messages.page.ts | 2 +- .../shared/chat/messages/messages.page.html | 113 ++++++++++-------- .../popover/chat-popover/chat-popover.page.ts | 1 + 5 files changed, 116 insertions(+), 96 deletions(-) diff --git a/src/app/pages/chat/group-messages/group-messages.page.ts b/src/app/pages/chat/group-messages/group-messages.page.ts index 406c41827..c927ed141 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -333,12 +333,14 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { cssClass: 'chat-popover', componentProps: { roomId: this.roomId, + members: this.members, }, }); await modal.present(); modal.onDidDismiss().then(res=>{ if(res.data == 'leave'){ console.log('saiu do grupo'); + //this.wsChatMethodsService.subscribeToRoomUpdate(this.roomId, this.room); } else if(res.data == 'cancel'){ console.log('cancel'); 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 7b1ee94b9..3ed43e24f 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -92,55 +92,64 @@
- -
-
- - - - -
-
- {{msg.u.name}} - {{showDateDuration(msg._updatedAt)}} -
-
- {{msg.msg}} -
-
-
- image -
-
+
+
+
+ AQUI +
+ + + + +
+
+ {{msg.u.name}} + {{showDateDuration(msg._updatedAt)}} +
+
+
+
+
+ image +
-
- -
- - - - - - - {{file.title}} +
+
+ +
+ + + + + + + {{file.title}} +
+
+
+ + {{file.description}} + + {{msg.file.type.replace('application/','').toUpperCase()}} +
-
-
- - {{file.description}} - - {{msg.file.type.replace('application/','').toUpperCase()}} -
+ {{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}}
+
+
-
+ image
@@ -167,7 +175,7 @@
- + -->
@@ -198,7 +206,7 @@
{{last ? scrollToBottom() : ''}}
-
+
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 37f8abdb4..df6e4fc46 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -112,7 +112,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe //this.scrollToBottom(); this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory(); this.wsChatMethodsService.getGroupRoom(this.roomId).getMsgFromDB(); - console.log('MESSAGES'+this.wsChatMethodsService.getGroupRoom(this.roomId).massages); + console.log('MESSAGES'+ this.wsChatMethodsService.getGroupRoom(this.roomId).massages); this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked setTimeout(()=>{ diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 5ceb5633e..bae7b0af1 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -56,63 +56,73 @@ {{last ? scrollToBottom() : ''}}
-
-
- - - - - -
-
- {{msg.u.name}} - {{showDateDuration(msg._updatedAt)}} -
-
- -
-
-
- - image - -
-
-
-
- - - - - - - - {{file.title}} -
+
+
+
+ + + + + +
+
+ {{msg.u.name}} + {{showDateDuration(msg._updatedAt)}} +
+
+
+
+
+ image
-
- - {{file.description}} - - {{msg.file.type.replace('application/','').toUpperCase()}} - +
+
+
+ + + + + + + + {{file.title}} +
+
+
+ + {{file.description}} + + {{msg.file.type.replace('application/','').toUpperCase()}} + +
+ {{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}} +
+
-
+ File image
@@ -141,10 +150,10 @@
-
+
--> -
+
diff --git a/src/app/shared/popover/chat-popover/chat-popover.page.ts b/src/app/shared/popover/chat-popover/chat-popover.page.ts index 89fb4a101..d15e5abdb 100644 --- a/src/app/shared/popover/chat-popover/chat-popover.page.ts +++ b/src/app/shared/popover/chat-popover/chat-popover.page.ts @@ -96,6 +96,7 @@ export class ChatPopoverPage implements OnInit { } this.close('leave'); + //this.wsChatMethodsService.subscribeToRoomUpdate(this.roomId, res.result); /* this.chatService.getRoomInfo(this.roomId).subscribe(room=>{ From 9d2bf896fac79bb38b780fe8dc310939c2748b63 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Thu, 27 Jan 2022 14:56:55 +0100 Subject: [PATCH 08/16] save --- src/app/shared/chat/group-messages/group-messages.page.html | 6 ++---- src/app/shared/chat/messages/messages.page.html | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) 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 3ed43e24f..fd98e664c 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -112,9 +112,8 @@
image
-
-
-
+
+
@@ -132,7 +131,6 @@ {{msg.file.type.replace('application/','').toUpperCase()}} -
diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index bae7b0af1..c8c6f57c6 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -76,7 +76,7 @@
image
-
+
From db5a679154c3471504976d8cee331a71b15db975 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Thu, 27 Jan 2022 14:58:57 +0100 Subject: [PATCH 09/16] save --- src/app/shared/chat/group-messages/group-messages.page.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fd98e664c..7d705a10d 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -248,7 +248,7 @@ - + From 0b9efc3bf696bc7ce50a61850d5e52ced76f1777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Thu, 27 Jan 2022 15:53:20 +0100 Subject: [PATCH 10/16] Image from camera web working fine --- src/app/services/functions/file.service.ts | 82 ++++++++++++++-------- 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/src/app/services/functions/file.service.ts b/src/app/services/functions/file.service.ts index 0d80e6506..2f3313ab2 100644 --- a/src/app/services/functions/file.service.ts +++ b/src/app/services/functions/file.service.ts @@ -254,43 +254,64 @@ export class FileService { this.capturedImage = this.images[0].data this.capturedImageTitle = new Date().getTime() + '.jpeg'; + const base64 = await fetch(this.capturedImage); + const blob = await base64.blob(); const formData = new FormData(); - formData.append("blobFile", this.capturedImage); - let guid: any = await this.uploadFile(this.capturedImage).toPromise() + formData.append("blobFile", blob); + console.log('ALL IMAGE', formData) + let guid: any = await this.uploadFile(formData).toPromise() console.log(guid.path); - let body = { - "message": - { - "rid": roomid, - "msg": "", - "attachments": [{ - "title": this.capturedImageTitle, - "title_link_download": false, - "image_url": this.capturedImage, - }], - "file":{ - "type": "application/img", - "guid": guid.path, - "image_url": "" + + this.downloadFile(guid.path).subscribe(async (event) => { + + 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) { + var fileImage = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); + console.log('add picture to chat',fileImage); + await this.storage.set(guid.path, fileImage).then(() => { + console.log('add picture to chat IMAGE SAVED') + let body = { + "message": + { + "rid": roomid, + "msg": "", + "attachments": [{ + "title": this.capturedImageTitle, + "title_link_download": false, + "image_url": fileImage, + }], + "file":{ + "type": "application/img", + "guid": guid.path, + "image_url": fileImage + } + } + } + console.log('BODY TAKE PICTURE CHAT', body) + const loader = this.toastService.loading(); + this.chatService.sendMessage(body).subscribe(res=> { + console.log(res); + loader.remove(); + },(error) => { + loader.remove(); + this.toastService.badRequest("Não foi possível adicionar a fotografia!"); + }); + + }); } - } - } - console.log('BODY TAKE PICTURE CHAT', body) - const loader = this.toastService.loading(); - this.chatService.sendMessage(body).subscribe(res=> { - console.log(res); - loader.remove(); - },(error) => { - loader.remove(); - this.toastService.badRequest("Não foi possível adicionar a fotografia!"); - }); + + }); } async addCameraPictureToChat(roomId){ + console.log('add camera to picture') + const image = await Camera.getPhoto({ quality: 50, allowEditing: false, @@ -300,6 +321,8 @@ export class FileService { if (image) { await this.saveImage(image,roomId) + } else { + console.log('Error saving image') } //this.capturedImage = this.capturedImage; @@ -375,12 +398,13 @@ export class FileService { const file = this.fileLoaderService.getFirstFile(input) - console.log(file); + console.log('first file',file); const formData = new FormData(); formData.append("blobFile", file); let guid: any = await this.uploadFile(formData).toPromise() + console.log('ADD IMAGE FORM DATA', formData) console.log('add picture to chat', guid.path); this.downloadFile(guid.path).subscribe(async (event) => { @@ -390,7 +414,7 @@ export class FileService { } else if (event.type === HttpEventType.Response) { var fileImage = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); console.log('add picture to chat',fileImage); - await this.storage.set(guid, fileImage).then(() => { + await this.storage.set(guid.path, fileImage).then(() => { console.log('add picture to chat IMAGE SAVED') let body = { From e1b6cb8c6bcf96faec4eb0e5273e2293f60f9ef3 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Thu, 27 Jan 2022 16:12:51 +0100 Subject: [PATCH 11/16] save --- .../pages/chat/messages/messages.page.html | 56 +++++-------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index d9027acc9..e232a3660 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -58,37 +58,6 @@
{{msg.msg}} -
-
-
- - image -
-
-
-
- -
- - - - - - - {{file.title}} -
-
-
- - {{file.description}} - - {{msg.file.type.replace('application/','').toUpperCase()}} - -
-
-
-
-
{{last ? scrollToBottom() : ''}}
@@ -104,7 +73,9 @@
--> -
+ +
+
{{msg.u.name}} {{showDateDuration(msg._updatedAt)}} @@ -112,15 +83,11 @@
-
- - File +
image
-
-
+
-
@@ -138,15 +105,22 @@ {{msg.file.type.replace('application/','').toUpperCase()}}
-
{{last ? scrollToBottom() : ''}}
+
+ {{msg.u.name}} criou esta reunião
+
+ De {{showDateDuration(msg.file.start_date)}} a {{showDateDuration(msg.file.end_date)}}
+ {{msg.file.venue}}
+
-
+
+ +
From 9c4ebaaa694b4486a727e7f2525224aab9b2b905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Thu, 27 Jan 2022 16:42:27 +0100 Subject: [PATCH 12/16] change value on sahre chat message page from msg.url to msg.file.url --- src/app/shared/chat/messages/messages.page.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index c8c6f57c6..831d0060c 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -74,7 +74,7 @@
- image + image
From 7c208d6c1919403479f311851d5fc46ee1bac3a9 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Thu, 27 Jan 2022 17:01:23 +0100 Subject: [PATCH 13/16] save --- src/app/pages/chat/messages/messages.page.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index e232a3660..afaa84300 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -85,6 +85,8 @@
image + +
From 87564626659efadddc7f6c49ea13e7b64f7ebdf1 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Thu, 27 Jan 2022 18:29:09 +0100 Subject: [PATCH 14/16] save --- .../group-messages/group-messages.page.html | 60 ++++++------------- .../pages/chat/messages/messages.page.html | 6 +- .../group-messages/group-messages.page.html | 34 +---------- .../shared/chat/messages/messages.page.html | 1 + .../chat-options-popover.page.html | 4 +- 5 files changed, 24 insertions(+), 81 deletions(-) diff --git a/src/app/pages/chat/group-messages/group-messages.page.html b/src/app/pages/chat/group-messages/group-messages.page.html index 8f9430043..38b6ad5b5 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.html +++ b/src/app/pages/chat/group-messages/group-messages.page.html @@ -57,48 +57,19 @@ A conversa original mantêm-se como chat individual
-
+
{{msg.u.name ?? ""}} {{showDateDuration(msg._updatedAt)}}
{{msg.msg}} -
-
-
- image -
-
-
-
- -
- - - - - - - {{file.title}} -
-
-
- - {{file.description}} - - {{msg.file.type.replace('application/','').toUpperCase()}} - -
-
-
-
-
{{last ? scrollToBottom() : ''}}
-
+ + File image
@@ -120,22 +90,22 @@ {{last ? scrollToBottom() : ''}}
-
+
--> -
+
+
{{msg.u.name ?? ""}} {{showDateDuration(msg._updatedAt)}}
- {{msg.msg}}
-
+
image +
-
-
+
@@ -154,13 +124,19 @@ {{msg.file.type.replace('application/','').toUpperCase()}}
-
{{last ? scrollToBottom() : ''}}
+
+ {{msg.u.name ?? ""}} criou esta reunião
+
+ De {{showDateDuration(msg.file.start_date)}} a {{showDateDuration(msg.file.end_date)}}
+ {{msg.file.venue}}
+
+
@@ -191,7 +167,7 @@
{{last ? scrollToBottom() : ''}}
-
+
diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index afaa84300..6630716f5 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -49,9 +49,8 @@ -->
-
-
+
+
{{msg.u.name}} {{showDateDuration(msg._updatedAt)}} @@ -85,7 +84,6 @@
image -
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 7d705a10d..1cde6d2f8 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -58,36 +58,6 @@
{{msg.msg}} -
-
-
- image -
-
-
-
- -
- - - - - - - {{file.title}} -
-
-
- - {{file.description}} - - {{msg.file.type.replace('application/','').toUpperCase()}} - -
-
-
-
-
{{last ? scrollToBottom() : ''}}
@@ -95,7 +65,6 @@
- AQUI
@@ -103,7 +72,6 @@
- {{msg.u.name}} {{showDateDuration(msg._updatedAt)}}
@@ -111,10 +79,10 @@
image +
-
diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 831d0060c..81790e731 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -75,6 +75,7 @@
image +
diff --git a/src/app/shared/popover/chat-options-popover/chat-options-popover.page.html b/src/app/shared/popover/chat-options-popover/chat-options-popover.page.html index eca090810..fb5cc2d04 100644 --- a/src/app/shared/popover/chat-options-popover/chat-options-popover.page.html +++ b/src/app/shared/popover/chat-options-popover/chat-options-popover.page.html @@ -7,8 +7,8 @@
- - + +
From 5a214aebf4dbdcecc1b5e222838e2158733d7c26 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Fri, 28 Jan 2022 15:31:52 +0100 Subject: [PATCH 15/16] bug fix in chat view --- src/app/pages/chat/chat.page.html | 9 ++- src/app/pages/chat/chat.page.ts | 1 + .../group-messages/group-messages.page.ts | 2 +- src/app/pages/chat/messages/messages.page.ts | 16 ++--- src/app/services/alert.service.ts | 14 +++-- src/app/services/chat/room.service.ts | 40 ++++++++++++- .../services/chat/ws-chat-methods.service.ts | 17 +++++- src/app/services/chat/ws-chat.service.ts | 60 ++++++++++++++++++- .../group-messages/group-messages.page.html | 4 +- .../group-messages/group-messages.page.ts | 9 +-- .../shared/chat/messages/messages.page.html | 4 +- src/app/shared/chat/messages/messages.page.ts | 18 ++---- 12 files changed, 145 insertions(+), 49 deletions(-) diff --git a/src/app/pages/chat/chat.page.html b/src/app/pages/chat/chat.page.html index aae5650aa..288f94d9c 100644 --- a/src/app/pages/chat/chat.page.html +++ b/src/app/pages/chat/chat.page.html @@ -68,17 +68,20 @@
{{room.value.lastMessage.msg}} - - + +
+ {{room.value.lastMessage.file.name || room.value.lastMessage.file.subject }} - +
+
Fotografia
+
diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 870541ab5..b5963e605 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -143,6 +143,7 @@ export class ChatPage implements OnInit { ngOnInit() { + console.log(this.wsChatMethodsService.dm); console.log(this.wsChatMethodsService.group); diff --git a/src/app/pages/chat/group-messages/group-messages.page.ts b/src/app/pages/chat/group-messages/group-messages.page.ts index c927ed141..b0c78926d 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -138,7 +138,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { "asUser": false, } if(msgId){ - this.alertService.confirmDeleteMessage(body); + //this.alertService.confirmDeleteMessage(body); } else{ this.toastService.badRequest('Não foi possível apagar'); diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index b5742811f..a00497bac 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -114,7 +114,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory() this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked - + setTimeout(()=>{ this.scrollToBottomClicked() }, 50) @@ -245,7 +245,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { "asUser": false, } if (msgId) { - this.alertService.confirmDeleteMessage(body); + //this.alertService.confirmDeleteMessage(body); } else { this.toastService.badRequest('Não foi possível apagar'); @@ -576,11 +576,11 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { }); } - /* + /* this.fileService.downloadFile(element.file.guid).subscribe(async (event) => { var name = element.file.guid; if (event.type === HttpEventType.DownloadProgress) { - + } else if (event.type === HttpEventType.Response) { var base64 = btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '') ); @@ -600,14 +600,14 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { console.log('error LAKE FS FILE', error) }); - + const readFile = await Filesystem.readFile({ path: `${IMAGE_DIR}/${name}`, directory: Directory.Data, - }); - - + }); + + });*/ getRoomMessageDB(roomId) { diff --git a/src/app/services/alert.service.ts b/src/app/services/alert.service.ts index 239c5d89c..447b18fe4 100644 --- a/src/app/services/alert.service.ts +++ b/src/app/services/alert.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@angular/core'; import { AlertController, AnimationController } from '@ionic/angular'; import { ChatService } from './chat.service'; +import { WsChatMethodsService } from './chat/ws-chat-methods.service'; import { ToastService } from './toast.service'; @Injectable({ @@ -13,6 +14,7 @@ export class AlertService { private animationController: AnimationController, private chatService: ChatService, private toastService: ToastService, + public wsChatMethodsService: WsChatMethodsService, ) { } async presentAlert(message:string) { @@ -40,7 +42,9 @@ export class AlertService { }, 2500); } - async confirmDeleteMessage(body:any) { + async confirmDeleteMessage(msgId:any, room:any) { + console.log(room); + const alert = await this.alertController.create({ cssClass: 'my-custom-class', header: 'Apagar a mensagem?', @@ -55,10 +59,10 @@ export class AlertService { }, { text: 'Apagar', handler: () => { - const loader = this.toastService.loading(); - this.chatService.deleteMessage(body).subscribe(res=>{ - loader.remove(); - }); + //const loader = this.toastService.loading(); + this.wsChatMethodsService.deleteMessage(msgId); + //this.wsChatMethodsService.subscribeToRoomUpdate(room._id, room); + //loader.remove(); } } ] diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 8d9c3a482..3e8e940d4 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -52,8 +52,9 @@ export class RoomService { receiveMessage() { - this.WsChatService.receiveLiveMessageFromRoom( + this.WsChatService.upateRoomEvents( this.id, + "stream-room-messages", (ChatMessage) => { ChatMessage = ChatMessage.fields.args[0] ChatMessage = this.fix_updatedAt(ChatMessage) @@ -63,7 +64,7 @@ export class RoomService { const message = new MessageService() message.setData(ChatMessage) - this.lastMessage.msg = message.msg + this.lastMessage = message if (message.t == 'r') { this.name = message.msg } this.calDateDuration(ChatMessage._updatedAt) this.massages.push(message) @@ -84,6 +85,37 @@ export class RoomService { } ) + + this.WsChatService.registerCallback + } + + async receiveMessageDelete() { + + this.WsChatService.upateRoomEvents( + this.id, + "stream-notify-room", + async (ChatMessage) => { + console.log(ChatMessage.fields.args[0]._id); + const messageId = ChatMessage.fields.args[0]._id; + this.massages.forEach((message, index)=>{ + if(message._id == messageId){ + this.massages.splice(index, 1) + this.storage.set('chatmsg' + this.id, this.massages).then((value) => { + //console.log('MSG DELETE ON STORAGE', value) + }); + + //Get previous last message from room + const previousLastMessage = this.massages.slice(-1)[0]; + + this.lastMessage = previousLastMessage; + this.calDateDuration(previousLastMessage._updatedAt) + + } + }) + + } + ) + this.WsChatService.registerCallback } send(msg) { @@ -148,7 +180,7 @@ export class RoomService { if (message.file) { if (message.file.guid) { this.storage.get(message.file.guid).then((image) => { - console.log('IMAGE FROM STORAGE', image) + //console.log('IMAGE FROM STORAGE', image) message.file.image_url = image }); } @@ -188,6 +220,8 @@ export class RoomService { this.WsChatService.loadHistory(this.id, limit).then(async (chatHistory: chatHistory) => { const mgsArray = chatHistory.result.messages.reverse(); + console.log(mgsArray); + if (this.platform.is('desktop') || this.platform.is('mobileweb')) { await this.storage.remove('chatmsg' + this.id).then(() => { console.log('MSG REMOVE ON STORAGE') diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 1db0198c6..d760efe42 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -58,14 +58,19 @@ export class WsChatMethodsService { this.WsChatService.streamRoomMessages(id).then((subscription)=>{ console.log('streamRoomMessages', subscription) }) + this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription)=>{ + console.log('streamNotifyRoomDeleteMessage', subscription); + }) } for (const id in this.group) { this.WsChatService.streamRoomMessages(id).then((subscription)=>{ console.log('streamRoomMessages', subscription) }) + this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription)=>{ + console.log('streamNotifyRoomDeleteMessage', subscription); + }) } - this.WsChatService.streamNotifyLogged().then((subscription=>{ console.log('streamRoomMessages', subscription) })) @@ -82,6 +87,9 @@ export class WsChatMethodsService { this.WsChatService.streamNotifyLogged().then((subscription=>{ console.log('streamRoomMessages', subscription) })) + this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription)=>{ + console.log('streamNotifyRoomDeleteMessage', subscription); + }) this.prepareRoom(roomData); @@ -103,10 +111,13 @@ export class WsChatMethodsService { }) room.receiveMessage() + room.receiveMessageDelete(); let roomId = this.getRoomId(roomData) if(this.isIndividual(roomData)) { + console.log(room); + this.dm[roomId] = room this.dmCount++ } else { @@ -115,7 +126,9 @@ export class WsChatMethodsService { } } - + deleteMessage(id?) { + return this.WsChatService.deleteMessage(id); + } leaveRoom(id?) { return this.WsChatService.leaveRoom(id); diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index e4415d5fc..d0b29a972 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -228,7 +228,29 @@ export class WsChatService { } joinRoom(){} - deleteMessage() {} + + deleteMessage(msgId) { + const requestId = uuidv4(); + + var message = { + msg: "method", + method: "deleteMessage", + id: requestId, + params:[{"_id":msgId}] + } + + this.ws.send({message, requestId}); + + return new Promise ((resolve, reject) => { + this.ws.registerCallback({type:'Onmessage', funx:(message) =>{ + if(message.id == requestId || deepFind(message, 'result') == requestId){ + resolve(message) + return true + } + }}) + }); + } + createPrivateRoom(groupName, username, customFields) { const requestId = uuidv4() @@ -337,15 +359,20 @@ export class WsChatService { } - receiveLiveMessageFromRoom(roomId, funx: Function) { +upateRoomEvents(roomId, collection:string, funx: Function, ) { this.ws.registerCallback({ type:'Onmessage', funx:(message)=>{ - if(message.msg =='changed' && message.collection == 'stream-room-messages') { + //console.log(message); + + if(message.msg =='changed' && message.collection == collection) { if(message.fields.args[0].rid == roomId) { funx(message) } + else if(message.fields.eventName ==`${roomId}/deleteMessage`){ + funx(message) + } } } }) @@ -432,6 +459,33 @@ export class WsChatService { } + streamNotifyRoomDeleteMessage(roomId:string) { + + const requestId = uuidv4() + + let message = { + "msg": "sub", + "id": requestId, + "name": "stream-notify-room", + "params": [ + `${roomId}/deleteMessage`, + true + ] + }; + + this.ws.send({message, requestId}) + + return new Promise((resolve, reject) => { + this.ws.registerCallback({type:'Onmessage', funx:(message)=>{ + if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send + resolve(message) + return true + } + }}) + }); + + } + registerCallback(data:wsCallbacksParams) { return this.ws.registerCallback(data) } 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 1cde6d2f8..1f04ea84d 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -49,7 +49,7 @@
- +
@@ -68,7 +68,7 @@
- +
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 df6e4fc46..b64694d09 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -306,13 +306,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe this.message = ""; } - deleteMessage(msgId: string) { - let body = { - "roomId": this.roomId, - "msgId": msgId, - "asUser": false, - } - this.alertService.confirmDeleteMessage(body); + deleteMessage(msgId: string, room:any) { + this.alertService.confirmDeleteMessage(msgId, room); } async openGroupMessagesOptions() { diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 81790e731..b72777b27 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -44,7 +44,7 @@ - +
@@ -63,7 +63,7 @@ - +
diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 8759a86ac..b6e737c76 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -107,8 +107,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.wsChatMethodsService.getDmRoom(this.roomId).massages.forEach((element) => { console.log('DATATATA 11', element) }) */ - - + + //this.transformData(this.wsChatMethodsService.getDmRoom(this.roomId).massages) //this.getMessageDB() @@ -254,16 +254,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.message = ""; } - deleteMessage(msgId: string) { - let body = { - "roomId": this.roomId, - "msgId": msgId, - "asUser": false, - } - this.alertService.confirmDeleteMessage(body); - /* this.chatService.deleteMessage(body).subscribe(res=>{ - console.log(res); - }); */ + deleteMessage(msgId: string, room:any) { + this.alertService.confirmDeleteMessage(msgId, room); } async viewDocument(msg: any, url?: string) { @@ -637,7 +629,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy console.log('FILE TYPE 33', msg.file.type) } else if (event.type === HttpEventType.Response) { this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - + msg.file = { guid: msg.file.guid, image_url: this.downloadFile, From 252bd24eee73a76cc3e72545d541dec76b6e4af5 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Fri, 28 Jan 2022 15:59:01 +0100 Subject: [PATCH 16/16] save --- src/app/Rules/despacho.service.ts | 2 +- src/app/services/chat/room.service.ts | 23 +++++++++++-------- .../services/chat/ws-chat-methods.service.ts | 4 +++- src/app/services/functions/sort.service.ts | 9 ++------ .../group-messages/group-messages.page.html | 2 +- .../group-messages/group-messages.page.ts | 2 +- .../shared/chat/messages/messages.page.html | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/app/Rules/despacho.service.ts b/src/app/Rules/despacho.service.ts index ae89903af..2e41e5305 100644 --- a/src/app/Rules/despacho.service.ts +++ b/src/app/Rules/despacho.service.ts @@ -254,7 +254,7 @@ export class DespachoService { }); despachoList = this.sortService.sortDate(despachoList, 'CreateDate') - + if(updateStore) { this.despachoStore.reset(despachoList); } diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 3e8e940d4..5f8235fac 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -8,12 +8,13 @@ import { chatHistory, ChatMessage } from 'src/app/models/chatMethod' import { Storage } from '@ionic/storage'; import { Platform } from '@ionic/angular'; import { SqliteService } from 'src/app/services/sqlite.service'; +import { SortService } from '../functions/sort.service'; @Injectable({ providedIn: 'root' }) export class RoomService { - massages: MessageService[] = [] + messages: MessageService[] = [] storageMessage: any[] = []; lastMessage: MessageService; @@ -37,6 +38,7 @@ export class RoomService { private storage: Storage, private platform: Platform, private sqlservice: SqliteService, + private sortService: SortService, ) { } setData({ customFields, id, name, t, lastMessage = new MessageService(), _updatedAt }) { @@ -67,12 +69,13 @@ export class RoomService { this.lastMessage = message if (message.t == 'r') { this.name = message.msg } this.calDateDuration(ChatMessage._updatedAt) - this.massages.push(message) + this.messages.push(message) setTimeout(() => { this.scrollDown() }, 100) + //this.sortService.sortDate(this.messages, '') // save to ionic storage this.storage.get('chatmsg' + this.id).then((messages: any) => { @@ -97,15 +100,15 @@ export class RoomService { async (ChatMessage) => { console.log(ChatMessage.fields.args[0]._id); const messageId = ChatMessage.fields.args[0]._id; - this.massages.forEach((message, index)=>{ + this.messages.forEach((message, index)=>{ if(message._id == messageId){ - this.massages.splice(index, 1) - this.storage.set('chatmsg' + this.id, this.massages).then((value) => { + this.messages.splice(index, 1) + this.storage.set('chatmsg' + this.id, this.messages).then((value) => { //console.log('MSG DELETE ON STORAGE', value) }); //Get previous last message from room - const previousLastMessage = this.massages.slice(-1)[0]; + const previousLastMessage = this.messages.slice(-1)[0]; this.lastMessage = previousLastMessage; this.calDateDuration(previousLastMessage._updatedAt) @@ -156,8 +159,8 @@ export class RoomService { console.log('FROM DB WEB', mmessage) const wewMessage = new MessageService() wewMessage.setData(mmessage) - this.massages.push(wewMessage) - console.log('loadHistory 222', this.massages) + this.messages.push(wewMessage) + console.log('loadHistory 222', this.messages) }); }); } @@ -190,8 +193,8 @@ export class RoomService { console.log('FROM DB WEB', mmessage) const wewMessage = new MessageService() wewMessage.setData(mmessage) - this.massages.push(wewMessage) - console.log('loadHistory 222', this.massages) + this.messages.push(wewMessage) + console.log('loadHistory 222', this.messages) }); }) } diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index d760efe42..7829b8b70 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -8,6 +8,7 @@ import { Rooms, Update as room } from 'src/app/models/chatMethod'; import { Storage } from '@ionic/storage'; import { Platform } from '@ionic/angular'; import { SqliteService } from 'src/app/services/sqlite.service'; +import { SortService } from '../functions/sort.service'; @Injectable({ providedIn: 'root' @@ -29,6 +30,7 @@ export class WsChatMethodsService { private storage: Storage, private platform: Platform, private sqlservice: SqliteService, + private sortService: SortService ) { (async()=>{ await this.getAllRooms(); @@ -100,7 +102,7 @@ export class WsChatMethodsService { prepareRoom(roomData){ let room:RoomService; - room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice) + room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice, this.sortService) room.setData({ customFields: roomData.customFields, id: this.getRoomId(roomData), diff --git a/src/app/services/functions/sort.service.ts b/src/app/services/functions/sort.service.ts index c248ff958..dc4c4b84f 100644 --- a/src/app/services/functions/sort.service.ts +++ b/src/app/services/functions/sort.service.ts @@ -15,7 +15,7 @@ export class SortService { }); } } - + sortArrayByDate(myArray: any) { console.log(myArray[0].taskStartDate); if(myArray.length > 0){ @@ -26,13 +26,8 @@ export class SortService { } sortDate(array = [], path: string) { - return array.sort( (a,b)=> { - - return new Date(this.ObjectService.deepFind(b, path)).getTime() - - new Date(this.ObjectService.deepFind(a, path)).getTime() - + return new Date(this.ObjectService.deepFind(b, path)).getTime() - new Date(this.ObjectService.deepFind(a, path)).getTime() }) - } } 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 1f04ea84d..234c7876a 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -44,7 +44,7 @@ A conversa original mantêm-se como chat individual
-
+
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 b64694d09..70d0fcec0 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -112,7 +112,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe //this.scrollToBottom(); this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory(); this.wsChatMethodsService.getGroupRoom(this.roomId).getMsgFromDB(); - console.log('MESSAGES'+ this.wsChatMethodsService.getGroupRoom(this.roomId).massages); + console.log('MESSAGES'+ this.wsChatMethodsService.getGroupRoom(this.roomId).messages); this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked setTimeout(()=>{ diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index b72777b27..18d330493 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -38,7 +38,7 @@
-
+