update user status

This commit is contained in:
Peter Maquiran
2023-09-22 17:25:27 +01:00
parent aaa11f98b2
commit e4bba2e68b
4 changed files with 120 additions and 113 deletions
@@ -103,6 +103,8 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
private file: File,
private fileOpener: FileOpener,
) {
this.ChatSystemService.getUser()
this.loggedUserChat = SessionStore.user.ChatData['data'];
this.isGroupCreated = true;
this.roomId = this.navParams.get('roomId');
@@ -115,7 +117,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.groupNameFormart = this.ChatSystemService.getGroupRoom(this.roomId).name.split('-').join(' ')
setTimeout(() => {
this.scrollToBottomClicked()
@@ -132,7 +134,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
ngOnInit() {
this.loggedUser = this.loggedUserChat;
this.getRoomInfo();
this.scrollToBottom();
@@ -142,7 +144,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
// this.getRoomMessageDB(this.roomId);
this.getGroupContacts({});
}
setStatus(status: string) {
@@ -151,7 +153,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
status: status,
}
// this.chatService.setUserStatus(body).subscribe(res => {
//
//
// })
}
@@ -231,7 +233,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.audioRecorded = base64Response.url;
}
@@ -243,7 +245,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
try {
this.storage.get('recordData').then((recordData) => {
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64);
}
@@ -259,13 +261,13 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
stopRecording() {
this.deleteRecording();
this.allowTyping = false;
if (!this.recording) {
return;
}
this.recording = false;
VoiceRecorder.stopRecording().then(async (result: RecordingData) => {
this.recording = false;
if (result.value && result.value.recordDataBase64) {
@@ -275,7 +277,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
//Save file
await this.storage.set('fileName', fileName)
this.storage.set('recordData', result).then(() => {
setTimeout(async () => {
this.loadFiles();
@@ -337,7 +339,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
});
modal.onDidDismiss().then((res) => {
});
await modal.present();
}
@@ -382,9 +384,9 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
} catch (error) {
this.roomName = this.room.name;
}
}
if(SessionStore.user.ChatData.data.userId == this.room.u._id){
this.isAdmin = true
@@ -399,10 +401,10 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
async getChatMembers() {
this.chatService.getAllUsers().subscribe(res => {
this.allUsers = res['users'].filter(data => data.username != SessionStore.user.UserName);
});
}
@@ -426,7 +428,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
// //If group is private call getGroupMembers
// if (this.room.t === 'p') {
// this.chatService.getGroupMembers(this.roomId).subscribe(res => {
// this.members = res['members'];
// this.showLoader = false;
// });
@@ -434,7 +436,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
// //Otherwise call getChannelMembers for públic groups
// else {
// this.chatService.getChannelMembers(this.roomId).subscribe(res => {
// this.members = res['members'];
// this.showLoader = false;
// });
@@ -469,7 +471,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
const roomId = this.roomId
let audioFile;
this.storage.get('recordData').then(async (recordData) => {
audioFile = recordData;
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
this.audioRecorded = recordData?.value?.recordDataBase64;
@@ -528,17 +530,17 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
//this.ChatSystemService.subscribeToRoomUpdate(this.roomId, this.room);
}
else if (res.data == 'cancel') {
}
else if (res.data == 'edit') {
this.editGroup(this.roomId);
} else if (res.data == 'addUser') {
this.addContacts();
} else if (res.data == 'delete') {
this.close()
this.ChatSystemService.deleteRoom(this.roomId)
}
}
});
}
@@ -615,7 +617,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
IsRequired: "true",
}
});
// this.popoverController.dismiss();
const modal = await this.modalController.create({
component: NewEventPage,
@@ -812,7 +814,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
const file: any = await this.fileService.getFileFromDevice(types);
if (file.type != "application/img" && file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/gif") {
@@ -823,7 +825,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
const formData = new FormData();
formData.append('blobFile', blob);
this.ChatSystemService.getGroupRoom(roomId).send({
file: {
@@ -843,7 +845,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
});
} else {
}
}
@@ -862,14 +864,14 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
resolve(reader.result)
};
reader.onerror = function (error) {
};
});
}
async openChatOptions(ev?: any) {
const roomId = this.roomId;
const popover = await this.popoverController.create({
@@ -885,7 +887,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
});
await popover.present();
await popover.onDidDismiss().then(async (res) => {
if (res['data'] == 'meeting') {
this.bookMeeting();
}
@@ -920,9 +922,9 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
cssClass: 'contacts',
backdropDismiss: false
});
modal.onDidDismiss().then(() => {
this.getRoomInfo();
});
@@ -941,7 +943,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
});
await modal.present();
modal.onDidDismiss().then((res) => {
this.getRoomInfo();
//this.modalController.dismiss(res.data);
});
@@ -1000,12 +1002,12 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
//this.loadMessages()
let msgOnly = res['messages'].filter(data => data.t != 'au');
//this.messages = msgOnly.reverse();
//
//
this.transformDataMSG(msgOnly.reverse());
// this.getRoomMessageDB(this.roomId);
// Reconnect in one second
if (this.route.url != "/home/chat") {
} else {
//Check if modal is opened
if (document.querySelector('.isGroupChatOpened')) {
@@ -1013,7 +1015,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
console.error(error);
});
await this.serverLongPull();
}
}
@@ -1090,7 +1092,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
} else {
pathFile = this.file.externalRootDirectory
}
await Filesystem.writeFile({
path: fileName,
data: pdfString,
@@ -1172,7 +1174,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
async audioPreview(msg) {
if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') {
this.downloadFileMsg(msg)
} else { }
@@ -1183,57 +1185,57 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
var byteString = atob(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
// create a view into the buffer
var ia = new Uint8Array(ab);
// set the bytes of the buffer to the correct values
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
// write the ArrayBuffer to a blob, and you're done
var blob = new Blob([ab], {type: mimeString});
return blob;
}
async compressImageBase64(base64String: string, maxWidth: number, maxHeight: number, quality: number): Promise<string> {
return new Promise((resolve, reject) => {
const image = new (window as any).Image();
image.src = base64String;
image.onload = async () => {
const canvas = document.createElement('canvas');
let newWidth = image.width;
let newHeight = image.height;
if (newWidth > maxWidth) {
newHeight *= maxWidth / newWidth;
newWidth = maxWidth;
}
if (newHeight > maxHeight) {
newWidth *= maxHeight / newHeight;
newHeight = maxHeight;
}
canvas.width = newWidth;
canvas.height = newHeight;
const context = canvas.getContext('2d');
context?.drawImage(image, 0, 0, newWidth, newHeight);
const compressedBase64 = canvas.toDataURL('image/jpeg', quality);
resolve(compressedBase64);
};
image.onerror = (error) => {
reject(error);
};