mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
Merge branch 'feature/viewer-attachment' of bitbucket.org:equilibriumito/gabinete-digital-fo into feature/viewer-attachment
This commit is contained in:
@@ -12,6 +12,7 @@ import { Storage } from '@ionic/storage';
|
||||
import { ChatController } from './controller/chat';
|
||||
import { register } from 'swiper/element/bundle';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import {ScreenOrientation} from "@ionic-native/screen-orientation/ngx";
|
||||
|
||||
const CUSTOM_DATE_FORMATS: NgxMatDateFormats = {
|
||||
parse: {
|
||||
@@ -41,7 +42,8 @@ export class AppComponent {
|
||||
public ThemeService: ThemeService,
|
||||
private storage: Storage,
|
||||
private ChatSystemService: ChatSystemService,
|
||||
private sanitizer: DomSanitizer
|
||||
private sanitizer: DomSanitizer,
|
||||
private screenOrientation: ScreenOrientation
|
||||
) {
|
||||
|
||||
window["sanitizer"] = this.sanitizer
|
||||
@@ -77,9 +79,12 @@ export class AppComponent {
|
||||
if (this.platform.is("tablet")) {
|
||||
window.screen.orientation.unlock();
|
||||
} else if( this.platform.is("mobile")) {
|
||||
// window.screen.orientation.lock('portrait');
|
||||
if(this.platform.is('ios')){
|
||||
this.screenOrientation.lock('portrait')
|
||||
} else {
|
||||
window.screen.orientation.lock('portrait');
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
|
||||
import { RouteService } from 'src/app/services/route.service';
|
||||
import { FileValidatorService } from "src/app/services/file/file-validator.service"
|
||||
import { sanitize } from "sanitize-filename-ts";
|
||||
import { FilePicker } from '@capawesome/capacitor-file-picker';
|
||||
|
||||
@Component({
|
||||
selector: 'app-group-messages',
|
||||
@@ -839,8 +840,47 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
async addFileToChat(types: typeof FileType[]) {
|
||||
|
||||
|
||||
|
||||
const roomId = this.roomId
|
||||
|
||||
if(this.platform.is('ios')) {
|
||||
console.log('ios add file ')
|
||||
|
||||
const resultt = await FilePicker.pickFiles({
|
||||
types: ['application/pdf'],
|
||||
multiple: false,
|
||||
readData: true,
|
||||
});
|
||||
|
||||
console.log('RESULT', resultt.files[0])
|
||||
|
||||
const blobb = this.fileService.base64toBlob(resultt.files[0].data, resultt.files[0].mimeType)
|
||||
|
||||
const formDataa = new FormData();
|
||||
formDataa.append('blobFile', blobb);
|
||||
/* console.log('add file', fileBase64) */
|
||||
|
||||
this.ChatSystemService.getGroupRoom(roomId).send({
|
||||
file: {
|
||||
"type": resultt.files[0].mimeType,
|
||||
"guid": '',
|
||||
},
|
||||
attachments: [{
|
||||
"title": sanitize(resultt.files[0].name),
|
||||
"name": sanitize(resultt.files[0].name),
|
||||
// "text": "description",
|
||||
"title_link_download": false,
|
||||
}],
|
||||
temporaryData: formDataa,
|
||||
attachmentsModelData: {
|
||||
fileBase64: '',
|
||||
}
|
||||
})
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
const file: any = await this.fileService.getFileFromDevice(types);
|
||||
|
||||
|
||||
|
||||
@@ -29,12 +29,13 @@ import { SessionStore } from 'src/app/store/session.service';
|
||||
import { ViewMediaPage } from 'src/app/modals/view-media/view-media.page';
|
||||
import { File } from '@awesome-cordova-plugins/file/ngx';
|
||||
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
|
||||
import { Filesystem, Directory } from '@capacitor/filesystem';
|
||||
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
|
||||
import { NewEventPage } from '../../agenda/new-event/new-event.page';
|
||||
import { NotificationsService } from 'src/app/services/notifications.service';
|
||||
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service'
|
||||
import { FileValidatorService } from "src/app/services/file/file-validator.service"
|
||||
import { sanitize } from "sanitize-filename-ts";
|
||||
import { FilePicker } from '@capawesome/capacitor-file-picker';
|
||||
import { ChangeDetectorRef } from '@angular/core';
|
||||
|
||||
|
||||
@@ -848,9 +849,46 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
async addFileToChat(types: typeof FileType[]) {
|
||||
console.log('add file')
|
||||
console.log('add file ')
|
||||
const roomId = this.roomId
|
||||
|
||||
if(this.platform.is('ios')) {
|
||||
console.log('ios add file ')
|
||||
|
||||
const resultt = await FilePicker.pickFiles({
|
||||
types: ['application/pdf'],
|
||||
multiple: false,
|
||||
readData: true,
|
||||
});
|
||||
|
||||
console.log('RESULT', resultt.files[0])
|
||||
|
||||
const blobb = this.fileService.base64toBlob(resultt.files[0].data, resultt.files[0].mimeType)
|
||||
|
||||
const formDataa = new FormData();
|
||||
formDataa.append('blobFile', blobb);
|
||||
/* console.log('add file', fileBase64) */
|
||||
|
||||
this.ChatSystemService.getDmRoom(roomId).send({
|
||||
file: {
|
||||
"type": resultt.files[0].mimeType,
|
||||
"guid": '',
|
||||
},
|
||||
attachments: [{
|
||||
"title": sanitize(resultt.files[0].name),
|
||||
"name": sanitize(resultt.files[0].name),
|
||||
// "text": "description",
|
||||
"title_link_download": false,
|
||||
}],
|
||||
temporaryData: formDataa,
|
||||
attachmentsModelData: {
|
||||
fileBase64: '',
|
||||
}
|
||||
})
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
const file: any = await this.fileService.getFileFromDevice(types);
|
||||
console.log(file)
|
||||
|
||||
@@ -1068,11 +1106,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
async openFile(pdfString, filename, type) {
|
||||
const blob = this.b64toBlob(pdfString, type)
|
||||
console.log(blob)
|
||||
let pathFile = ''
|
||||
const fileName = filename
|
||||
const contentFile = blob
|
||||
if (this.platform.is('ios')) {
|
||||
pathFile = this.file.documentsDirectory
|
||||
} else {
|
||||
@@ -1084,13 +1119,16 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
await Filesystem.writeFile({
|
||||
path: fileName,
|
||||
data: pdfString,
|
||||
directory: Directory.Data,
|
||||
directory: Directory.Cache,
|
||||
encoding: Encoding.UTF8,
|
||||
}).then((dir) => {
|
||||
console.log('DIR ', dir)
|
||||
this.fileOpener
|
||||
.open(dir.uri, type)
|
||||
.then(() => console.log())
|
||||
.catch(e => console.error(e))
|
||||
}).catch((error) => {
|
||||
console.log('error writing the file', error)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1248,6 +1286,17 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
dataURItoBlobIso(dataURI: any) {
|
||||
const byteString = window.atob(dataURI);
|
||||
const arrayBuffer = new ArrayBuffer(byteString.length);
|
||||
const int8Array = new Uint8Array(arrayBuffer);
|
||||
for (let i = 0; i < byteString.length; i++) {
|
||||
int8Array[i] = byteString.charCodeAt(i);
|
||||
}
|
||||
const blob = new Blob([int8Array], { type: 'application/pdf' });
|
||||
return blob;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -448,6 +448,8 @@ export class MessageService {
|
||||
let downloadFile = "";
|
||||
this.AttachmentsService.downloadFile(this.file.guid).subscribe(async (event) => {
|
||||
|
||||
console.log('download file',event)
|
||||
|
||||
if (event.type === HttpEventType.DownloadProgress) {
|
||||
|
||||
} else if (event.type === HttpEventType.Response) {
|
||||
@@ -456,6 +458,7 @@ export class MessageService {
|
||||
} else if (this.file.type != "application/img") {
|
||||
|
||||
downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '');
|
||||
console.log('downloaded file', downloadFile)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -263,5 +263,17 @@ export class FileService {
|
||||
return new File([u8arr], filename, {type:mime});
|
||||
}
|
||||
|
||||
base64toBlobIos(base64Data, contentType) {
|
||||
contentType = contentType || '';
|
||||
const byteCharacters = atob(base64Data);
|
||||
const byteArray = new Uint8Array(byteCharacters.length);
|
||||
|
||||
for (let i = 0; i < byteCharacters.length; i++) {
|
||||
byteArray[i] = byteCharacters.charCodeAt(i);
|
||||
}
|
||||
|
||||
return new Blob([byteArray], { type: contentType });
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user