This commit is contained in:
Peter Maquiran
2022-02-09 17:06:12 +01:00
parent 3679091e60
commit faa30ee56e
8 changed files with 23 additions and 14 deletions
@@ -109,7 +109,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
} }
}; };
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory(); this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory({});
this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked; this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked;
this.wsChatMethodsService.openRoom(this.roomId) this.wsChatMethodsService.openRoom(this.roomId)
+1 -1
View File
@@ -124,7 +124,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
} }
}; };
this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory() this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory({})
this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked
this.wsChatMethodsService.openRoom(this.roomId) this.wsChatMethodsService.openRoom(this.roomId)
+4 -2
View File
@@ -43,7 +43,6 @@ export class AlertService {
} }
async confirmDeleteMessage(msgId:any, room:any) { async confirmDeleteMessage(msgId:any, room:any) {
console.log(room);
const alert = await this.alertController.create({ const alert = await this.alertController.create({
cssClass: 'my-custom-class', cssClass: 'my-custom-class',
@@ -60,7 +59,10 @@ export class AlertService {
text: 'Apagar', text: 'Apagar',
handler: () => { handler: () => {
//const loader = this.toastService.loading(); //const loader = this.toastService.loading();
this.wsChatMethodsService.deleteMessage(msgId);
this.wsChatMethodsService.deleteMessage(msgId).then(()=>{
room.deleteMessage(msgId)
})
//this.wsChatMethodsService.subscribeToRoomUpdate(room._id, room); //this.wsChatMethodsService.subscribeToRoomUpdate(room._id, room);
//loader.remove(); //loader.remove();
} }
+12 -4
View File
@@ -67,6 +67,15 @@ export class RoomService {
private NfService: NfService private NfService: NfService
) { ) {
this.NativeNotificationService.askForPermission() this.NativeNotificationService.askForPermission()
this.WsChatService.registerCallback({
type: 'reConnect',
funx: ()=>{
this.hasLoadHistory = false
}
})
} }
setData({ customFields, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService), _updatedAt }) { setData({ customFields, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService), _updatedAt }) {
@@ -181,6 +190,7 @@ export class RoomService {
deleteMessage(id) { deleteMessage(id) {
this.messages.forEach((message, index) => { this.messages.forEach((message, index) => {
if(message._id == id) { if(message._id == id) {
alert('found and delete')
this.messages.splice(index, 1) this.messages.splice(index, 1)
this.deleteMessageFromDb(id) this.deleteMessageFromDb(id)
@@ -232,8 +242,6 @@ export class RoomService {
file, file,
temporaryData temporaryData
} }
console.log('offlineChatMessage', offlineChatMessage)
this.addMessageDB(offlineChatMessage) this.addMessageDB(offlineChatMessage)
const message: MessageService = this.prepareMessage(offlineChatMessage) const message: MessageService = this.prepareMessage(offlineChatMessage)
@@ -355,9 +363,9 @@ export class RoomService {
} }
// runs onces only // runs onces only
async loadHistory(limit = 100) { async loadHistory({limit = 100, forceUpdate = false }) {
if (this.hasLoadHistory) { return false } if (this.hasLoadHistory || forceUpdate) { return false }
this.restoreMessageFromDB() this.restoreMessageFromDB()
@@ -210,7 +210,7 @@ export class WsChatMethodsService {
this.prepareRoom(roomData); this.prepareRoom(roomData);
this.getGroupRoom(id).loadHistory(); this.getGroupRoom(id).loadHistory({});
} }
+1 -1
View File
@@ -273,7 +273,7 @@ export class WsChatService {
return new Promise ((resolve, reject) => { return new Promise ((resolve, reject) => {
this.ws.registerCallback({type:'Onmessage', funx:(message) =>{ this.ws.registerCallback({type:'Onmessage', funx:(message) =>{
if(message.id == requestId || deepFind(message, 'result') == requestId){ if(message.id == requestId ){
resolve(message) resolve(message)
return true return true
} }
@@ -121,7 +121,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
this.getRoomInfo(); this.getRoomInfo();
//this.scrollToBottom(); //this.scrollToBottom();
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory(); this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory({});
// console.log('MESSAGES'+ this.wsChatMethodsService.getGroupRoom(this.roomId).messages); // console.log('MESSAGES'+ this.wsChatMethodsService.getGroupRoom(this.roomId).messages);
this.wsChatMethodsService.openRoom(this.roomId) this.wsChatMethodsService.openRoom(this.roomId)
this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked
@@ -272,7 +272,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
} }
async getRoomInfo() { async getRoomInfo() {
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory(); this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory({});
let room = await this.chatService.getRoomInfo(this.roomId).toPromise(); let room = await this.chatService.getRoomInfo(this.roomId).toPromise();
this.room = room['room']; this.room = room['room'];
if (this.room.name) { if (this.room.name) {
@@ -110,7 +110,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory() this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory({})
this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked
@@ -124,7 +124,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.scrollToBottomClicked() this.scrollToBottomClicked()
}, 150) }, 150)
} }
ngOnInit() { ngOnInit() {