offline messagens

This commit is contained in:
Peter Maquiran
2022-02-04 00:22:35 +01:00
parent 61de7b937b
commit 0f04ad98c2
11 changed files with 381 additions and 239 deletions
@@ -121,7 +121,7 @@
<ion-label *ngIf="msg.file">
<span *ngIf="file.description">{{file.description}}</span>
<span *ngIf="file.description && msg.file.type != 'application/webtrix'"></span>
<span *ngIf="msg.file.type != 'application/webtrix'">{{msg.file.type.replace('application/','').toUpperCase()}}</span>
<span *ngIf="msg.file.type != 'application/webtrix'">{{msg.displayType}}</span>
</ion-label>
</div>
</div>
@@ -339,7 +339,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
sendMessage() {
this.wsChatMethodsService.getGroupRoom(this.roomId).send()
this.wsChatMethodsService.getGroupRoom(this.roomId).send({})
}
async openOptions() {
@@ -503,13 +503,36 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
const lastphoto: any = await this.FileSystemService.loadFiles(roomId);
const { capturedImage, capturedImageTitle} = await this.FileSystemService.loadFileData(lastphoto, roomId);
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": capturedImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
const base64 = await fetch(capturedImage);
const blob = await base64.blob();
const formData = new FormData();
formData.append("blobFile", blob);
console.log('ALL IMAGE', formData)
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
console.log(guid.path);
updateMessage({
file: {
type: "application/img",
guid: guid.path,
image_url: capturedImage
}
})
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
@@ -518,25 +541,12 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
//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', capturedImage);
await this.storage.set(guid.path, capturedImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
file: {
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
message.getFileFromDb()
});
}
});
@@ -565,15 +575,10 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
modal.onDidDismiss().then(async res=>{
const data = res.data;
if(data.selected){
if(data.selected) {
const loader = this.toastService.loading();
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
console.log(url_no_options);
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
alias: "documento",
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file:{
"name": res.data.selected.Assunto,
"type": "application/webtrix",
@@ -581,6 +586,22 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
"DocId": res.data.selected.Id,
"Assunto": res.data.selected.Assunto,
},
attachments: [{
"title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc,
// "title_link": url_no_options,
"title_link_download": true,
//"thumb_url": "assets/images/webtrix-logo.png",
// "message_link": url_no_options,
"type": "webtrix"
}]
})
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
console.log(url_no_options);
updateMessage({
attachments: [{
"title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc,
@@ -591,6 +612,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
"type": "webtrix"
}]
})
loader.remove();
}
@@ -598,11 +620,37 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
async addFileToChat(types: typeof FileType[] ) {
const file = await this.fileService.getFileFromDevice(types);
const imageData = await this.fileToBase64Service.convert(file)
const formData = new FormData();
formData.append("blobFile", file);
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": imageData
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
updateMessage({
file: {
type: "application/img",
guid: guid.path,
image_url: imageData
}
})
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
if (event.type === HttpEventType.DownloadProgress) {
@@ -613,21 +661,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
console.log('add picture to chat',fileImage);
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
file: {
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
message.getFileFromDb()
});
}
@@ -680,7 +714,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": guid.path,
@@ -102,7 +102,7 @@
<ion-label *ngIf="msg.file && msg.file != ''">
<span *ngIf="file.description">{{file.description}}</span>
<span *ngIf="file.description && msg.file.type != 'application/webtrix'"></span>
<span *ngIf="msg.file.type != 'application/webtrix'">{{msg.file.type.replace('application/','').toUpperCase()}}</span>
<span *ngIf="msg.file.type != 'application/webtrix'">{{msg.displayType}}</span>
</ion-label>
</div>
</div>
+78 -42
View File
@@ -38,6 +38,7 @@ import { element } from 'protractor';
import { FileType } from 'src/app/models/fileType';
import { SearchPage } from 'src/app/pages/search/search.page';
import { Storage } from '@ionic/storage';
import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
const IMAGE_DIR = 'stored-images';
@@ -111,6 +112,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
private CameraService: CameraService,
private processesService: ProcessesService,
private storage: Storage,
private fileToBase64Service: FileToBase64Service,
) {
this.loggedUser = authService.ValidatedUserChat['data'];
this.roomId = this.navParams.get('roomId');
@@ -347,7 +349,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
sendMessage() {
this.wsChatMethodsService.getDmRoom(this.roomId).send()
this.wsChatMethodsService.getDmRoom(this.roomId).send({})
}
@@ -524,13 +526,36 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
const lastphoto: any = await this.FileSystemService.loadFiles(roomId);
const { capturedImage, capturedImageTitle} = await this.FileSystemService.loadFileData(lastphoto, roomId);
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": capturedImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
const base64 = await fetch(capturedImage);
const blob = await base64.blob();
const formData = new FormData();
formData.append("blobFile", blob);
console.log('ALL IMAGE', formData)
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
console.log(guid.path);
updateMessage({
file: {
type: "application/img",
guid: guid.path,
image_url: capturedImage
}
})
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
@@ -539,25 +564,12 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
//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', capturedImage);
await this.storage.set(guid.path, capturedImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
file: {
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
message.getFileFromDb()
});
}
});
@@ -586,15 +598,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
modal.onDidDismiss().then(async res=>{
const data = res.data;
if(data.selected){
if(data.selected) {
const loader = this.toastService.loading();
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
console.log(url_no_options);
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
alias: "documento",
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file:{
"name": res.data.selected.Assunto,
"type": "application/webtrix",
@@ -602,6 +609,22 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
"DocId": res.data.selected.Id,
"Assunto": res.data.selected.Assunto,
},
attachments: [{
"title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc,
// "title_link": url_no_options,
"title_link_download": true,
//"thumb_url": "assets/images/webtrix-logo.png",
// "message_link": url_no_options,
"type": "webtrix"
}]
})
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
console.log(url_no_options);
updateMessage({
attachments: [{
"title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc,
@@ -612,6 +635,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
"type": "webtrix"
}]
})
loader.remove();
}
@@ -619,11 +643,37 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
async addFileToChat(types: typeof FileType[] ) {
const file = await this.fileService.getFileFromDevice(types);
const imageData = await this.fileToBase64Service.convert(file)
const formData = new FormData();
formData.append("blobFile", file);
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": imageData
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
updateMessage({
file: {
type: "application/img",
guid: guid.path,
image_url: imageData
}
})
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
if (event.type === HttpEventType.DownloadProgress) {
@@ -634,21 +684,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
console.log('add picture to chat',fileImage);
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
file: {
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
message.getFileFromDb()
});
}
@@ -701,7 +737,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": guid.path,
+22 -5
View File
@@ -23,6 +23,7 @@ export class MessageService {
file
attachments
offline = true
displayType = ''
constructor(private storage: Storage) {
}
@@ -49,14 +50,16 @@ export class MessageService {
if (this.file) {
if (this.file.guid) {
this.storage.get(this.file.guid).then((image) => {
// console.log('IMAGE FROM STORAGE', image)
this.file.image_url = image
});
this.getFileFromDb()
if(this.file.type) {
if(this.file.type != 'application/webtrix' && typeof(this.file.type) == 'string') {
this.displayType = this.file.type.replace('application/','').toUpperCase()
}
}
}
}
delete() {}
@@ -75,4 +78,18 @@ export class MessageService {
return firstName + ' ' + lastName
}
getFileFromDb() {
if (this.file) {
if (this.file.guid) {
this.storage.get(this.file.guid).then((image) => {
if(image != null) {
this.file.image_url = image
}
});
}
}
}
}
+31 -51
View File
@@ -54,6 +54,7 @@ export class RoomService {
}
sortRoomList = () => {}
uploadAttachment = (formData) => {}
constructor(
public WsChatService: WsChatService,
@@ -204,51 +205,9 @@ export class RoomService {
/**
* @description sen text message
*/
send() {
if(environment.chatOffline == false) {
this.WsChatService.send(this.id, this.message)
this.message= ''
} else {
const offlineChatMessage = {
channels: [],
mentions: [],
rid: this.id,
msg: this.message,
u: {
name: this.usernameToDisplayName(SessionStore.user.RochetChatUser),
username: SessionStore.user.RochetChatUser,
_id: ""
},
_updatedAt: new Date().getTime(),
offline: true
}
this.addMessageDB(offlineChatMessage)
const message: MessageService = this.prepareMessage(offlineChatMessage)
setTimeout(() => {
this.scrollDown()
}, 150)
this.lastMessage = message
send({file = null, attachments = null}) {
this.WsChatService.send(this.id, message.msg).then((data: any) => {
let ChatMessage = data.result
this.redefinedMessage(message, ChatMessage)
})
this.calDateDuration(message._updatedAt)
this.sortRoomList()
this.message= ''
}
}
sendFile({file, attachments, alias = 'document'}) {
let offlineChatMessage = {
rid: this.id,
msg: this.message,
@@ -265,16 +224,35 @@ export class RoomService {
this.lastMessage = message
if(file == null && attachments == null) {
console.log('simple send')
this.WsChatService.send({roomId:this.id, msg:message.msg}).then((data: any) => {
let ChatMessage = data.result
this.redefinedMessage(message, ChatMessage)
})
} else {
console.log('complex send')
return {
message: message,
updateMessage: (update)=> {
offlineChatMessage = Object.assign(offlineChatMessage, update)
this.WsChatService.send({roomId:this.id, msg:message.msg,attachments:offlineChatMessage.attachments, file:offlineChatMessage.file}).then((data: any) => {
console.log('send sucees', data.result)
let ChatMessage = data.result
this.redefinedMessage(message, ChatMessage)
})
}
}
}
this.calDateDuration(message._updatedAt)
this.sortRoomList()
this.chatService.sendMessage({message:offlineChatMessage}).subscribe((res:any) => {
let ChatMessage = res.message
console.log('ChatMessage', ChatMessage)
this.redefinedMessage(message, ChatMessage)
}, (error) => {
});
this.message= ''
}
redefinedMessage (message: MessageService, ChatMessage) {
@@ -362,11 +340,13 @@ export class RoomService {
let localMessages = []
if(messages==null) messages = []
messages.forEach((ChatMessage, index) => {
const wewMessage = this.prepareMessage(ChatMessage)
if(wewMessage.offline == true) {
this.WsChatService.send(this.id, wewMessage.msg).then((data: any) => {
this.WsChatService.send({roomId:this.id, msg:wewMessage.msg, attachments:wewMessage.attachments, file: wewMessage.file}).then((data: any) => {
let _ChatMessage = data.result
this.redefinedMessage(wewMessage, _ChatMessage)
this.storage.set('chatmsg' + this.id, messages)
+12 -11
View File
@@ -162,7 +162,7 @@ export class WsChatService {
}
// send message to room
send(roomId, msg) {
send({roomId, msg, attachments = null, file = null}) {
const requestId = uuidv4()
@@ -171,9 +171,10 @@ export class WsChatService {
method: "sendMessage",
id: requestId,
params: [{
_id: uuidv4(),
rid: roomId,
msg: msg
msg: msg,
attachments,
file
}]
}
@@ -181,7 +182,7 @@ export class WsChatService {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -206,7 +207,7 @@ export class WsChatService {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -232,7 +233,7 @@ export class WsChatService {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -255,7 +256,7 @@ export class WsChatService {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -310,7 +311,7 @@ export class WsChatService {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -337,7 +338,7 @@ export class WsChatService {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -565,7 +566,7 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -592,7 +593,7 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
return new Promise((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
if(message.id == requestId || deepFind(message,'result.id') == requestId) { // same request send
if(message.id == requestId ) { // same request send
resolve(message)
return true
}
@@ -97,7 +97,7 @@
<ion-label *ngIf="msg.file">
<span *ngIf="file.description">{{file.description}}</span>
<span *ngIf="file.description && msg.file.type != 'application/webtrix'"></span>
<span *ngIf="msg.file.type != 'application/webtrix'">{{msg.file.type.replace('application/','').toUpperCase()}}</span>
<span *ngIf="msg.file.type != 'application/webtrix'">{{msg.displayType}}</span>
</ion-label>
</div>
</div>
@@ -317,7 +317,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}
sendMessage() {
this.wsChatMethodsService.getGroupRoom(this.roomId).send()
this.wsChatMethodsService.getGroupRoom(this.roomId).send({})
}
deleteMessage(msgId: string, room:any) {
@@ -674,13 +674,36 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
const lastphoto: any = await this.FileSystemService.loadFiles(roomId);
const { capturedImage, capturedImageTitle} = await this.FileSystemService.loadFileData(lastphoto, roomId);
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": capturedImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
const base64 = await fetch(capturedImage);
const blob = await base64.blob();
const formData = new FormData();
formData.append("blobFile", blob);
console.log('ALL IMAGE', formData)
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
console.log(guid.path);
updateMessage({
file: {
type: "application/img",
guid: guid.path,
image_url: capturedImage
}
})
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
@@ -689,25 +712,12 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
//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', capturedImage);
await this.storage.set(guid.path, capturedImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
file: {
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
message.getFileFromDb()
});
}
});
@@ -736,15 +746,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
modal.onDidDismiss().then(async res=>{
const data = res.data;
if(data.selected){
if(data.selected) {
const loader = this.toastService.loading();
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
console.log(url_no_options);
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
alias: "documento",
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file:{
"name": res.data.selected.Assunto,
"type": "application/webtrix",
@@ -752,6 +757,22 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"DocId": res.data.selected.Id,
"Assunto": res.data.selected.Assunto,
},
attachments: [{
"title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc,
// "title_link": url_no_options,
"title_link_download": true,
//"thumb_url": "assets/images/webtrix-logo.png",
// "message_link": url_no_options,
"type": "webtrix"
}]
})
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
console.log(url_no_options);
updateMessage({
attachments: [{
"title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc,
@@ -762,6 +783,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"type": "webtrix"
}]
})
loader.remove();
}
@@ -769,11 +791,37 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}
async addFileToChat(types: typeof FileType[] ) {
const file = await this.fileService.getFileFromDevice(types);
const imageData = await this.fileToBase64Service.convert(file)
const formData = new FormData();
formData.append("blobFile", file);
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": imageData
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
updateMessage({
file: {
type: "application/img",
guid: guid.path,
image_url: imageData
}
})
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
if (event.type === HttpEventType.DownloadProgress) {
@@ -784,21 +832,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
console.log('add picture to chat',fileImage);
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
file: {
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
message.getFileFromDb()
});
}
@@ -887,7 +921,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": guid.path,
@@ -97,7 +97,7 @@
<span *ngIf="file.description">{{file.description}}</span>
<span *ngIf="file.description && msg.file.type != 'application/webtrix'"></span>
<span
*ngIf="msg.file.type != 'application/webtrix'">{{msg.file.type.replace('application/','').toUpperCase()}}</span>
*ngIf="msg.file.type != 'application/webtrix'">{{msg.displayType}}</span>
</ion-label>
</div>
</div>
+82 -42
View File
@@ -32,6 +32,7 @@ import { CameraService } from 'src/app/services/camera.service';
import { FileType } from 'src/app/models/fileType';
import { SearchPage } from 'src/app/pages/search/search.page';
import { ProcessesService } from 'src/app/services/processes.service';
import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
const IMAGE_DIR = 'stored-images';
@Component({
@@ -102,6 +103,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
private FileSystemService: FileSystemService,
private CameraService: CameraService,
private processesService: ProcessesService,
private fileToBase64Service: FileToBase64Service,
) {
this.loggedUser = authService.ValidatedUserChat['data'];
@@ -113,6 +115,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked
this.wsChatMethodsService.openRoom(this.roomId)
this.wsChatMethodsService.getDmRoom(this.roomId).uploadAttachment = async (formData) => {
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
}
setTimeout(() => {
this.scrollToBottomClicked()
}, 150)
@@ -238,7 +245,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
sendMessage() {
this.wsChatMethodsService.getDmRoom(this.roomId).send()
this.wsChatMethodsService.getDmRoom(this.roomId).send({})
}
deleteMessage(msgId: string, room:any) {
@@ -443,13 +450,36 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
const lastphoto: any = await this.FileSystemService.loadFiles(roomId);
const { capturedImage, capturedImageTitle} = await this.FileSystemService.loadFileData(lastphoto, roomId);
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": capturedImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
const base64 = await fetch(capturedImage);
const blob = await base64.blob();
const formData = new FormData();
formData.append("blobFile", blob);
console.log('ALL IMAGE', formData)
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
console.log(guid.path);
updateMessage({
file: {
type: "application/img",
guid: guid.path,
image_url: capturedImage
}
})
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
@@ -458,26 +488,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
//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', capturedImage);
await this.storage.set(guid.path, capturedImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
message.getFileFromDb()
});
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
alias: 'document',
file: {
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
}
});
@@ -506,15 +522,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
modal.onDidDismiss().then(async res=>{
const data = res.data;
if(data.selected){
if(data.selected) {
const loader = this.toastService.loading();
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
console.log(url_no_options);
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
alias: "documento",
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file:{
"name": res.data.selected.Assunto,
"type": "application/webtrix",
@@ -522,6 +533,22 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
"DocId": res.data.selected.Id,
"Assunto": res.data.selected.Assunto,
},
attachments: [{
"title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc,
// "title_link": url_no_options,
"title_link_download": true,
//"thumb_url": "assets/images/webtrix-logo.png",
// "message_link": url_no_options,
"type": "webtrix"
}]
})
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
console.log(url_no_options);
updateMessage({
attachments: [{
"title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc,
@@ -532,6 +559,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
"type": "webtrix"
}]
})
loader.remove();
}
@@ -539,11 +567,37 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
async addFileToChat(types: typeof FileType[] ) {
const file = await this.fileService.getFileFromDevice(types);
const imageData = await this.fileToBase64Service.convert(file)
const formData = new FormData();
formData.append("blobFile", file);
const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({
file: {
"type": "application/img",
"guid": '',
"image_url": imageData
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
updateMessage({
file: {
type: "application/img",
guid: guid.path,
image_url: imageData
}
})
this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => {
if (event.type === HttpEventType.DownloadProgress) {
@@ -554,21 +608,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
console.log('add picture to chat',fileImage);
await this.storage.set(guid.path, fileImage).then(() => {
console.log('add picture to chat IMAGE SAVED')
this.wsChatMethodsService.getDmRoom(this.roomId).sendFile({
file: {
"type": "application/img",
"guid": guid.path,
"image_url": fileImage
},
attachments: [{
//"title": this.capturedImageTitle ,
//"text": "description",
"title_link_download": false,
//"image_url": this.capturedImage,
}]
})
message.getFileFromDb()
});
}
@@ -585,7 +625,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
chatSendFile() {
chatsend() {
}