fixe chat message

This commit is contained in:
Peter Maquiran
2023-06-29 16:04:44 +01:00
parent 8c02c5abb8
commit 246ea2e4a6
16 changed files with 356 additions and 227 deletions
+7 -4
View File
@@ -16,6 +16,7 @@ export class MessageModel extends models.Model {
_updatedAt = models.IntegerField() _updatedAt = models.IntegerField()
messageSend = models.BooleanField() messageSend = models.BooleanField()
offline = models.BooleanField() offline = models.BooleanField()
hasFile = models.BooleanField({blank:true})
viewed = ArrayField({blank:true}) viewed = ArrayField({blank:true})
received = ArrayField({blank:true}) received = ArrayField({blank:true})
localReference = models.CharField({blank:true, unique: true}) localReference = models.CharField({blank:true, unique: true})
@@ -23,14 +24,16 @@ export class MessageModel extends models.Model {
file = JsonField({blank:true}) file = JsonField({blank:true})
async getAttachments() { async getAttachments() {
const _attachments = await attachments.filter({id: this['id']}) console.log('this[id]', this['id'])
return _attachments const _attachments = await attachments.filter({messageId: this['id']}).execute()
return _attachments[0]
} }
} }
export class attachments extends models.Model { export class attachments extends models.Model {
message = models.OneToOneField({model:MessageModel}) messageId = models.IntegerField()
attachments = ArrayField({default:[]}) attachments = ArrayField({blank:true})
file = JsonField({blank:true})
} }
export class DeleteMessageModel extends models.Model { export class DeleteMessageModel extends models.Model {
+4
View File
@@ -90,6 +90,10 @@ export interface Message {
received: string[], received: string[],
delate: boolean, delate: boolean,
delateRequest: boolean delateRequest: boolean
attachmentsModelData: {
fileBase64: string
}
hasFile: boolean
} }
@@ -114,11 +114,15 @@
<div (click)="openPreview(msg)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file"> <div (click)="openPreview(msg)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
<div *ngIf="!msg.attachments[0].image_url"> <div *ngIf="!msg.attachments[0].image_url">
<ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button"> <ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button">
<ion-icon *ngIf="msg.attachments[0].type != 'webtrix'" name="document" class="file-icon"></ion-icon> <ion-icon *ngIf="msg.attachments[0].type != 'webtrix'" name="document" class="file-icon"></ion-icon>
<ion-icon *ngIf="msg.attachments[0].type == 'webtrix'" src="assets/icon/webtrix.svg" class="file-icon"></ion-icon> <ion-icon *ngIf="msg.attachments[0].type == 'webtrix'" src="assets/icon/webtrix.svg" class="file-icon"></ion-icon>
<ion-label>{{file.title}}</ion-label> <ion-label>{{ file.title}}</ion-label>
<ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon> <ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon> <ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="( msg.downloadLoader == true || msg.uploadingFile == true )" class="icon-download" src="assets/gif/theme/{{ThemeService.currentTheme}}/Blocks-loader.svg" slot="end"></ion-icon>
</ion-item> </ion-item>
</div> </div>
<div *ngIf="msg.attachments[0].image_url"> <div *ngIf="msg.attachments[0].image_url">
@@ -16,7 +16,6 @@ import { EventPerson } from 'src/app/models/eventperson.model';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page'; import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
import { ThemeService } from 'src/app/services/theme.service' import { ThemeService } from 'src/app/services/theme.service'
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page'; import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
import { SqliteService } from 'src/app/services/sqlite.service';
import { ChatSystemService } from 'src/app/services/chat/chat-system.service'; import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
import { FileType } from 'src/app/models/fileType'; import { FileType } from 'src/app/models/fileType';
import { Storage } from '@ionic/storage'; import { Storage } from '@ionic/storage';
@@ -463,32 +462,12 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.ChatSystemService.getGroupRoom(this.roomId).send({}) this.ChatSystemService.getGroupRoom(this.roomId).send({})
} }
base64toBlob(base64Data, contentType) {
contentType = contentType || '';
var sliceSize = 1024;
var byteCharacters = atob(base64Data);
var bytesLength = byteCharacters.length;
var slicesCount = Math.ceil(bytesLength / sliceSize);
var byteArrays = new Array(slicesCount);
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
var begin = sliceIndex * sliceSize;
var end = Math.min(begin + sliceSize, bytesLength);
var bytes = new Array(end - begin);
for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
bytes[i] = byteCharacters[offset].charCodeAt(0);
}
byteArrays[sliceIndex] = new Uint8Array(bytes);
}
return new Blob(byteArrays, { type: contentType });
}
async sendAudio(fileName) { async sendAudio(fileName) {
const roomId = this.roomId const roomId = this.roomId
let audioFile; let audioFile;
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then(async (recordData) => {
audioFile = recordData; audioFile = recordData;
if (recordData?.value?.recordDataBase64.includes('data:audio')) { if (recordData?.value?.recordDataBase64.includes('data:audio')) {
@@ -500,7 +479,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
//Converting base64 to blob //Converting base64 to blob
const encodedData = btoa(this.audioRecorded); const encodedData = btoa(this.audioRecorded);
const blob = this.base64toBlob(encodedData, recordData.value.mimeType) const blob = this.fileService.base64toBlob(encodedData, recordData.value.mimeType)
const formData = new FormData(); const formData = new FormData();
formData.append("blobFile", blob); formData.append("blobFile", blob);
@@ -516,7 +495,10 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
"title_link_download": true, "title_link_download": true,
"type": "audio" "type": "audio"
}], }],
temporaryData: formData temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
}); });
@@ -670,7 +652,10 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
"title": capturedImageTitle, "title": capturedImageTitle,
"text": "description", "text": "description",
"title_link_download": false, "title_link_download": false,
}] }],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
} }
@@ -740,7 +725,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch ((error) => { const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch ((error) => {
console.error(error); console.error(error);
}))); })));
const blob = this.base64toBlob(encodedData, file.type) const blob = this.fileService.base64toBlob(encodedData, file.type)
const formData = new FormData(); const formData = new FormData();
formData.append('blobFile', blob); formData.append('blobFile', blob);
@@ -757,7 +742,10 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
// "text": "description", // "text": "description",
"title_link_download": false, "title_link_download": false,
}], }],
temporaryData: formData temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}); });
} else { } else {
@@ -864,65 +852,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}); });
} }
/* async actionSheet() {
const actionSheet = await this.actionSheetController.create({
cssClass: 'my-custom-class',
buttons: [{
text: 'Sair do grupo',
handler: () => {
}
}, {
text: 'Alterar nome do grupo1',
handler: () => {
this.openChangeGroupName()
}
}, {
text: 'Apagar o grupo',
handler: () => {
}
},
]
});
await actionSheet.present();
}
*/
// getRoomMessageDB(roomId) {
// if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
// } else {
// this.sqlservice.getAllChatMSG(roomId).then((msg: any) => {
// let chatmsgArray = [];
// let array = []
// msg.forEach(element => {
// let msgChat = {
// _id: element.Id,
// attachments: this.isJson(element.Attachments),
// channels: this.isJson(element.Channels),
// file: this.isJson(element.File),
// mentions: this.isJson(element.Mentions),
// msg: element.Msg,
// rid: element.Rid,
// ts: element.Ts,
// u: this.isJson(element.U),
// _updatedAt: element.UpdatedAt,
// image_url: this.isJson(element.image_url)
// }
// chatmsgArray.push(msgChat)
// });
// // this.messages = chatmsgArray;
// })
// }
// }
isJson(str) { isJson(str) {
try { try {
JSON.parse(str); JSON.parse(str);
@@ -114,11 +114,14 @@
<div *ngIf="!msg.attachments[0].image_url"> <div *ngIf="!msg.attachments[0].image_url">
<ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button"> <ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button">
<ion-icon *ngIf="msg.attachments[0].type != 'webtrix'" name="document" class="file-icon"></ion-icon> <ion-icon *ngIf="msg.attachments[0].type != 'webtrix'" name="document" class="file-icon"></ion-icon>
<ion-icon *ngIf="msg.attachments[0].type == 'webtrix'" src="assets/icon/webtrix.svg" class="file-icon"></ion-icon> <ion-icon *ngIf="msg.attachments[0].type == 'webtrix'" src="assets/icon/webtrix.svg" class="file-icon"></ion-icon>
<ion-label>{{file.title}}</ion-label> <ion-label>{{ file.title}}</ion-label>
<ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon> <ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon> <ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="( msg.downloadLoader == true || msg.uploadingFile == true )" class="icon-download" src="assets/gif/theme/{{ThemeService.currentTheme}}/Blocks-loader.svg" slot="end"></ion-icon>
</ion-item> </ion-item>
</div> </div>
+22 -32
View File
@@ -401,31 +401,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}) })
} */ } */
base64toBlob(base64Data, contentType) {
contentType = contentType || '';
var sliceSize = 1024;
var byteCharacters = atob(base64Data);
var bytesLength = byteCharacters.length;
var slicesCount = Math.ceil(bytesLength / sliceSize);
var byteArrays = new Array(slicesCount);
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
var begin = sliceIndex * sliceSize;
var end = Math.min(begin + sliceSize, bytesLength);
var bytes = new Array(end - begin);
for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
bytes[i] = byteCharacters[offset].charCodeAt(0);
}
byteArrays[sliceIndex] = new Uint8Array(bytes);
}
return new Blob(byteArrays, { type: contentType });
}
async sendAudio(fileName) { async sendAudio(fileName) {
const roomId = this.roomId const roomId = this.roomId
let audioFile; let audioFile;
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then(async (recordData) => {
audioFile = recordData; audioFile = recordData;
if (recordData?.value?.recordDataBase64.includes('data:audio')) { if (recordData?.value?.recordDataBase64.includes('data:audio')) {
@@ -439,7 +418,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
//Converting base64 to blob //Converting base64 to blob
const encodedData = btoa(this.audioRecorded); const encodedData = btoa(this.audioRecorded);
const blob = this.base64toBlob(encodedData, recordData.value.mimeType) const blob = this.fileService.base64toBlob(encodedData, recordData.value.mimeType)
const formData = new FormData(); const formData = new FormData();
formData.append("blobFile", blob); formData.append("blobFile", blob);
@@ -455,7 +434,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
"title_link_download": true, "title_link_download": true,
"type": "audio" "type": "audio"
}], }],
temporaryData: formData temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
}); });
@@ -658,14 +640,12 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
source: CameraSource.Camera source: CameraSource.Camera
}); });
const blob = this.dataURItoBlob('data:image/jpeg;base64,' + file.base64String) const base64 = 'data:image/jpeg;base64,' + file.base64String
console.log('data:image/jpeg;base64,' + file.base64String)
const blob = this.dataURItoBlob(base64)
const formData = new FormData(); const formData = new FormData();
formData.append("blobFile", blob); formData.append("blobFile", blob);
// console.log('capturedImage', capturedImage);
this.ChatSystemService.getDmRoom(roomId).send({ this.ChatSystemService.getDmRoom(roomId).send({
file: { file: {
"type": "application/img", "type": "application/img",
@@ -676,7 +656,11 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
"text": "description", "text": "description",
"title_link_download": false, "title_link_download": false,
}], }],
temporaryData: formData temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
} }
@@ -789,7 +773,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
"title": file.path, "title": file.path,
"text": "description", "text": "description",
"title_link_download": false, "title_link_download": false,
}] }],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
} }
@@ -813,7 +800,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch ((error) => { const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch ((error) => {
console.error(error); console.error(error);
}))); })));
const blob = this.base64toBlob(encodedData, file.type) const blob = this.fileService.base64toBlob(encodedData, file.type)
const formData = new FormData(); const formData = new FormData();
@@ -831,7 +818,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
// "text": "description", // "text": "description",
"title_link_download": false, "title_link_download": false,
}], }],
temporaryData: formData temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}); });
} else { } else {
+4 -3
View File
@@ -166,7 +166,9 @@ export class AuthService {
return true return true
} catch(e) { } catch(e) {
window['e'] = e
console.error('BeforesendAtachment', e) console.error('BeforesendAtachment', e)
message.uploadingFile = false
return false return false
} }
@@ -183,7 +185,9 @@ export class AuthService {
return true return true
} catch(e) { } catch(e) {
window['e'] = e
console.error('BeforesendAtachment', e) console.error('BeforesendAtachment', e)
message.uploadingFile = false
return false return false
} }
} }
@@ -211,9 +215,6 @@ export class AuthService {
type: message.file.type type: message.file.type
} }
await this.storage.set(message.file.guid, downloadFile).then(() => {
//
});
return true return true
} }
return false return false
+135 -22
View File
@@ -6,7 +6,7 @@ import { NfService } from 'src/app/services/chat/nf.service';
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service'; import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
import { showDateDuration } from 'src/plugin/showDateDuration'; import { showDateDuration } from 'src/plugin/showDateDuration';
import { ChatMethodsService } from './chat-methods.service'; import { ChatMethodsService } from './chat-methods.service';
import { MessageModel } from '../../models/beast-orm'; import { MessageModel, attachments } from '../../models/beast-orm';
import { AESEncrypt } from '../aesencrypt.service'; import { AESEncrypt } from '../aesencrypt.service';
import { HttpEventType } from '@angular/common/http'; import { HttpEventType } from '@angular/common/http';
import { AttachmentsService } from 'src/app/services/attachments.service'; import { AttachmentsService } from 'src/app/services/attachments.service';
@@ -40,7 +40,7 @@ export class MessageService {
file file
attachments attachments
displayType = '' displayType = ''
temporaryData: any = {} temporaryData: any
hasFile = false hasFile = false
hasSendAttachment = false hasSendAttachment = false
sendAttempt = 0 sendAttempt = 0
@@ -64,7 +64,9 @@ export class MessageService {
manualRetry = false manualRetry = false
origin: 'history' | 'stream' | 'local' origin: 'history' | 'stream' | 'local'
rowInstance: MessageModel messageModelInstance: MessageModel
attachmentsModelData: any
constructor( constructor(
private NfService: NfService, private NfService: NfService,
@@ -77,7 +79,7 @@ export class MessageService {
private notificationService: NotificationsService) { private notificationService: NotificationsService) {
} }
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference = 'out-'+uuidv4() , viewed = [], received = [], delate = false, delateRequest =false, from, sendAttempt = 0, origin }:Message) { setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference = 'out-'+uuidv4() , viewed = [], received = [], delate = false, delateRequest =false, from, sendAttempt = 0, origin, attachmentsModelData, hasFile = false }:Message) {
this.channels = channels || [] this.channels = channels || []
this.mentions = mentions || [] this.mentions = mentions || []
@@ -96,6 +98,7 @@ export class MessageService {
this.delateRequest = delateRequest this.delateRequest = delateRequest
this.sendAttempt = 0 this.sendAttempt = 0
this.origin = origin this.origin = origin
this.attachmentsModelData = attachmentsModelData
if(this.attachments?.length >= 1 && attachments?.length >= 1) { if(this.attachments?.length >= 1 && attachments?.length >= 1) {
this.attachments[0] = Object.assign(this.attachments[0], attachments[0]) this.attachments[0] = Object.assign(this.attachments[0], attachments[0])
@@ -112,12 +115,10 @@ export class MessageService {
this.messageSend = true this.messageSend = true
} }
if (this.file) { this.hasFile = hasFile
if(this.file.type) {
if(typeof(this.file.type) == 'string') { if (this.instanceHasAttachment && !this.hasFile) {
this.hasFile = true this.hasFile = true
}
}
} }
if(this.hasFile) { if(this.hasFile) {
@@ -201,6 +202,7 @@ export class MessageService {
} else { } else {
console.log('send', this)
let uploadSuccessfully = await this.sendRequestAttachment() let uploadSuccessfully = await this.sendRequestAttachment()
if(uploadSuccessfully) { if(uploadSuccessfully) {
@@ -247,24 +249,35 @@ export class MessageService {
functionTimer = null; functionTimer = null;
async sendRequestAttachment() { async sendRequestAttachment() {
this.uploadingFile = true this.uploadingFile = true
let uploadSuccessfully = false let uploadSuccessfully = false
if(!this.instanceHasAttachmentBase64 && !this.temporaryData) {
try {
await this.getFileFromDB()
} catch (error) {}
}
if(!this.instanceHasTemporaryData) {
await this.generateTemporaryData()
}
if(this.hasSendAttachment == false) { if(this.hasSendAttachment == false) {
try { try {
uploadSuccessfully = await this.NfService.beforeSendAttachment(this) uploadSuccessfully = await this.NfService.beforeSendAttachment(this)
this.UploadAttachmentsTemp++ this.UploadAttachmentsTemp++
this.uploadingFile = false this.uploadingFile = false
this.manualRetry = false this.manualRetry = false
this.errorUploadingAttachment = false this.errorUploadingAttachment = false
this.hasSendAttachment = true this.hasSendAttachment = true
this.temporaryData = {}
} catch (error) { } catch (error) {
this.uploadingFile = false this.uploadingFile = false
this.errorUploadingAttachment = true this.errorUploadingAttachment = true
this.UploadAttachmentsTemp++ this.UploadAttachmentsTemp++
console.error('beforeSendAttachment error:', error)
} }
} }
@@ -411,6 +424,7 @@ export class MessageService {
// save the changes to the storage // save the changes to the storage
this.saveChanges() this.saveChanges()
this.addFileToDb()
this.downloadLoader = false; this.downloadLoader = false;
this.downloadAttachments = true this.downloadAttachments = true
this.downloadAttachmentsTemp++; this.downloadAttachmentsTemp++;
@@ -461,11 +475,11 @@ export class MessageService {
async delateDB() { async delateDB() {
if(!this.rowInstance) { if(!this.messageModelInstance) {
this.rowInstance = await this.getRowInstance() this.messageModelInstance = await this.getRowInstance()
} }
await this.rowInstance.delete() await this.messageModelInstance.delete()
} }
@@ -489,6 +503,7 @@ export class MessageService {
u: this.u, u: this.u,
_id: this._id, _id: this._id,
id: this.id, id: this.id,
hasFile: this.hasFile,
origin: this.origin, origin: this.origin,
_updatedAt: this._updatedAt, _updatedAt: this._updatedAt,
messageSend: this.messageSend, messageSend: this.messageSend,
@@ -509,10 +524,18 @@ export class MessageService {
this.addToDb = true this.addToDb = true
const message = this.getChatObj() const message = this.getChatObj()
if(this.instanceHasAttachment) {
this.hasFile = true
}
delete message.id delete message.id
const createdMessage = await MessageModel.create(message) const createdMessage = await MessageModel.create(message)
this.rowInstance = createdMessage if(this.instanceHasAttachment) {
this.addFileToDb()
}
this.messageModelInstance = createdMessage
this.id = createdMessage.id this.id = createdMessage.id
if(this.earlySave) { if(this.earlySave) {
@@ -521,6 +544,96 @@ export class MessageService {
} }
} }
async addFileToDb() {
if(!this.messageModelInstance) {
this.messageModelInstance = await this.getRowInstance()
}
const createdMessage: any = this.messageModelInstance
try {
let file = {}
if(this.attachmentsModelData) {
file = {image_url: this.attachmentsModelData?.fileBase64}
}
await attachments.create({messageId: createdMessage.id, attachments: this.attachments, file: Object.assign(this.file, file) })
} catch (error) {
console.log(error)
}
}
async getFileFromDB() {
if(!this.messageModelInstance) {
this.messageModelInstance = await this.getRowInstance()
}
const data = await this.messageModelInstance.getAttachments()
console.log('data', data);
this.attachments = data.attachments
this.file = data.file
}
async generateTemporaryData () {
const blob: any = await this.base64StringToBlob(this.file.image_url)
const formData = new FormData();
formData.append("blobFile", blob);
this.temporaryData = formData
}
get instanceHasAttachment() {
if (this.file) {
if(this.file.type) {
if(typeof(this.file.type) == 'string') {
return true
}
}
}
return false
}
get instanceHasAttachmentBase64() {
if (this.file) {
if(this.file.type) {
if(this.file?.image_url) {
return true
}
}
}
return false
}
get instanceHasTemporaryData() {
if (!this.temporaryData) {
return false
}
return true
}
base64StringToBlob(base64Data) {
return new Promise((resolve, reject) => {
fetch(base64Data)
.then(res => resolve(res.blob()))
.then(console.log)
})
}
async getRowInstance () { async getRowInstance () {
@@ -547,11 +660,11 @@ export class MessageService {
async saveChanges() { async saveChanges() {
if(!this.rowInstance) { if(!this.messageModelInstance) {
this.rowInstance = await this.getRowInstance() this.messageModelInstance = await this.getRowInstance()
} }
if(this.save && this.rowInstance) { if(this.save && this.messageModelInstance) {
const message = this.getChatObj() const message = this.getChatObj()
if(!message.id) { if(!message.id) {
@@ -560,11 +673,11 @@ export class MessageService {
for( const [name, value] of Object.entries(message)) { for( const [name, value] of Object.entries(message)) {
try { try {
this.rowInstance[name] = value this.messageModelInstance[name] = value
} catch (error) {} } catch (error) {}
} }
await this.rowInstance.save() await this.messageModelInstance.save()
} else { } else {
this.earlySave = true this.earlySave = true
+9 -3
View File
@@ -564,7 +564,7 @@ export class RoomService {
/** /**
* @description sen text message * @description sen text message
*/ */
async send({file = null, attachments = null, temporaryData = {}}) { async send({file = null, attachments = null, temporaryData = {}, attachmentsModelData = {}}) {
const localReference = uuidv4(); const localReference = uuidv4();
@@ -575,9 +575,13 @@ export class RoomService {
file, file,
temporaryData, temporaryData,
localReference, localReference,
origin: 'local' origin: 'local',
attachmentsModelData
} }
console.log('offlineChatMessage', offlineChatMessage)
this.message= '' this.message= ''
const message: MessageService = await this.prepareCreate({message:offlineChatMessage, save: environment.chatOffline}) const message: MessageService = await this.prepareCreate({message:offlineChatMessage, save: environment.chatOffline})
@@ -705,12 +709,14 @@ export class RoomService {
const wewMessage = await this.simplePrepareMessage(ChatMessage) const wewMessage = await this.simplePrepareMessage(ChatMessage)
wewMessage.from = 'Offline' wewMessage.from = 'Offline'
wewMessage.loadHistory = this.hasLoadHistory wewMessage.loadHistory = this.hasLoadHistory
wewMessage.messageModelInstance = ChatMessage
if(wewMessage.offline == false) { if(wewMessage.offline == false) {
const message = await this.prepareCreate({message:ChatMessage}) const message = await this.prepareCreate({message:ChatMessage})
message.from = 'Offline' message.from = 'Offline'
message.loadHistory = this.hasLoadHistory message.loadHistory = this.hasLoadHistory
wewMessage.messageModelInstance = ChatMessage
message?.decryptMessage() message?.decryptMessage()
} else { } else {
@@ -719,11 +725,11 @@ export class RoomService {
offlineMessage.from = 'Offline' offlineMessage.from = 'Offline'
offlineMessage.loadHistory = this.hasLoadHistory offlineMessage.loadHistory = this.hasLoadHistory
wewMessage.messageModelInstance = ChatMessage
this.registerSendMessage(offlineMessage) this.registerSendMessage(offlineMessage)
offlineMessage?.decryptMessage() offlineMessage?.decryptMessage()
offlineMessage.send() offlineMessage.send()
} }
if(wewMessage.delate && !wewMessage.offline && !wewMessage.delateRequest) { if(wewMessage.delate && !wewMessage.offline && !wewMessage.delateRequest) {
@@ -169,9 +169,85 @@ export class FileService {
} }
getFileFromDeviceBase64(types: typeof FileType[]) {
const input = this.fileLoaderService.createInput({
accept: types
})
return new Promise((resolve, reject)=>{
input.onchange = async () => {
const file = this.fileLoaderService.getFirstFile(input)
resolve(await this.getBase64(file));
};
})
}
getBase64(file) {
return new Promise((resolve, reject) => {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
resolve(reader.result)
};
reader.onerror = function (error) {
console.log('Error: ', error);
};
})
}
viewDocumentByUrl(url) { viewDocumentByUrl(url) {
const browser = this.iab.create(url,"_parent"); const browser = this.iab.create(url,"_parent");
browser.show(); browser.show();
} }
blobToBase64 = blob => {
const reader = new FileReader();
reader.readAsDataURL(blob);
return new Promise(resolve => {
reader.onloadend = () => {
resolve(reader.result);
};
});
}
base64toBlob(base64Data, contentType) {
contentType = contentType || '';
var sliceSize = 1024;
var byteCharacters = atob(base64Data);
var bytesLength = byteCharacters.length;
var slicesCount = Math.ceil(bytesLength / sliceSize);
var byteArrays = new Array(slicesCount);
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
var begin = sliceIndex * sliceSize;
var end = Math.min(begin + sliceSize, bytesLength);
var bytes = new Array(end - begin);
for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
bytes[i] = byteCharacters[offset].charCodeAt(0);
}
byteArrays[sliceIndex] = new Uint8Array(bytes);
}
return new Blob(byteArrays, { type: contentType });
}
base64StringToBlob(base64Data) {
return new Promise((resolve, reject) => {
fetch(base64Data)
.then(res => resolve(res.blob()))
.then(console.log)
})
}
} }
@@ -120,11 +120,14 @@
<div (click)="openPreview(msg)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file"> <div (click)="openPreview(msg)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
<div *ngIf="!msg.attachments[0].image_url"> <div *ngIf="!msg.attachments[0].image_url">
<ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button"> <ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button">
<ion-icon *ngIf="msg.attachments[0].type != 'webtrix'" name="document" class="file-icon"></ion-icon> <ion-icon *ngIf="msg.attachments[0].type != 'webtrix'" name="document" class="file-icon"></ion-icon>
<ion-icon *ngIf="msg.attachments[0].type == 'webtrix'" src="assets/icon/webtrix.svg" class="file-icon"></ion-icon> <ion-icon *ngIf="msg.attachments[0].type == 'webtrix'" src="assets/icon/webtrix.svg" class="file-icon"></ion-icon>
<ion-label>{{file.title}}</ion-label> <ion-label>{{ file.title}}</ion-label>
<ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon> <ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon> <ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="( msg.downloadLoader == true || msg.uploadingFile == true )" class="icon-download" src="assets/gif/theme/{{ThemeService.currentTheme}}/Blocks-loader.svg" slot="end"></ion-icon>
</ion-item> </ion-item>
</div> </div>
<div *ngIf="msg.attachments[0].image_url"> <div *ngIf="msg.attachments[0].image_url">
@@ -424,31 +424,11 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
this.ChatSystemService.getGroupRoom(this.roomId).send({}) this.ChatSystemService.getGroupRoom(this.roomId).send({})
} }
base64toBlob(base64Data, contentType) {
contentType = contentType || '';
var sliceSize = 1024;
var byteCharacters = atob(base64Data);
var bytesLength = byteCharacters.length;
var slicesCount = Math.ceil(bytesLength / sliceSize);
var byteArrays = new Array(slicesCount);
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
var begin = sliceIndex * sliceSize;
var end = Math.min(begin + sliceSize, bytesLength);
var bytes = new Array(end - begin);
for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
bytes[i] = byteCharacters[offset].charCodeAt(0);
}
byteArrays[sliceIndex] = new Uint8Array(bytes);
}
return new Blob(byteArrays, { type: contentType });
}
async sendAudio(fileName) { async sendAudio(fileName) {
const roomId = this.roomId const roomId = this.roomId
let audioFile; let audioFile;
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then(async (recordData) => {
audioFile = recordData; audioFile = recordData;
if (recordData?.value?.recordDataBase64.includes('data:audio')) { if (recordData?.value?.recordDataBase64.includes('data:audio')) {
@@ -461,7 +441,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
//Converting base64 to blob //Converting base64 to blob
const encodedData = btoa(this.audioRecorded); const encodedData = btoa(this.audioRecorded);
const blob = this.base64toBlob(encodedData, recordData.value.mimeType) const blob = this.fileService.base64toBlob(encodedData, recordData.value.mimeType)
const formData = new FormData(); const formData = new FormData();
formData.append("blobFile", blob); formData.append("blobFile", blob);
@@ -477,7 +457,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"title_link_download": true, "title_link_download": true,
"type": "audio" "type": "audio"
}], }],
temporaryData: formData temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
}); });
@@ -748,7 +731,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"image_url": 'data:image/jpeg;base64,' + file.base64String, "image_url": 'data:image/jpeg;base64,' + file.base64String,
"text": "description", "text": "description",
"title_link_download": false, "title_link_download": false,
}] }],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
} }
@@ -776,7 +762,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"text": "description", "text": "description",
"title_link_download": false, "title_link_download": false,
}], }],
temporaryData: formData temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
} }
@@ -864,7 +853,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"image_url": 'data:image/jpeg;base64,' + file.base64String, "image_url": 'data:image/jpeg;base64,' + file.base64String,
"text": "description", "text": "description",
"title_link_download": false, "title_link_download": false,
}] }],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
} }
@@ -882,7 +874,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch ((error) => { const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch ((error) => {
console.error(error); console.error(error);
}))); })));
const blob = this.base64toBlob(encodedData, file.type) const blob = this.fileService.base64toBlob(encodedData, file.type)
const formData = new FormData(); const formData = new FormData();
@@ -900,7 +892,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
// "text": "description", // "text": "description",
"title_link_download": false, "title_link_download": false,
}], }],
temporaryData: formData temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
} else { } else {
@@ -122,10 +122,11 @@
<ion-icon *ngIf="msg.attachments[0].type != 'webtrix'" name="document" class="file-icon"></ion-icon> <ion-icon *ngIf="msg.attachments[0].type != 'webtrix'" name="document" class="file-icon"></ion-icon>
<ion-icon *ngIf="msg.attachments[0].type == 'webtrix'" src="assets/icon/webtrix.svg" class="file-icon"></ion-icon> <ion-icon *ngIf="msg.attachments[0].type == 'webtrix'" src="assets/icon/webtrix.svg" class="file-icon"></ion-icon>
<ion-label>{{ file.title}}</ion-label> <ion-label>{{ file.title}}</ion-label>
<ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon> <ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon> <ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="( msg.downloadLoader == true || msg.uploadingFile == true )" class="icon-download" src="assets/gif/theme/{{ThemeService.currentTheme}}/Blocks-loader.svg" slot="end"></ion-icon>
</ion-item> </ion-item>
</div> </div>
+26 -30
View File
@@ -411,7 +411,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
async sendAudio(fileName) { async sendAudio(fileName) {
const roomId = this.roomId const roomId = this.roomId
let audioFile; let audioFile;
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then(async (recordData) => {
audioFile = recordData; audioFile = recordData;
@@ -423,7 +423,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
} }
//Converting base64 to blob //Converting base64 to blob
const encodedData = btoa(this.audioRecorded); const encodedData = btoa(this.audioRecorded);
const blob = this.base64toBlob(encodedData, recordData.value.mimeType) const blob = this.fileService.base64toBlob(encodedData, recordData.value.mimeType)
const formData = new FormData(); const formData = new FormData();
formData.append("blobFile", blob); formData.append("blobFile", blob);
@@ -439,7 +439,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
"title_link_download": true, "title_link_download": true,
"type": "audio" "type": "audio"
}], }],
temporaryData: formData temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
}); });
@@ -451,27 +454,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.ChatSystemService.getDmRoom(this.roomId).sendDeleteRequest(msgId) this.ChatSystemService.getDmRoom(this.roomId).sendDeleteRequest(msgId)
} }
base64toBlob(base64Data, contentType) {
contentType = contentType || '';
var sliceSize = 1024;
var byteCharacters = atob(base64Data);
var bytesLength = byteCharacters.length;
var slicesCount = Math.ceil(bytesLength / sliceSize);
var byteArrays = new Array(slicesCount);
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
var begin = sliceIndex * sliceSize;
var end = Math.min(begin + sliceSize, bytesLength);
var bytes = new Array(end - begin);
for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
bytes[i] = byteCharacters[offset].charCodeAt(0);
}
byteArrays[sliceIndex] = new Uint8Array(bytes);
}
return new Blob(byteArrays, { type: contentType });
}
async openViewDocumentModal(file: any) { async openViewDocumentModal(file: any) {
let task = { let task = {
@@ -661,7 +643,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
source: CameraSource.Camera source: CameraSource.Camera
}); });
const blob = this.dataURItoBlob('data:image/jpeg;base64,' + file.base64String) const base64 = 'data:image/jpeg;base64,' + file.base64String
const blob = this.dataURItoBlob(base64)
const formData = new FormData(); const formData = new FormData();
formData.append("blobFile", blob); formData.append("blobFile", blob);
@@ -678,7 +661,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
//"image_url": 'data:image/jpeg;base64,' + file.base64String, //"image_url": 'data:image/jpeg;base64,' + file.base64String,
"text": "description", "text": "description",
"title_link_download": false, "title_link_download": false,
}] }],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
} }
@@ -710,7 +696,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
"image_url": capturedImage, "image_url": capturedImage,
"text": "description", "text": "description",
"title_link_download": false, "title_link_download": false,
}] }],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
} }
@@ -778,6 +767,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
//const imageData = await this.fileToBase64Service.convert(file) //const imageData = await this.fileToBase64Service.convert(file)
// //
const response = await fetch('data:image/jpeg;base64,' + file.base64String!); const response = await fetch('data:image/jpeg;base64,' + file.base64String!);
const blob = await response.blob(); const blob = await response.blob();
@@ -795,7 +785,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
//"image_url": 'data:image/jpeg;base64,' + file.base64String, //"image_url": 'data:image/jpeg;base64,' + file.base64String,
"text": "description", "text": "description",
"title_link_download": false, "title_link_download": false,
}] }],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
} }
@@ -814,7 +807,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch ((error) => { const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch ((error) => {
console.error(error); console.error(error);
}))); })));
const blob = this.base64toBlob(encodedData, file.type) const blob = this.fileService.base64toBlob(encodedData, file.type)
const formData = new FormData(); const formData = new FormData();
@@ -832,7 +825,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
// "text": "description", // "text": "description",
"title_link_download": false, "title_link_download": false,
}], }],
temporaryData: formData temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
}) })
} else { } else {
@@ -87,7 +87,12 @@
Diplomas por validar Diplomas por validar
</ion-segment-button> </ion-segment-button>
<ion-segment-button value="assinados"> <ion-segment-button value="assinados">
Diplomas assinados PR <span *ngIf="!p.userPermission([p.permissionList.Gabinete.pr_tasks])">
Diplomas assinados PR
</span>
<span *ngIf="p.userPermission([p.permissionList.Gabinete.pr_tasks])">
Diplomas
</span>
</ion-segment-button> </ion-segment-button>
</ion-segment> </ion-segment>
</ion-toolbar> </ion-toolbar>
+6 -6
View File
@@ -1,12 +1,12 @@
export let versionData = { export let versionData = {
"shortSHA": "2c28e37a4", "shortSHA": "8c02c5abb",
"SHA": "2c28e37a4b09610c5e3ab7da7d1c887065ab91b6", "SHA": "8c02c5abb8e15fb6d0dfa2e119ec8005953ae968",
"branch": "feature/gabinete-search", "branch": "feature/gabinete-search",
"lastCommitAuthor": "'Peter Maquiran'", "lastCommitAuthor": "'Peter Maquiran'",
"lastCommitTime": "'Fri Jun 23 12:14:24 2023 +0100'", "lastCommitTime": "'Fri Jun 23 13:56:34 2023 +0100'",
"lastCommitMessage": "change words to english", "lastCommitMessage": "rename",
"lastCommitNumber": "5020", "lastCommitNumber": "5021",
"change": "", "change": "",
"changeStatus": "On branch feature/gabinete-search\nChanges to be committed:\n (use \"git restore --staged <file>...\" to unstage)\n\tmodified: src/app/domain/process/DiplomaGenerate.ts\n\tmodified: src/app/domain/process/DiplomaSignPr.ts\n\tmodified: src/app/domain/process/DiplomaToSign.ts\n\tmodified: src/app/domain/process/DiplomasValidate.ts\n\tmodified: src/app/domain/process/DispatchDomain.ts\n\tmodified: src/app/domain/process/DispatchPrDomain.ts\n\tmodified: src/app/domain/process/Expediente.ts\n\tmodified: src/app/domain/process/GenericBehaviorTaskActions.ts\n\tmodified: src/app/domain/process/RequestsForDeferment.ts", "changeStatus": "On branch feature/gabinete-search\nChanges to be committed:\n (use \"git restore --staged <file>...\" to unstage)\n\tmodified: src/app/models/beast-orm.ts\n\tmodified: src/app/models/chatMethod.ts\n\tmodified: src/app/pages/chat/group-messages/group-messages.page.html\n\tmodified: src/app/pages/chat/group-messages/group-messages.page.ts\n\tmodified: src/app/pages/chat/messages/messages.page.html\n\tmodified: src/app/pages/chat/messages/messages.page.ts\n\tmodified: src/app/services/auth.service.ts\n\tmodified: src/app/services/chat/message.service.ts\n\tmodified: src/app/services/chat/room.service.ts\n\tmodified: src/app/services/functions/file.service.ts\n\tmodified: src/app/shared/chat/group-messages/group-messages.page.html\n\tmodified: src/app/shared/chat/group-messages/group-messages.page.ts\n\tmodified: src/app/shared/chat/messages/messages.page.html\n\tmodified: src/app/shared/chat/messages/messages.page.ts\n\tmodified: src/app/shared/gabinete-digital/diplomas/diplomas.page.html",
"changeAuthor": "peter.maquiran" "changeAuthor": "peter.maquiran"
} }