QuickBlox / q-municate-android

Qmunicate Android chat application
MIT License
254 stars 197 forks source link

How to Add & Accept Friend Immediately [Android] #267

Closed sheikhrashid closed 1 year ago

sheikhrashid commented 6 years ago

As in Q-municate project two users can't chat unless they become friends.

I have implemented the feature just like Whatsapp. I retrieved the contacts from my Address Book and Quickblox Server. So I don't need to add them as my Friend, i can chat directly with them. Exactly like Whatspp.

Now my issue is, I can't remove the friend table or comment those as Q-municate based on this Friends.

As you know, when user send request to other user. (this is called) QBAddFriendCommand.start(context, qbUser.getId());

and when other user accepts the request. (this one is called) QBAceeptFriendCommand.start(context, qbUser.getId());

And both becomes Friend.

What I am doing is I am retrieving the contacts and at the same time I run these two commands. But QBAcceptFriendCommand is supposed to run on the other end.

How can I make them friends immediately?

tatanka987 commented 6 years ago

hello @sheikhrashid, sorry for long time answer, as fast solution you can try check roster for incoming requests in method init of QBFriendListHelper. For it use:

    private void autoAcceptIncomingRequests(QBRoster roster) throws Exception {
        for (QBRosterEntry entry : roster.getEntries()){
            if (entry.getType() == RosterPacket.ItemType.to){
                roster.confirmSubscription(entry.getUserId());
            }
        }
    } 

Additionally you should add logic for automatically adding users to friends table of DB (on both sides). But pay attention, this solution not verified and you can get other errors.

Correct solution for your case will be refuse from contact list logic. You can create private chat and send messages to it. On other side you will get it message and can create new dialog for chatting. This is extensive solution and I can't provide simple solution for it.

sheikhrashid commented 6 years ago

autoAcceptIncomingRequests This is available in which SDK version?

tatanka987 commented 6 years ago

this method not from SDK, you can add this method in your app for auto applying requests during loading roster. Additionally you need review code for adding apply request in RosterListener for realtime requests.

sheikhrashid commented 6 years ago

My question is still same.

QBAcceptFriendCommand.start(context, qbUser.getId()); This command when run on the other User end, it works fine.

But I don't want to involve the other user. I want to make them friends at once without accepting from other User side.

tatanka987 commented 6 years ago

As I wrote before, for your needs you should rewrote app logic for work with contacts. QuickBlox provides this functionality (you can send message without adding user to roster). If you want use roster you have to call accept request manually anyway.

sheikhrashid commented 6 years ago

(you can send message without adding user to roster))

How this thing works? How can I do this? I only see that without making friends i am not able to send messages, call, etc.

tatanka987 commented 6 years ago

Now Q-municate searches opponents in 'friend' table and if not found they in this table we can't do anything with this users. You can delete this check or automatic add all contact list to this table. But in this case you wont listen online status in realtime for this users (because you didn't add users to roster), you need rewrote logic for it (for example you can use feature last user's activity).

sheikhrashid commented 6 years ago

Is there any place where I can see the structure (schema) of Friend table?

Bosa17 commented 6 years ago

Is anyone there? Please help with implementing whatsapp like functionality with user contacts