clear storage and add group

This commit is contained in:
Lorito Tiago
2023-10-11 16:20:42 +01:00
5 changed files with 172 additions and 141 deletions
@@ -80,7 +80,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
durationDisplay = '';
duration = 0;
showAvatar = true;
audioPermissionStatus: 'granted'| 'denied' | 'prompt' | null = null
audioPermissionStatus: 'granted' | 'denied' | 'prompt' | null = null
sessionStore = SessionStore
isAdmin = false;
constructor(
@@ -114,10 +114,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
};
this.ChatSystemService.getGroupRoom(this.roomId).loadHistory({});
this.ChatSystemService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked;
this.ChatSystemService.openRoom(this.roomId)
this.groupNameFormart = this.ChatSystemService.getGroupRoom(this.roomId).name.split('-').join(' ')
this.open();
setTimeout(() => {
this.scrollToBottomClicked()
@@ -133,6 +130,20 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
open() {
try {
this.ChatSystemService.getGroupRoom(this.roomId).loadHistory({});
this.ChatSystemService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked;
this.ChatSystemService.openRoom(this.roomId)
this.groupNameFormart = this.ChatSystemService.getGroupRoom(this.roomId).name.split('-').join(' ')
} catch (error) {
setTimeout(() => {
this.open()
}, 3000)
}
}
ngOnInit() {
this.loggedUser = this.loggedUserChat;
@@ -166,7 +177,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.scrollChangeCallback = () => this.onContentScrolled(event);
window.addEventListener('scroll', this.scrollChangeCallback, true);
if(this.room?.customFields?.countDownDate) {
if (this.room?.customFields?.countDownDate) {
this.roomCountDownDate = this.timeService.countDownDate(this.room.customFields.countDownDate, this.room._id);
}
}
@@ -249,7 +260,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64);
}
else if(recordData?.value?.mimeType && recordData?.value?.recordDataBase64) {
else if (recordData?.value?.mimeType && recordData?.value?.recordDataBase64) {
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`);
}
});
@@ -290,22 +301,22 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
async startRecording() {
VoiceRecorder.requestAudioRecordingPermission();
if(await VoiceRecorder.canDeviceVoiceRecord().then((result: GenericResponse) =>{return result.value})){
if(await VoiceRecorder.requestAudioRecordingPermission().then((result: GenericResponse) => {return result.value})){
if (await VoiceRecorder.canDeviceVoiceRecord().then((result: GenericResponse) => { return result.value })) {
if (await VoiceRecorder.requestAudioRecordingPermission().then((result: GenericResponse) => { return result.value })) {
//if(await this.hasAudioRecordingPermission()){
if (this.recording) {
return;
}
this.recording = true;
VoiceRecorder.startRecording();
this.calculateDuration();
if (this.recording) {
return;
}
this.recording = true;
VoiceRecorder.startRecording();
this.calculateDuration();
//}
}
else{
else {
this.toastService._badRequest('Para gravar uma mensagem de voz, permita o acesso do Gabinete Digital ao seu microfone.');
}
}
else{
else {
this.toastService._badRequest('Este dispositivo não tem capacidade para gravação de áudio!');
}
}
@@ -388,7 +399,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
if(SessionStore.user.ChatData.data.userId == this.room.u._id){
if (SessionStore.user.ChatData.data.userId == this.room.u._id) {
this.isAdmin = true
} else {
this.isAdmin = false
@@ -534,7 +545,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
else if (res.data == 'edit') {
this.editGroup(this.roomId);
} else if (res.data == 'addUser') {
} else if (res.data == 'addUser') {
this.addContacts();
} else if (res.data == 'delete') {
@@ -796,7 +807,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
_getBase64(file) {
return new Promise((resolve, reject)=>{
return new Promise((resolve, reject) => {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
@@ -806,7 +817,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
console.log('Error: ', error);
};
})
}
}
async addFileToChat(types: typeof FileType[]) {
@@ -818,7 +829,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
if (file.type != "application/img" && file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/gif") {
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);
})));
const blob = this.fileService.base64toBlob(encodedData, file.type)
@@ -909,7 +920,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
async addContacts() {
if(this.isAdmin) {
if (this.isAdmin) {
const modal = await this.modalController.create({
component: GroupContactsPage,
@@ -1011,7 +1022,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
} else {
//Check if modal is opened
if (document.querySelector('.isGroupChatOpened')) {
await new Promise(resolve => setTimeout(resolve, 5000)).catch ((error) => {
await new Promise(resolve => setTimeout(resolve, 5000)).catch((error) => {
console.error(error);
});
await this.serverLongPull();
@@ -1100,9 +1111,9 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}).then((dir) => {
console.log('DIR ', dir)
this.fileOpener
.open(dir.uri, type)
.then(() => console.log())
.catch(e => console.error(e))
.open(dir.uri, type)
.then(() => console.log())
.catch(e => console.error(e))
});
}
@@ -1120,7 +1131,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
async openPreview(msg: MessageService) {
if(msg?.file?.type === "application/webtrix") {
if (msg?.file?.type === "application/webtrix") {
this.viewDocument(msg.file, msg.attachments.image_url)
} else {
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
@@ -1197,11 +1208,11 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
// set the bytes of the buffer to the correct values
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
ia[i] = byteString.charCodeAt(i);
}
// write the ArrayBuffer to a blob, and you're done
var blob = new Blob([ab], {type: mimeString});
var blob = new Blob([ab], { type: mimeString });
return blob;
}