I'm new to quickblox
, I have checked some official tutorials, and I've been able to create and connect to my application.
Now the problem I'm having is, that in my quickblox
account, I only have the option to make "rooms", something similar to irc
I think?, but that is not my idea.
I need each user to have his own list of contacts, similar to Facebook chat/ Whatsapp / telegram etc.
So I really don't figure out how to do this, since in all examples I have read they connect to a room.
How should I implement this?
Thanks
You can do it with CustomObjects module for example.
Let's start with Android CustomObjects example http://quickblox.com/developers/SimpleSample-customObjects-android
1) Create class with name FriendsList with one field - friendsIDs (array of int) - this guide shows how to create class http://quickblox.com/developers/SimpleSample-customObjects-android#Add_Custom_Data_structure_to_your_application
2) When UserA adds UserB to friends - put UserB id to friendsIDs field.
QBCustomObject co = new QBCustomObject();
co.setClassName("FriendsList");
HashMap<String, Object> fields = new HashMap<String, Object>();
fields.put("push[friendsIDs][]", "788"); // 788 id UserB id
co.setFields(fields);
co.setCustomObjectId("502f7c4036c9ae2163000002");
QBCustomObjects.updateObject(co, new QBCallbackImpl() {
@Override
public void onComplete(Result result) {
if (result.isSuccess()) {
QBCustomObjectResult updateResult = (QBCustomObjectResult) result;
QBCustomObject qbCustomObject = updateResult.getCustomObject();
Log.d("Updated friends list: ",qbCustomObject.toString());
} else {
Log.e("Errors",result.getErrors().toString());
}
}
});
3) To request friends list:
QBCustomObjectRequestBuilder requestBuilder = new QBCustomObjectRequestBuilder();
requestBuilder.eq("user_id", "222"); // 222 is your user id
QBCustomObjects.getObjects("Movie", requestBuilder, new QBCallbackImpl() {
@Override
public void onComplete(Result result) {
if (result.isSuccess()) {
QBCustomObjectLimitedResult coresult = (QBCustomObjectLimitedResult) result;
ArrayList<QBCustomObject> co = coresult.getCustomObjects();
Log.d("friends list: ", co.toString());
} else {
Log.e("Errors",result.getErrors().toString());
}
}
});