Message / Chat - Input in firebase - record getting duplicated - Ionic Firebase


#1

I wonder what am i doing wrong here to get 2 inserts instead of one:

my page code:

  send(message) {
    this.loader.displayPreloader();
        this.uidLogin = this.auth.getLoggedUID();
        let newMessage: IMessage = {
          key:        null,
          userFromUid: this.uidLogin,
          userToUID: this.msgDatarecebido.idmensagemTo,
          timestamp: new Date().toString(),
          message: message,
        };
        this.db.submitMessage(newMessage);
        this.loader.hidePreloader();
        this.scrollToBottom();
      }

database service:

  submitMessage(newMessage: IMessage) {
    this.messagesRef.push(newMessage);
}

database scheme1

i’ve tried different forms but still always getting duplicated, for example:

submitMessage(newMessage: IMessage) {
      var newMessageRef = this.messagesRef.push();
    return newMessageRef.set(newMessage);
}

#2

The code you posted seems fine. Well, fine-ish. You’re hiding the preloader before the message is uploaded. But your double-submit is probably coming from somewhere else, e.g., you calling send twice without realizing it.


#3

bingo! button click and form submit.

I must be tired… hehehe thanks for that bro!