@elidjeaka wrote:
I’m designing a chat application and so receive a notification when his correspondent tells him that his correspondent has read the message; For this, my message contains three properties: message, status (false or true), sendby, timestamp. By default when a message is sent, the status is false. and when its match puts the focus in the message writing area, the status is changed to true. The problem is that after that the status does not return to false, it remains. Need help
Here is my code to update message statusupdateStatusMessage() { var promise = new Promise((resolve, reject) => { let temp; this.firebuddychats.child(firebase.auth().currentUser.uid) .child(this.buddy.uid).orderByChild("status") .equalTo(false).on('value', (snapshot) => { temp = snapshot.val() console.log(temp) if (temp) { for (var tempkey in temp) { if (tempkey) { let t = JSON.parse(JSON.stringify(temp[tempkey])) console.log(tempkey) this.firebuddychats .child(firebase.auth().currentUser.uid) .child(this.buddy.uid) .child(tempkey).update({ status: true }).then(() => { console.log("test 1", t) resolve({ success: true }) }) .catch((err) => { reject(err) }) } } } }) }) return promise; }This code is call when I put focus in the input text
<ion-input [(ngModel)]="newmessage" placeholder="Saisir votre message ..." (ionFocus)="hasread()" (focusout)="hasnotread()"></ion-input> <ion-buttons end> <button ion-button (click)="addmessage()"> <ion-icon name="send" color="primary"></ion-icon> </button> </ion-buttons>here is my code , I call it to get all friends and get notifications
await this.events.subscribe('friends', async ()=>{ this.myfriends = []; this.myfriends = await this.requestsService.myfriends; this.myfriends.forEach(friend => { this.notreadbyfriend = [] console.log(this.notreadbyfriend) if (friend.uid) { this.chatService.countnotreadmessages(friend.uid) // rechercher le nombre de messages non lus envoyés par l'utilisateur this.events.subscribe('nbmessage', async (tab) => { // récupération de cette valeur et attribution de la valeur à l'objet console.log("jkjhkj",this.chatService.tab_notreadfriend) if (this.chatService.tab_notreadfriend.length>0){ this.notreadbyfriend = await this.chatService.tab_notreadfriend let tab_people_not_read = this.notreadbyfriend.filter((element) => element.nb > 0) this.nb_people_not_read = tab_people_not_read.length this.events.publish("notreadnb", this.nb_people_not_read) } }) } }) })here is my code to send new message
addnewmessage(msg){ if(this.buddy){ var promise = new Promise((resolve, reject)=>{ this.firebuddychats.child(firebase.auth().currentUser.uid) .child(this.buddy.uid) .push() .set({ sentby:firebase.auth().currentUser.uid, message:msg, status: true, timestamp:firebase.database.ServerValue.TIMESTAMP }).then(()=>{ this.firebuddychats.child(this.buddy.uid).child(firebase.auth().currentUser.uid) .push() .set({ sentby: firebase.auth().currentUser.uid, message: msg, status:false, timestamp: firebase.database.ServerValue.TIMESTAMP }).then((data)=>{ console.log(data) this.countnotreadmessages(this.buddy.uid) resolve(true) }).catch((err)=>{ reject(err) }) }) }) } return promise; }for first time, if somebody send a message to a buddy, buddy receive a sending notification but if buddy would to reply after end leave the reply page
my code continue to update status message
Need Help
Posts: 1
Participants: 1