further improvements

This commit is contained in:
tiago.kayaya
2021-09-23 12:13:20 +01:00
parent ccd211140a
commit 07cbb237e4
20 changed files with 249 additions and 111 deletions
+27 -17
View File
@@ -139,6 +139,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.scrollingOnce = false;
}
this.currentPosition = scroll;
/* console.log(this.currentPosition);
console.log(this.scrollingOnce); */
}
ngOnDestroy() {
@@ -356,6 +358,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
}
this.openNewEventPage.emit(data);
}
else if(res['data'] == 'take-picture'){
this.fileService.addCameraPictureToChat(this.roomId);
//this.loadPicture();
}
else if(res['data'] == 'add-picture'){
this.fileService.addPictureToChat(this.roomId);
//this.loadPicture();
@@ -376,38 +382,42 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
async serverLongPull() {
const roomId = this.roomId
this.chatService.getRoomMessages(this.roomId).subscribe(async res => {
const roomId = this.roomId;
if (res == 502) {
// Connection timeout
// happens when the connection was pending for too long
// let's reconnect
await this.serverLongPull();
} else if (res != 200) {
this.chatService.getRoomMessages(this.roomId).subscribe(async res => {
console.log(res['success']);
if (res['success'] == true) {
// Show Error
//showMessage(response.statusText);
//this.loadMessages()
this.messages = res['messages'].reverse();
this.chatMessageStore.add(roomId, this.messages)
console.log(this.messages);
// Reconnect in one second
if(this.route.url != "/home/chat"){
console.log("Timer message stop")
} else {
if(document.querySelector('app-messages')){
await new Promise(resolve => setTimeout(resolve, 5000));
await this.serverLongPull();
this.getDirectMessages.emit();
console.log('Timer message running')
}
}
} else {
else{
if(document.querySelector('app-messages')){
await new Promise(resolve => setTimeout(resolve, 5000));
await this.serverLongPull();
this.getDirectMessages.emit();
console.log('Timer message running')
}
}
} /* else {
// Got message
//let message = await response.text();
//this.loadMessages()
await this.serverLongPull();
}
} */
}, (error)=>{
console.log(error);
this.serverLongPull();
});
}