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);
};
@@ -24,7 +24,7 @@ export class ContactsPage implements OnInit {
dm:any;
sessionStore = SessionStore
userList = this.ChatSystemService.users
constructor(
private modalController: ModalController,
private http: HttpClient,
@@ -44,6 +44,7 @@ export class ContactsPage implements OnInit {
ngOnInit() {
// this.chatService.refreshtoken();
// this.loadUsers();
this.ChatSystemService.getUser()
}
@@ -55,7 +56,7 @@ export class ContactsPage implements OnInit {
const username = e.name.toLowerCase()
return username.includes(this.textSearch)
})
}
@@ -86,7 +87,7 @@ export class ContactsPage implements OnInit {
createRoom(username:string) {
if(this.loading) {
return
return
}
this.loading = true
@@ -109,7 +110,7 @@ export class ContactsPage implements OnInit {
}
getDirectMessage(roomId:any) {
this.openModal(roomId);
}
+7 -4
View File
@@ -104,6 +104,7 @@ export class ChatSystemService {
document.addEventListener('resume', function () {
this.RochetChatConnectorService.setStatus('online')
if(this._dm?.length == 0 && this._group?.length == 0) {
this.getAllRooms();
}
@@ -516,16 +517,18 @@ export class ChatSystemService {
const userId = d.fields.args[0][0]
const username = d.fields.args[0][1]
const statusNum = d.fields.args[0][2]
let statusNum = d.fields.args[0][2]
const statusText = this.statusNumberToText(statusNum)
for ( const user of this.users) {
if(user._id == userId) {
user.status = statusText
for ( const user in this.users) {
if(this.users[user]._id == userId) {
this.users[user].status = statusText
}
}
console.log('user status', d)
})
}
@@ -106,7 +106,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
private fileOpener: FileOpener,
public p: PermissionService,
) {
this.ChatSystemService.getUser()
this.loggedUserChat = SessionStore.user.ChatData['data'];
this.isGroupCreated = true;
this.roomCountDownDate = "";
@@ -117,10 +118,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
this.getRoomInfo();
this.ChatSystemService.getGroupRoom(this.roomId).loadHistory({});
//
//
this.ChatSystemService.openRoom(this.roomId)
this.ChatSystemService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked
this.groupNameFormart = this.ChatSystemService.getGroupRoom(this.roomId).name.split('-').join(' ')
this.groupNameFormart = this.ChatSystemService.getGroupRoom(this.roomId).name.split('-').join(' ')
this.showAvatar = false
@@ -139,7 +140,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
this.getRoomInfo()
//}, 1000);
this.getChatMembers();
this.deleteRecording();
this.loadFiles();
}
@@ -194,7 +195,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
});
modal.onDidDismiss().then((res) => {
});
await modal.present();
}
@@ -256,7 +257,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
})
this.storage.get('recordData').then((recordData) => {
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64);
}
@@ -294,13 +295,13 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
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) {
const recordData = result.value.recordDataBase64;
@@ -309,7 +310,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
//Save file
this.storage.set('fileName', fileName);
this.storage.set('recordData', result).then(() => {
})
}
})
@@ -364,16 +365,16 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
get watch() {
this.getRoomInfo();
return this.roomId;
}
async getRoomInfo() {
if(this.ChatSystemService.getGroupRoom(this.roomId)) {
this.ChatSystemService.getGroupRoom(this.roomId).loadHistory({});
}
let room = await this.chatService.getRoomInfo(this.roomId).toPromise();
this.room = room['room'];
if (this.room.name) {
@@ -382,9 +383,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
} catch (error) {
this.roomName = this.room.name;
}
}
if(SessionStore.user.ChatData.data.userId == this.room.u._id){
this.isAdmin = true
@@ -412,7 +413,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
// //Otherwise call getChannelMembers for públic groups
// else {
// this.chatService.getChannelMembers(this.roomId).subscribe(res => {
// this.members = res['members'];
// this.showLoader = false;
// });
@@ -430,7 +431,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
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;
@@ -477,25 +478,25 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
const backdropAnimation = this.animationController.create()
.addElement(baseEl.querySelector('ion-backdrop')!)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = this.animationController.create()
.addElement(baseEl.querySelector('.modal-wrapper')!)
.keyframes([
{ offset: 0, opacity: '1', right: '-100%' },
{ offset: 1, opacity: '1', right: '0px' }
]);
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
}
const leaveAnimation = (baseEl: any) => {
return enterAnimation(baseEl).direction('reverse');
}
const modal = await this.modalController.create({
enterAnimation,
leaveAnimation,
@@ -521,14 +522,14 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
this.showEmptyContainer.emit();
}
else if (res.data == 'cancel') {
}
else if (res.data == 'edit') {
//this.closeAllDesktopComponents.emit();
this.openEditGroupPage.emit(this.roomId);
} else if (res.data == 'addUser') {
this.openGroupContactsPage();
}
else {
@@ -538,24 +539,24 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
this.roomName = res.data.name.split('-').join(' ');
} catch (error) {
this.roomName = res.data.name
}
}
};
});
}
openSendGroupMessageOptions(ev?: any) {
if (window.innerWidth <= 701) {
this.openChatOptions(ev);
}
else {
this._openChatOptions();
}
}
@@ -573,7 +574,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
});
await popover.present();
popover.onDidDismiss().then(res => {
if (res.data) {
//this.getRoomInfo();
//this.modalController.dismiss();
@@ -597,7 +598,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
});
}
async addContacts() {
if(this.isAdmin) {
const modal = await this.modalController.create({
component: GroupContactsPage,
@@ -610,9 +611,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
cssClass: 'contacts',
backdropDismiss: false
});
modal.onDidDismiss().then(() => {
//this.getRoomInfo();
});
@@ -714,7 +715,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
resultType: CameraResultType.Base64,
source: CameraSource.Camera
});
//const imageData = await this.fileToBase64Service.convert(file)
//
var base64 = 'data:image/jpeg;base64,' + file.base64String
@@ -900,7 +901,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
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") {
@@ -947,7 +948,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
})
} else {
}
@@ -967,7 +968,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
resolve(reader.result)
};
reader.onerror = function (error) {
};
});
@@ -1018,7 +1019,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
});
await modal.present();
modal.onDidDismiss().then(async (res) => {
const roomId = this.roomId;
if (res['data'] == 'meeting') {
@@ -1102,9 +1103,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
} else {
pathFile = this.file.externalRootDirectory
}
this.file
.writeFile(pathFile, fileName, contentFile, { replace: true })
.then(success => {
@@ -1158,7 +1159,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
}
async audioPreview(msg) {
if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') {
this.downloadFileMsg(msg)
} else { }
@@ -1169,32 +1170,32 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
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);
};
@@ -1205,25 +1206,25 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
// 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;
}