chat21 / chat21-android-sdk

Android Chat SDK built on Firebase
http://www.chat21.org
MIT License
233 stars 98 forks source link

how to get IChatUser detail from email id? #41

Closed vandanabpatel closed 4 years ago

vandanabpatel commented 4 years ago

i want to start conversation directly can we get user detail by their email id if exist to firebase can anyone guild me :)

gab-95 commented 4 years ago

if you have user mail, you can first retrive all contacts, like this:

private ContactsSynchronizer contactsSynchronizer;
contactsSynchronizer= ChatManager.getInstance().getContactsSynchronizer();
List<IChatUser> users = contactsSynchronizer.getContacts();

then check if with for statement if user mail exist. if true create new contact to start chat with:

for(IChatUser user: users) {
                    if (user.getEmail().equals(YOUR_EMAIL)) {

                        IChatUser contact = new ChatUser();
                        contact.setId(user.getId());
                        contact.setEmail(YOUR_EMAIL);
                        Log.d(TAG, "Open chat with contact: " + contact.toString());
                        ChatUI.getInstance().openConversationMessagesActivity(contact);
                        return;
                    }
                }

use openConversationMessagesActivity(contact) to start the chat directly with the last contact created.

Let me know if it works properly

vandanabpatel commented 4 years ago

thanks:) it works @gab-95