2

I am using Firebase and working in Swift 2.3 and Xcode 7.3 I create chat app using JSQMessagesViewController Chat working fine in live mode and in background mode

I want to set read, pending and unread status of messages in bubbles like WhatsApp and Messenger.

AnyOne help me????

  • Would you mind sharing or removing your question? – Dan Leonard Jan 30 '17 at 15:54
  • How did you do it? I'm stuck with this too.... – JRafaelM Feb 13 '17 at 20:36
  • Ya it would be great if you could shed any light on this matter. – Dan Leonard Feb 15 '17 at 18:18
  • Yeah @hunaintariq , for the message status it was fine, I just subclassed the JSQMessage and reloaded the data, but adding it to the view is more challenging, I just added a text on the bubble's bottom label, it appears that adding ImageViews will be more challenging... – JRafaelM Apr 18 '17 at 11:38

1 Answers1

1

Yes i solve this issues, Just add observer of ChilChanged, this observer will trigger when u changed any value in firebase

messageRef = channelRef!.child("messages")
messageRef.observeEventType(FIRDataEventType.ChildChanged, withBlock: { (snapshot) in
}) { (e) in
            print(e.localizedDescription)
        }

And when u get message just update your status like this, when u do this the above method will trigger on friends device and u can change your local object with respect to your Firebase DB

messageRef.observeEventType(FIRDataEventType.ChildAdded, withBlock: { (snapshot) in
if messageData["status"] as String! == "Sent"{
                        let prntRef  = FIRDatabase.database().reference().child("friends").child(self.chatId).child("messages").child(refKey)
                        prntRef.updateChildValues(["status":"Read"])
                    }
}) { (e) in
                print(e.localizedDescription)
                MBProgressHUD.hideHUDForView(self.view, animated: true)
        }