'use setvalue inside data snapshot

I am trying to use the sanpshot to find if the value exist or not but i am unable to write my code indise if else block how to fix this

binding.chatSend.setOnClickListener{
    database!!.reference.child("users").child(recieverUid!!)
        .addValueEventListener(object :ValueEventListener{
            override fun onDataChange(snapshot: DataSnapshot) {
                if(snapshot.exists()){
                    val vip = snapshot.getValue(String::class.java)
                    if (vip == "yes"){
                        val messageTxt:String = binding.chatMessagebox.text.toString()
                        val date = Date()
                        val message = Chat(messageTxt,senderUid,date.time)
                        binding!!.chatMessagebox.setText("")
                        val randomkey = database!!.reference.push().key
                        val LastMsgObj = HashMap<String,Any>()
                        LastMsgObj["LastMsg"]= message.message!!
                        LastMsgObj["lastMsgTime"]= date.time
                        database!!.reference.child("chats").child(senderRoom!!)
                            .updateChildren(LastMsgObj)
                        database!!.reference.child("chats").child(reciverRoom!!)
                            .updateChildren(LastMsgObj)
                        database!!.reference.child("chats").child(senderRoom!!)
                            .child("message")
                            .child(randomkey!!)
                            .setValue(message).addOnSuccessListener {
                                database!!.reference.child("chats")
                                    .child(reciverRoom!!)
                                    .child("message")
                                    .child(randomkey)
                                    .setValue(message)
                                    .addOnSuccessListener { }
                            }
                    }else{
                            val intent = Intent(this@ChatActivity,VipActivity::class.java)
                            startActivity(intent)
                        }
                }
            }
            override fun onCancelled(error: DatabaseError) {
                TODO("Not yet implemented")
            }
        })


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source